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 pipx (recommended)
We recommend to use pipx, which allows to install python applications in isolated environments (installation beyond a specific environment). Do not worry, using pipx will not mess up your environments ๐.
pipx install git+https://git.list.lu/gustavo.larrea/replicable-lca.git
If you do not have pipx installed, you can, first, install it with pip:
pip install pipx
Then, make all application accessible:
pipx ensurepath
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:
๐ซ Contact
โป๏ธ License
MIT
Contributors โจ
Gustavo Larrea
Tomรกs Navarrete Gutiรฉrrez
ยฉ [2024] Luxembourg Institute of Science and Technology. All Rights Reserved
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bw2scaffold-0.0.8.post1.dev4.tar.gz.
File metadata
- Download URL: bw2scaffold-0.0.8.post1.dev4.tar.gz
- Upload date:
- Size: 88.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5624f4614d4d7b09bc44142b23e6e4874cf6c1e8aa8e1ed48b84aad43452fe24
|
|
| MD5 |
690bda78fba98f7f26263958f559abb3
|
|
| BLAKE2b-256 |
cf49435d2b944a28e2c87fd593624ceccf810c2e5ac7326aad3b4bf1c817884f
|
File details
Details for the file bw2scaffold-0.0.8.post1.dev4-py3-none-any.whl.
File metadata
- Download URL: bw2scaffold-0.0.8.post1.dev4-py3-none-any.whl
- Upload date:
- Size: 26.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3de962ed888804c212286aa1607583e68f697cbbaf7e20d0ed6d964b1e7a4caf
|
|
| MD5 |
a53dc8acc123265a40d5cebc4dbd65a3
|
|
| BLAKE2b-256 |
59f5f9ae83b55ec0fd16b880eaf0090692c0e754f2e0d5285c8a31ccb43b1684
|