### Running Brightway2 Setup (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This function initializes the necessary directories and default databases for Brightway2. It should be run once per installation or project setup. ```python bi.bw2setup() ``` -------------------------------- ### Initializing Brightway2 LCA (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This snippet creates an LCA object using the prepared demand and data objects. This object holds the matrices and setup for the LCA calculation. ```python lca = bc.LCA(demand=demand, data_objs=data_objs) ``` -------------------------------- ### Viewing Brightway2 Function Help (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This uses the IPython/Jupyter '?' magic command to display the docstring and help information for the `bd.prepare_lca_inputs` function. ```python bd.prepare_lca_inputs? ``` -------------------------------- ### Initializing Exiobase Importer (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This snippet creates an instance of the Exiobase3MonetaryImporter. It requires the path to the Exiobase data file and a name for the database to be created in Brightway2. ```python ex = Exiobase3MonetaryImporter( Path("/Users/cmutel/Documents/LCA/EXIOBASE/3.8.1/IOT_2015_pxp"), "Exiobase 3.8.1 Monetary 2015" ) ``` -------------------------------- ### Preparing LCA Inputs (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This function prepares the necessary demand dictionary and data objects (matrices, methods) required to initialize a Brightway2 LCA calculation. ```python demand, data_objs, _ = bd.prepare_lca_inputs({act: 1}, ipcc) ``` -------------------------------- ### Getting Random Database Activity and ID (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb Similar to a previous snippet, this retrieves a random activity but also explicitly accesses and displays its internal Brightway2 database ID. ```python act = bd.Database("Exiobase 3.8.1 Monetary 2015").random() act, act.id ``` -------------------------------- ### Setting Brightway2 Current Project (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This command sets the currently active Brightway2 project. Subsequent operations will be performed within this project context. ```python bd.projects.set_current("EXIOBASE 3.8.1 2015") ``` -------------------------------- ### Getting Random Database Activity (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This code retrieves a random activity object from the specified Brightway2 database. This is often used for testing or exploring database contents. ```python act = bd.Database("Exiobase 3.8.1 Monetary 2015").random() act ``` -------------------------------- ### Writing Importer Database (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This method writes the processed Exiobase data, after applying strategies, into a new Brightway2 database with the specified name. ```python ex.write_database() ``` -------------------------------- ### Applying Importer Strategies (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This method applies a set of predefined strategies to the imported Exiobase data. Strategies handle data cleaning, linking, and other processing steps before writing to the database. ```python ex.apply_strategies() ``` -------------------------------- ### Importing Brightway2 Libraries (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This snippet imports the necessary Brightway2 modules and the specific Exiobase monetary importer class, along with the pathlib module for path handling. ```python import bw2data as bd import bw2io as bi import bw2calc as bc from bw2io.importers.exiobase3_monetary import Exiobase3MonetaryImporter from pathlib import Path ``` -------------------------------- ### Deleting Brightway2 Project (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This command deletes a Brightway2 project by its name. The second argument `True` confirms the deletion without prompting. ```python bd.projects.delete_project("EXIOBASE 3.8.1 2015", True) ``` -------------------------------- ### Accessing LCA Technosphere Matrix (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This accesses the technosphere matrix used internally by the LCA object. This matrix represents the system model of production activities. ```python lca.technosphere_matrix ``` -------------------------------- ### Timing LCA Recalculation (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This uses the IPython/Jupyter `%timeit` magic command to measure the execution time of recalculating the LCIA for a specific activity ID with a demand of 1. ```python %timeit lca.redo_lcia({12254: 1}) ``` -------------------------------- ### Running LCA Inventory and Impact Assessment (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb These methods execute the core LCA calculation steps: `lci()` calculates the life cycle inventory, and `lcia()` calculates the life cycle impact assessment scores based on the defined method. ```python lca.lci() lca.lcia() ``` -------------------------------- ### Accessing LCA Impact Score (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This accesses the calculated total impact score from the completed LCA object. The score corresponds to the impact method defined during initialization. ```python lca.score ``` -------------------------------- ### Defining LCA Impact Method (Python) Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Exiobase 3.8 import.ipynb This snippet defines a tuple representing a specific impact assessment method from the default Brightway2 methods database. The tuple structure identifies the method, category, and subcategory. ```python ipcc = ('IPCC 2013', 'climate change', 'GWP 100a') ``` -------------------------------- ### Importing Brightway2 Libraries - Python Source: https://github.com/brightway-lca/brightway2-io/blob/main/dev/Untitled.ipynb Imports the `bw2data` library for managing databases and core Brightway2 data structures, and the `bw2io` library for handling data input and output operations. These imports are fundamental prerequisites for most Brightway2 workflows. ```python import bw2data as bd import bw2io as bi ``` -------------------------------- ### Importing and Processing Ecoinvent Database using brightway2-io in Python Source: https://github.com/brightway-lca/brightway2-io/blob/main/README.rst Demonstrates the typical workflow for using `brightway2-io` to import an ecoinvent database. It shows initializing the importer, applying standard processing strategies, checking for unlinked exchanges, and writing the processed data to the Brightway database. ```ipython In [1]: import bw2io as bi In [2]: import brightway2 as bw2 In [3]: bi.__version__ Out[3]: (0, 8, 7) In [4]: bw2.__version__ Out[4]: (2, 4, 1) In [5]: importer = bi.SingleOutputEcospold2Importer('path/to/ecoinvent/datasets/', 'ei_38_cutoff') Extracting XML data from 19565 datasets Extracted 19565 datasets in 19.21 seconds In [6]: importer.apply_strategies() Applying strategy: normalize_units Applying strategy: update_ecoinvent_locations Applying strategy: remove_zero_amount_coproducts Applying strategy: remove_zero_amount_inputs_with_no_activity Applying strategy: remove_unnamed_parameters Applying strategy: es2_assign_only_product_with_amount_as_reference_product Applying strategy: assign_single_product_as_activity Applying strategy: create_composite_code Applying strategy: drop_unspecified_subcategories Applying strategy: fix_ecoinvent_flows_pre35 Applying strategy: drop_temporary_outdated_biosphere_flows Applying strategy: link_biosphere_by_flow_uuid Applying strategy: link_internal_technosphere_by_composite_code Applying strategy: delete_exchanges_missing_activity Applying strategy: delete_ghost_exchanges Applying strategy: remove_uncertainty_from_negative_loss_exchanges Applying strategy: fix_unreasonably_high_lognormal_uncertainties Applying strategy: set_lognormal_loc_value Applying strategy: convert_activity_parameters_to_list Applying strategy: add_cpc_classification_from_single_reference_product Applying strategy: delete_none_synonyms Applied 21 strategies in 3.62 seconds In [7]: importer.statistics() 19565 datasets 629959 exchanges 0 unlinked exchanges Out[7]: (19565, 629959, 0) In [8]: if importer.statistics()[2] == 0: ...: importer.write_database() ...: else: ...: print("There are unlinked exchanges.") ...: importer.write_excel() ...: 19565 datasets 629959 exchanges 0 unlinked exchanges Writing activities to SQLite3 database: 0% [##############################] 100% | ETA: 00:00:00 Total time elapsed: 00:02:29 Title: Writing activities to SQLite3 database: Started: 11/07/2022 11:55:57 Finished: 11/07/2022 11:58:26 Total time elapsed: 00:02:29 CPU %: 32.90 Memory %: 11.17 Created database: ei_38_cutoff ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.