### Install Brightway with pip (x64) Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/index.md Install the Brightway25 package and the pypardiso solver using pip. Note that 'brightway25' is an installation convenience and not meant for import. ```console pip install brightway25 pypardiso ``` -------------------------------- ### Install Brightway with pip (Apple Silicon/ARM) Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/index.md Install Brightway and scikit-umfpack on MacOS (Apple Silicon/ARM) using pip. 'brightway25' is for installation only. ```console pip install brightway25 scikit-umfpack ``` -------------------------------- ### Data Migration Example Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/overview/importing.md Example of a data migration configuration to transform 'Water' emissions from 'kilogram' to 'cubic meter' with a multiplier. Migrations are applied using the `.migrate(migrations_name)` method. ```python { 'fields': `'name', 'categories', 'type', 'unit', 'data': ` ( ## First element is input data in the order of `fields` above ('Water', ('air',), 'biosphere', 'kilogram'), ## Second element is new values to substitute { 'unit': 'cubic meter', 'multiplier': 0.001 } ) ` } ``` -------------------------------- ### Git Submodule Configuration Example Source: https://github.com/brightway-lca/brightway-documentation/blob/main/README.md This is an example of how a Git submodule's configuration appears in the .gitmodules file after updating its URL. ```ini [submodule "brightway2-data"] path = brightway2-data url = https://github.com/michaelweinold/brightway2-data branch = main ``` -------------------------------- ### Install Project with Initial Data Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/projects.md Creates a new project with basic data, such as elementary flows and LCIA categories. Choose a `` from the available options. ```python bi.remote.install_project('', '') ``` -------------------------------- ### Install SuiteSparse Dependencies with brew Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/index.md Install necessary dependencies for SuiteSparse on MacOS (Apple Silicon/ARM) using Homebrew. This is required for fast calculations. ```console brew install swig suite-sparse ``` -------------------------------- ### Install JupyterLab with Conda Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/index.md Install the jupyterlab library using conda from the conda-forge channel. This is an optional but recommended step. ```console conda install -c conda-forge jupyterlab ``` -------------------------------- ### List All Brightway Projects Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/projects.md Returns a sorted list of all available project names. No specific setup needed. ```python sorted(bd.projects) ``` -------------------------------- ### Retrieve datapackage Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/databases.md Gets the bw_processing datapackage associated with the database. ```python bd.Database('').datapackage() ``` -------------------------------- ### Get Current Active Project Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/projects.md Retrieves the name of the currently active project. No setup required. ```python bd.projects.current ``` -------------------------------- ### Create Conda Environment with Brightway (x64) Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/index.md Create a new Conda environment named 'brightway' and install Brightway25 from conda-forge and cmutel channels. ```console conda create -n brightway -c conda-forge -c cmutel brightway25 ``` -------------------------------- ### Create Python Virtual Environment with pip Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/index.md Use this command to create a new virtual environment for Brightway on Linux, Windows, or MacOS (x64). Ensure Python is installed first. ```console python -m venv C:/Users/me/virtualenvs/brightway ``` -------------------------------- ### List installed impact categories Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/ia.md Returns a sorted list of all available impact categories. ```python sorted(bd.methods) ``` -------------------------------- ### Access MultiLCA Inventory Results Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/lca.md Example structure of the inventories dictionary returned by MultiLCA. ```python { ("γ",): sparse_matrix, ("ε",): sparse_matrix, } ``` -------------------------------- ### Match Database Function Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/overview/importing.md Links exchanges to activities in other installed databases. Allows customization of fields used for matching and other options. ```python .match_database() ``` -------------------------------- ### Configure MultiLCA Impact Assessment Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/lca.md Setup MethodConfig and functional units for LCIA calculations. ```python method_config = bc.MethodConfig() ``` ```python functional_units = { "γ": {node_1.id: 1}, "ε": {node_2.id: 2}, } ``` ```python data_objs = bd.get_multilca_data_objs(functional_units, method_config) lca = bc.MultiLCA( demands=functional_units, method_config=impact_categories, data_objs=data_objs, ) lca.lci() lca.lcia() ``` -------------------------------- ### List Production Edges (Outputs) Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/inventory.md Get a list of all production edges (outputs produced) for a given node. This represents products or byproducts generated by the process. ```python list(my_node.production()) ``` -------------------------------- ### Get Linking Statistics Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Retrieve statistics on the number of edges that have been linked so far. ```python importer.statistics() ``` -------------------------------- ### Access Characterized Inventory Results Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/lca.md Example structure of characterized_inventories dictionary with multiple impact categories. ```python { (('', ''), "γ"): sparse_matrix, (('', ''), "ε"): sparse_matrix, (('', ''), "γ"): sparse_matrix, (('', ''), "ε"): sparse_matrix, } ``` -------------------------------- ### List Technosphere Edges (Inputs) Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/inventory.md Get a list of all technosphere edges (inputs consumed) for a given node. This represents materials or energy used by the process. ```python list(my_node.technosphere()) ``` -------------------------------- ### Export Conda Environment to File Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/faq/environment_management.md Saves the current Conda environment to a YAML file, including only packages installed from history. Replace placeholders with your environment and file details. ```bash conda activate conda env export --from-history > "/.yml" ``` -------------------------------- ### Build Documentation with Live Preview Source: https://github.com/brightway-lca/brightway-documentation/blob/main/README.md Run this command to automatically rebuild documentation on file changes and open a live preview. Ignores API documentation to prevent build loops. ```bash sphinx-autobuild source _build/html -a -j auto --ignore source/content/api* --open-browser ``` -------------------------------- ### Initialize Ecospold Importers Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Initialize importers for Ecospold 1 or 2 formats by specifying the directory path and database name. ```python importer = bi.SingleOutputEcospold1Importer('', '') ``` ```python importer = bi.SingleOutputEcospold2Importer('', '') ``` -------------------------------- ### Initialize Git Submodules Source: https://github.com/brightway-lca/brightway-documentation/blob/main/README.md Downloads and updates the submodule repositories required for documentation generation. ```bash git submodule update --init --recursive --remote --force ``` -------------------------------- ### Build Documentation Manually with Sphinx Source: https://github.com/brightway-lca/brightway-documentation/blob/main/README.md Use this command to build the documentation into a single HTML file. Ensure you are in the repository root directory. ```bash sphinx-build source _build/html --builder=singlehtml --jobs=auto --write-all; open _build/html/index.html ``` -------------------------------- ### Clone Repository Source: https://github.com/brightway-lca/brightway-documentation/blob/main/README.md Downloads the documentation repository from GitHub. ```bash git clone https://github.com/brightway-lca/brightway-documentation.git ``` -------------------------------- ### Create and Activate Virtual Environment on MacOS (ARM) Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/index.md Create a directory for virtual environments and then create and activate a new virtual environment for Brightway on MacOS with Apple Silicon. ```console cd mkdir virtualenvs python -m venv virtualenvs/brightway source virtualenvs/brightway/bin/activate ``` -------------------------------- ### Initialize Excel Importer Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Create an instance of the Excel importer using a file path. ```python importer = bi.ExcelImporter('') ``` -------------------------------- ### Instantiate a Database object Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/databases.md Creates a reference to an existing database by its name. ```python my_db = bd.Database('') ``` -------------------------------- ### Backup Brightway Project Directory Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/projects.md Creates a backup of a specified project's directory. Provide the project name and the desired backup directory path. ```python bi.backup.backup_project_directory( project='', dir_backup='' ) ``` -------------------------------- ### Initialize SimaPro CSV Importer Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Create an instance of the SimaPro block CSV importer using a pathlib Path object. ```python from pathlib import Path importer = bi.SimaProBlockCSVImporter(Path('')) ``` -------------------------------- ### Get All Data Attributes of an Edge Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/inventory.md Retrieve all data attributes of an edge as a dictionary. This is useful for inspecting the properties of an exchange. ```python my_edge.as_dict() ``` -------------------------------- ### Get All Data Attributes of a Node Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/inventory.md Retrieve all data attributes of a node as a dictionary. This is useful for inspecting node properties. ```python my_node.as_dict() ``` -------------------------------- ### Run Brightway Docker Containers Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/docker.md Commands to launch Jupyter Lab instances for Brightway 2 and 2.5. These containers are ephemeral, so consider mounting a data volume. ```bash docker run --rm -p 8888:8888 -e JUPYTER_ENABLE_LAB=yes brightway/bw2 ``` ```bash docker run --rm -p 8888:8888 -e JUPYTER_ENABLE_LAB=yes brightway/bw25 ``` -------------------------------- ### Get a Random Node from a Database Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/inventory.md Retrieve a single, random node from a specified database. Useful for sampling or testing. ```python bd.Database('').random() ``` -------------------------------- ### Add Unlinked Activities as Placeholders Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Create placeholder process or product nodes for activities referenced in the imported data but lacking producers. ```python importer.add_unlinked_activities() ``` -------------------------------- ### Activate Python Virtual Environment with pip Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/index.md Activate the created virtual environment. The exact command varies by operating system. ```console source C:/Users/me/virtualenvs/brightway/bin/activate ``` -------------------------------- ### List Biosphere Edges Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/inventory.md Get a list of all biosphere edges associated with a process. These typically represent environmental releases or resource extractions. ```python list(my_node.biosphere()) ``` -------------------------------- ### Implement a strategy with additional arguments using currying Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/overview/importing.md Use functools.partial to provide extra arguments to a strategy function that expects only one input. This allows integration with standard Brightway strategy application workflows. ```python def add_silly_string(data, string): for ds in data: ds['name'] += string return data ``` ```python from functools import partial add_silly_string_fixed = partial(add_silly_string, string="something silly") ``` -------------------------------- ### Get a Specific Node Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/inventory.md Retrieve a specific node by providing attribute-value pairs. Multiple filters can be combined with commas. For attributes with spaces, use a dictionary. ```python my_node = bd.get_node(my_attr="") ``` ```python bd.get_node(name="", location="bar") ``` ```python bd.get_node(**{"some value with spaces": True}) ``` -------------------------------- ### Restore Brightway Project from Backup Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/projects.md Restores a project from a previously created backup. Specify the path to the backup file and the desired project name for restoration. ```python bi.backup.restore_project_directory( fp='', project_name='' ) ``` -------------------------------- ### Import Local Ecoinvent Release Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Import a local Ecoinvent database file, apply strategies, and write the database to the project. ```python importer = bi.SingleOutputEcospold2Importer( dirpath='', db_name='' ) importer.apply_strategies() importer.write_database() ``` -------------------------------- ### Copy a Database Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/databases.md Creates a new database by copying the contents of an existing one. ```python copied_database = bd.Database('').copy('') ``` -------------------------------- ### View Repository Structure Source: https://github.com/brightway-lca/brightway-documentation/blob/main/README.md Displays the directory layout of the documentation repository. ```text . ├── environment.yml ├── source/ │ ├── conf.py | ├── index.md │ └── content/ │ ├── setup/ │ ├── introduction/ │ └── (...other documentation sections) ├── README.md ├── brightway2-io/ (git submodule) ├── brightway2-data/ (git submodule) └── (...other Brightway modules as git submodules) ``` -------------------------------- ### Recreate Conda Environment from File Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/faq/environment_management.md Creates a new Conda environment based on a provided YAML file. Ensure the file path is correct. ```bash conda env create -f "/environment.yml" ``` -------------------------------- ### Manage Conda Environment Data Paths Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/faq/data_management.md Commands for navigating and setting up environment-specific data directories in Conda. ```bash cd /envs/ ``` ```bash mkdir -p etc/conda/activate.d mkdir -p etc/conda/deactivate.d ``` ```bash #!/bin/sh export BRIGHTWAY2_DIR="" ``` ```bash #!/bin/sh unset BRIGHTWAY2_DIR ``` ```bash chmod +x etc/conda/activate.d/.sh chmod +x etc/conda/deactivate.d/.sh ``` -------------------------------- ### List all databases Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/databases.md Returns a sorted list of all currently registered database labels. ```python sorted(bd.databases) ``` -------------------------------- ### Migrate project to Brightway 2.5 Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/upgrading.md Python script to migrate an existing project to version 2.5. Requires the bw2data library. ```python import bw2data as bd bd.projects.set_current('') bd.projects.migrate_project_25() ``` -------------------------------- ### Create Conda Environment with Brightway (Apple Silicon/ARM) Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/index.md Create a new Conda environment for Apple Silicon (ARM) Macs, including brightway25, scikit-umfpack, and numpy. pypardiso is not compatible with ARM. ```console conda create -n brightway -c conda-forge brightway25 scikit-umfpack numpy">=2" scikit-umfpack">=0.4.2" ``` -------------------------------- ### Backup Brightway Project Directory Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/exporting.md Use this function to create a compressed backup of your entire Brightway project. Specify the project name and the target directory for the backup file. ```python bi.backup.backup_project_directory(project="", dir_backup="") ``` -------------------------------- ### Check database dependencies Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/databases.md Retrieves the list of other databases that the specified database refers to. ```python bd.Database('').metadata['depends'] ``` -------------------------------- ### Create a New Node Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/inventory.md Create a new node within a database by providing a dictionary of attributes, then save it. The `**attributes` syntax unpacks the dictionary into keyword arguments. ```python my_node = bd.Database('').new_node(**attributes) my_node.save() ``` -------------------------------- ### Calculate characterized inventory Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/lca.md Include a method parameter during input preparation to calculate the characterized inventory matrix. ```python my_functional_unit, data_objs, _ = bd.prepare_lca_inputs( {my_node: 42}, method=('', '') ) my_lca = bc.LCA(demand=my_functional_unit, data_objs=data_objs) my_lca.lci() my_lca.lcia() ``` -------------------------------- ### Configure BRIGHTWAY2_DIR Environment Variable Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/faq/data_management.md Commands to set the custom data directory path in Unix and Windows shells. ```bash echo 'export BRIGHTWAY2_DIR=' >> ~/.zshenv ``` ```powershell [Environment]::SetEnvironmentVariable("BRIGHTWAY2_DIR", "", "User") ``` -------------------------------- ### Import Ecoinvent Release Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Import an Ecoinvent release via the online portal using credentials and system model specifications. ```python bi.import_ecoinvent_release( version='', system_model='', username='', password='' ) ``` -------------------------------- ### Activate a Brightway Project Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/projects.md Sets a specific project as the active one. Replace '' with the desired project's name. ```python bd.projects.set_current(name='') ``` -------------------------------- ### Check database backend Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/databases.md Identifies the storage engine or modelling paradigm used by the database. ```python bd.Database('').metadata['backend'] ``` -------------------------------- ### Inspect Brightway database activity objects Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/faq/python.md Retrieve a random activity from a database and inspect its inheritance hierarchy. ```python import bw2data as bd import inspect my_database = bd.Database('') print(inspect.getmro(type(my_database.random()))) ``` -------------------------------- ### Applying Linking Strategies Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/overview/importing.md Use `.apply_strategies(some_new_strategy)` to apply new linking strategies to resolve unlinked exchanges. This method requires a list of strategies. ```python sp.apply_strategies(some_new_strategy) ``` -------------------------------- ### Restore Brightway Project Directory Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/exporting.md Restore a Brightway project from a previously created backup file. Ensure the file path points to a valid .tar.gz backup archive. ```python bi.backup.restore_project_directory(fp="") ``` -------------------------------- ### Locate Default Data Directories Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/faq/data_management.md Platform-specific default paths where Brightway stores project data. ```text C:\Documents and Settings\\Application Data\Local Settings\pylca\Brightway3 ``` ```text /Users//Library/Application Support/Brightway3 ``` ```text /home//.local/share/Brightway3 ``` -------------------------------- ### Copy a Brightway Project Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/projects.md Creates a duplicate of the currently active project. Specify the desired name for the new project. ```python bd.projects.copy_project(name='') ``` -------------------------------- ### Activate Conda Environment Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/index.md Activate the Conda environment named 'brightway'. ```console conda activate brightway ``` -------------------------------- ### Import Brightway core libraries Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/index.md Required imports for accessing Brightway's analysis, calculation, data management, and I/O modules. ```python import bw2analyzer as ba import bw2calc as bc import bw2data as bd import bw2io as bi ``` -------------------------------- ### Enable Stochastic LCA with Distributions Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/lca.md Enable probability distribution functions for stochastic calculations in LCA or MultiLCA. ```python bc.LCA(..., use_distributions=True) bc.MultiLCA(..., use_distributions=True) ``` -------------------------------- ### Apply Transformation Strategies Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Apply default or custom transformation strategies to the imported data. ```python importer.apply_strategies() ``` ```python importer.apply_strategy() ``` -------------------------------- ### Calculate life cycle inventory Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/lca.md Prepare inputs and initialize the LCA object to calculate the inventory matrix. ```python my_functional_unit, data_objs, _ = bd.prepare_lca_inputs({my_node: 42}) my_lca = bc.LCA(demand=my_functional_unit, data_objs=data_objs) my_lca.lci() ``` -------------------------------- ### Define Custom Transformation Strategy Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Create a function that accepts and returns the entire import data list. ```python from typing import List def my_custom_strategy(data: List[dict]) -> List[dict]: """Add very import information to each dataset""" for dataset in data: dataset["this is a dataset"] = True return data ``` -------------------------------- ### Update References Between Background Database Versions Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/overview/importing.md Use this transformation to update references from one background database version to a newer one. Ensure precise version matching and verify the transformation's effect. ```python import randonneur_data as rd registry = rd.Registry() registry.sample('ecoinvent-3.9.1-biosphere-ecoinvent-3.10-biosphere') { 'replace': [{ 'source': { 'name': 'Xylene', 'uuid': '0e6cf9f9-44ff-4395-ad3b-36109a32e6eb' }, 'target': { 'name': 'Xylenes, unspecified', 'formula': 'C8H10', 'uuid': '0e6cf9f9-44ff-4395-ad3b-36109a32e6eb' }, 'comment': 'Flow attribute change not listed in change report' }, { 'source': { 'uuid': 'ce11d77b-c85a-4f03-816e-714dcda260ea', 'name': 'Americium-241' }, 'target': { 'uuid': 'a0e98cdc-79cd-4073-9713-c1a48238883a', 'name': 'Americium-241' } }] } ``` -------------------------------- ### Add Database Name Strategy Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/overview/importing.md Applies the database name to each dataset. Useful for distinguishing data from different sources. ```python bw2io.strategies.generic.add_database_name ``` -------------------------------- ### Check database existence Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/databases.md Verifies if a specific database label exists in the current environment. ```python '' in bd.databases ``` -------------------------------- ### Create New Biosphere Database from Unlinked Flows Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Separate unlinked biosphere nodes into a new, distinct Brightway Database. ```python importer.create_new_biosphere('') ``` -------------------------------- ### List All Edges of a Process Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/inventory.md Retrieve a list of all edges (both inputs and outputs) defined for a given process node. This provides a comprehensive view of the process's connections. ```python list(my_node.edges()) ``` -------------------------------- ### Write Database Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/overview/importing.md Writes the imported data to a new Brightway2 database once all exchanges are successfully linked. ```python .write_database() ``` -------------------------------- ### Activate Conda Environment Source: https://github.com/brightway-lca/brightway-documentation/blob/main/README.md Activates the previously created 'sphinx' environment. ```bash conda activate sphinx ``` -------------------------------- ### Creating a New Biosphere Database Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/overview/importing.md Use `create_new_biosphere("new biosphere name")` to create a new biosphere database containing the unlinked flows. This is an alternative to adding them to an existing database. ```python create_new_biosphere("new biosphere name") ``` -------------------------------- ### Calculate weighted inventory Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/lca.md Include weighting factors during input preparation to calculate the weighted inventory matrix. ```python my_functional_unit, data_objs, _ = bd.prepare_lca_inputs( {my_node: 42}, method=('', ''), weighting=('', '') ) my_lca = bc.LCA(demand=my_functional_unit, data_objs=data_objs) my_lca.lci() my_lca.lcia() ``` -------------------------------- ### Calculate normalized inventory Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/lca.md Include normalization factors during input preparation to calculate the normalized inventory matrix. ```python my_functional_unit, data_objs, _ = bd.prepare_lca_inputs( {my_node: 42}, method=('', ''), normalization=('', '') ) my_lca = bc.LCA(demand=my_functional_unit, data_objs=data_objs) my_lca.lci() my_lca.lcia() ``` -------------------------------- ### Create Conda Environment Source: https://github.com/brightway-lca/brightway-documentation/blob/main/README.md Creates a new Conda environment named 'sphinx' using the provided environment file. ```bash conda env create -f 'environment.yaml --name sphinx' ``` -------------------------------- ### Check External Links with Sphinx Source: https://github.com/brightway-lca/brightway-documentation/blob/main/README.md Run this command from the repository root to check for dead external links in the documentation. It uses the Sphinx linkcheck builder with a specified number of parallel workers. ```bash sphinx-build -b linkcheck -D linkcheck_workers=20 source _build/linkcheck ``` -------------------------------- ### Write characterization data to a method Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/ia.md Saves the prepared characterization factor data to a specific impact category. ```python bd.Method(('', '')).write(my_cf_data) ``` -------------------------------- ### Import Ecoinvent 3.8 with bw2io Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/faq/ecoinvent.md Use SingleOutputEcospold2Importer to import Ecoinvent 3.8 data. Ensure you are using a compatible bw2io version for older Ecoinvent releases. ```python import bw2io import bw2data importer_ei38 = bw2io.SingleOutputEcospold2Importer( dirpath = , db_name = 'ei38' ) importer_ei38.apply_strategies() importer_ei38.statistics() ``` -------------------------------- ### Update individual packages Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/upgrading.md General syntax for updating a specific package using pip. ```console pip install -U ``` -------------------------------- ### Mermaid Diagram for GitHub Actions Workflow Source: https://github.com/brightway-lca/brightway-documentation/blob/main/README.md This Mermaid diagram illustrates the flow of events and actions involved in updating the Brightway documentation when the bw2data repository is updated, including the role of GitHub Apps for permissions. ```mermaid flowchart TD; id1([bw2data updated]) --> id2(bw2data Action: Re-Use Workflow) --> id3(bw2data Action: Trigger 'Update Submodules') --> id4(brightway-documentation Action: Update Submodules) --> id5([bw2data submodule in brightway-documentation updated]) id7(Documentation Workflow App)-- permissions to trigger run -->id3 ``` -------------------------------- ### Match Database Links Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Realize internal links among nodes within the imported data. ```python importer.match_database() ``` -------------------------------- ### Update Brightway libraries Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/installation/upgrading.md Commands to update the brightway25 package using different package managers. Ensure the target environment is activated before execution. ```console pip install -U brightway25 conda update -c conda-forge -c cmutel brightway25 mamba update -c conda-forge -c cmutel brightway25 ``` -------------------------------- ### Matching to Another Database Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/overview/importing.md Use `.match_database("another database")` to link technosphere or biosphere exchanges to a different background database. This is useful for resolving missing flows. ```python sp.match_database("another database") ``` -------------------------------- ### Create Information Box in MyST Markdown Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/contributing/formatting.md Utilize the ':::{note} ... :::' syntax in MyST Markdown to create colored information boxes. This helps highlight important notes or tips. ```markdown ::: {note} This is an information box ::: ``` -------------------------------- ### Enable Stochastic LCA with Presampled Arrays Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/lca.md Enable the use of presampled values from arrays for stochastic calculations. ```python bc.LCA(..., use_arrays=True) bc.MultiLCA(..., use_arrays=True) ``` -------------------------------- ### Create Randonneur Template for Unlinked Edges Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Create an Excel template specifically for matching unlinked edges using the Randonneur format. See the relevant documentation for customization. ```python filepath = importer.create_randonneur_excel_template_for_unlinked() ``` -------------------------------- ### Define Functional Units with Node Objects Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/lca.md Use Node objects as dictionary keys when functional units contain only a single product node. ```python functional_units = { node_1: {node_1.id: 4.88}, node_2: {node_2.id: 11}, } ``` -------------------------------- ### Add Unlinked Flows to Existing Biosphere Database Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Integrate unlinked biosphere flows into an already existing Brightway biosphere database. ```python importer.add_unlinked_flows_to_biosphere_database('') ``` -------------------------------- ### Link Imported Database to External Database Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Use this function to establish external links from your imported data to other Brightway Databases. Refer to the `bw2io.importers.base_lci.LCIImporter.match_database` documentation for customization options. ```python importer.match_database('') ``` -------------------------------- ### Writing Unlinked Exchanges to Excel Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/overview/importing.md Use `.write_excel("some name")` to generate a spreadsheet of characterization factors, including their linking status. This facilitates manual review and correction of unlinked exchanges. ```python sp.write_excel("some name") ``` -------------------------------- ### List All Consumer Edges Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/inventory.md Retrieve a list of all edges that consume the specified node. This shows which processes use the output of `my_node`. ```python list(my_node.consumers()) ``` -------------------------------- ### Create a New Edge Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/inventory.md Create a new edge (exchange) between nodes by providing a dictionary of attributes, including type, amount, and input, then save it. The `**attributes` syntax unpacks the dictionary into keyword arguments. ```python my_edge = my_node.new_edge(**attributes) my_edge.save() ``` -------------------------------- ### Curry Custom Transformation Strategy Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Use functools.partial to pass additional arguments to a transformation strategy. ```python from typing import List from functools import partial def my_custom_strategy(data: List[dict], favorite_color: str) -> List[dict]: """Add very import color information""" for dataset in data: dataset["my favorite color"] = favorite_color return data importer.apply_strategy(partial(my_custom_strategy, favorite_color="blue")) ``` -------------------------------- ### Calculate MultiLCA Inventory Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/lca.md Initialize and run an LCI calculation for multiple functional units using the MultiLCA class. ```python functional_units = { "γ": {node_1.id: 3.9}, "ε": {node_2.id: 6.2}, } data_objs = bd.get_multilca_data_objs(functional_units, {}) lca = bc.MultiLCA( demands=functional_units, method_config={}, data_objs=data_objs, ) lca.lci() ``` -------------------------------- ### Apply Randonneur Transformations Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/cheatsheet/importing.md Apply static transformations using the randonneur_data package. ```python importer.randonneur('').rename('') ``` -------------------------------- ### Inspect class inheritance hierarchy Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/faq/python.md Use inspect.getmro to view the full inheritance chain of an object's class. ```python import inspect print(inspect.getmro(type(my_object))) ``` -------------------------------- ### Statistics of Unlinked Exchanges Source: https://github.com/brightway-lca/brightway-documentation/blob/main/source/content/overview/importing.md Use `.statistics()` to view the number and types of unlinked exchanges after importing data. This helps identify what needs to be resolved. ```python > sp.statistics() 366 datasets 3991 exchanges 2639 unlinked exchanges Type biosphere: 170 unique unlinked exchanges Type technosphere: 330 unique unlinked exchanges ```