Skip to main content

bw2scaffold is a templating tool that can facilitate the development of Life Cycle Oriented studies.

Project description

bw2scaffold is a templating tool that can facilitate the development of Life Cycle Oriented studies following the recommendations of the protocol prototype for enhancing the reproducibility and transparency in Life Cycle Inventory building

This tool is still under development, but contributions and recommendations are welcomed.

Installation

Using pip

You can the package in your environment directly from the github repository:

pip install git+https://git.list.lu/gustavo.larrea/replicable-lca.git

Usage: start

This is still work in progress. bw2scaffold provides a CLI command bw2init with two additional commands to setup and pack up an LCA project. To understand more, use the --help option.

> bw2init --help

 Usage: bw2init [OPTIONS] COMMAND [ARGS]...

โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --install-completion          Install completion for the current shell.                              โ”‚
โ”‚ --show-completion             Show completion for the current shell, to copy it or customize the     โ”‚
โ”‚                               installation.                                                          โ”‚
โ”‚ --help                        Show this message and exit.                                            โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ•ญโ”€ Commands โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ finish   Packs up a project created with bw2scaffold and verifies its quality.                       โ”‚
โ”‚ start    Prepares a brightway project template and starts your LCA modelling.                        โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

The start command creates a ready-to-use repository. It requires only one mandatory project_name argument, but it can also install some useful plugins:

> bw2init start --help

 Usage: bw2init start [OPTIONS] PROJECT_NAME

 Prepares a brightway project template and starts your LCA modelling.

โ•ญโ”€ Arguments โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ *    project_name      TEXT  [default: None] [required]                                              โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --full     -f            Installs recommended shell plugins that facilitate work. Works only in      โ”‚
โ”‚                          UNIX-like systems                                                           โ”‚
โ”‚ --verbose  -v            Activate to have verbose logging                                            โ”‚
โ”‚ --email            TEXT  [default: None]                                                             โ”‚
โ”‚ --help                   Show this message and exit.                                                 โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Once your project is created, a success message and the project path will be printed:

> bw2init start my_lca_project
 โœจSuccess! your brightway-based repo has been created:
 /home/larrea_30718/repos/bw2scaffold/my_lca_project

The project structure follows the recommendations of the protocol prototype, like this:

> tree my_lca_project -a
my_lca_project
โ”œโ”€โ”€ .env
โ”œโ”€โ”€ environment.yaml
โ”œโ”€โ”€ .env.leave
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ src
    โ”œโ”€โ”€ analysis
    โ”‚ย ย  โ””โ”€โ”€ README.md
    โ”œโ”€โ”€ assets
    โ”‚ย ย  โ””โ”€โ”€ README.md
    โ”œโ”€โ”€ data
    โ”‚ย ย  โ”œโ”€โ”€ private
    โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ processed
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ README.md
    โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ raw
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ README.md
    โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ README.md
    โ”‚ย ย  โ”œโ”€โ”€ processed
    โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ README.md
    โ”‚ย ย  โ””โ”€โ”€ raw
    โ”‚ย ย      โ””โ”€โ”€ README.md
    โ”œโ”€โ”€ modeling
    โ”‚ย ย  โ””โ”€โ”€ README.md
    โ”œโ”€โ”€ processing
    โ”‚ย ย  โ””โ”€โ”€ README.md
    โ””โ”€โ”€ run.py

12 directories, 16 files

The .env file contains an environmental variable (BRIGHTWAY2_DIR) that stores the path of a folder that will contain all the brightway databases specific for this project. This helps to isolate one project from the rest, allowing (hopefully) to have a fully replicable project.

> cat .env

# Path where bw2data will store data (`.bw2projects`)
BRIGHTWAY2_DIR=/home/gustavo.larrea/test-lca/.bw2projects
export BRIGHTWAY2_DIR
# Useful only for UNIX-like operating system
AUTOENV_ENABLE_LEAVE=True

The best way to use this custom project folder is by loading it before importing bw2data. You can do this by using the python-dotenv package. Install it doing pip install python-dotenv. Imagine this python file (projects.py):

from dotenv import load_dotenv
load_dotenv() # This searches for `.env` file and loads the variables

import bw2data as bd # bw2data will automatically read the environmental variable.
bd.projects.set_current('my_lca_project')
print('This are your projects:\n',bd.projects)

Running this script will have this output:

> python projects.py
16:05:13+0200 [info     ] Using environment variable BRIGHTWAY2_DIR for data directory:
/home/larrea@private.list.lu/repos/test2/.bw2projects
This are your projects:
 Brightway2 projects manager with 2 objects:
    default
    my_lca_project
Use `projects.report()` to get a report on all projects.

This means that brightway will only read and write from the custom folder, isolating your project.

Usage: finish

The finish command packs up the project generating the statistics and figures that are necessary to fulfill the protocol.

> bw2init finish --help

 Usage: bw2init finish [OPTIONS] INPUT_FILE [OUTPUT_FILE]

 Packs up a project created with bw2scaffold and verifies its quality.

โ•ญโ”€ Arguments โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ *    input_file       TEXT           Path of run.py [default: None] [required]                       โ”‚
โ”‚      output_file      [OUTPUT_FILE]  Path to export the callgraph [default: data/callgraph.png]      โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --function  -func      TEXT  Name of the function containing the main pipeline [default: main]       โ”‚
โ”‚ --help                       Show this message and exit.                                             โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

At the moment, this command only generates a callgraph of the computional pipeline of the project. For instance, if the project looks like this run.py example:

"""
This is an Life Cycle Oriented study
"""

def read_data():
    print("I am reading some data")
    return None

def lcia_step() -> float :
    print("I am building LCIA")
    return "LCA impact"

def curate_data():
    print("Data curated")
    return None

def prepare():
    curate_data()
    print("I am preparing some data")

def build_lci() ->  None :
    prepare()
    print('I am building LCI')
    return None

def export(results):
    print(f"I am exporting results: {results}")

def main():
    build_lci()
    results = lcia_step()
    export(results)

    print("Main is done")

if __name__=="__main__":
    main()

When running the bw2init finish command, it is necessary to indicate the source file src/run.py, the output file data/callgraph.png, and the specific function in the source file that starts the whole computation main:

> bw2init finish src/run.py data/callgraph.png --function main
   Code2Flow: Found 1 files from sources argument.
   Code2Flow: Implicitly detected language as 'py'.
   Code2Flow: Processing 1 source file(s).
   Code2Flow:   src/run.py
   Code2Flow: Found groups ['File: run'].
   Code2Flow: Found nodes ['(global)', 'build_lci', 'curate_data', 'export', 'lcia_step', 'main', 'prepare', 'read_data'].
   Code2Flow: Found calls ['build_lci()', 'curate_data()', 'export()', 'lcia_step()', 'main()', 'prepare()', 'print()'].
   Code2Flow: Found variables ['print->UNKNOWN_MODULE', 'results-><Call owner_token=None token=lcia_step>'].
   Code2Flow: Filtering into subset...
   Code2Flow: Generating output file...
   Code2Flow: Wrote output file 'data/callgraph.gv' with 7 nodes and 6 edges.
   Code2Flow: For better machine readability, you can also try outputting in a json format.
   Code2Flow: Code2flow finished processing in 0.00 seconds.
   Code2Flow: Running graphviz to make the image...
   Code2Flow: Graphviz finished in 0.04 seconds.
   Code2Flow: Completed your flowchart! To see it, open 'data/callgraph.png'.
   [10/23/24 09:55:03] INFO     โœจSuccess! ๐Ÿ“ฆ โœ” Your project has been checked and packed โœ” ๐Ÿ“ฆ
   Code2Flow: :sparkles:[bold green]Success![/bold green] :package: :heavy_check_mark: Your project has been checked and packed :heavy_check_mark: :package:

The callgraph construction is done in an static manner, meaning that the code is not run again. In this case, the computation graph looks like the following:

docs/callgraph.png

๐Ÿ“ซ Contact

gustavo.larrea@list.lu

โ™ป๏ธ License

MIT

Contributors โœจ

Gustavo Larrea

Tomรกs Navarrete Gutiรฉrrez

ยฉ [2024] Luxembourg Institute of Science and Technology. All Rights Reserved

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bw2scaffold-0.0.9.tar.gz (82.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bw2scaffold-0.0.9-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file bw2scaffold-0.0.9.tar.gz.

File metadata

  • Download URL: bw2scaffold-0.0.9.tar.gz
  • Upload date:
  • Size: 82.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for bw2scaffold-0.0.9.tar.gz
Algorithm Hash digest
SHA256 5a554e60fa29a2c7bd636cf4c166fa60cef96276b03effdca89bcf7df73e23bc
MD5 3408bd3320fb52a930df7d6b5e1d0a51
BLAKE2b-256 00df09c1c94d6004cd815bd1094d5060ed1300839ef9f7214802009049cd20b5

See more details on using hashes here.

File details

Details for the file bw2scaffold-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: bw2scaffold-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for bw2scaffold-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 3ed6a8cb3aad4637cfd4cc091da5bf65d72df9a04fc9b4c1c4a5ffbc2aba0933
MD5 4a57598a7d88aa1f2b141093c09b9e8b
BLAKE2b-256 532b4a32eb6d983a6ab0d3c058ef64a52985a5f8ce18d8f6e7fbfe60ca7d0316

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page