bw2io.strategies.lcia#
Functions#
|
Add 'code' field to characterization factors using 'activity_hash', if 'code' not already present. |
|
Drop characterization factors (CFs) that don't have an 'input' attribute. |
Update flow names in ecoinvent 3.8 LCIA implementation to correct inconsistencies. |
|
|
Add CFs for biosphere flows with the same top-level categories as a given characterization. |
|
Rationalize LCIA method names by removing redundant parts and unifying naming conventions. |
|
Set characterization factor (CF) types to 'biosphere' for compatibility with LCI strategies. |
Module Contents#
- bw2io.strategies.lcia.add_activity_hash_code(data)[source]#
Add ‘code’ field to characterization factors using ‘activity_hash’, if ‘code’ not already present.
Iterates over the LCIA methods in the given data and adds a ‘code’ field to each characterization factor using the ‘activity_hash’ function, if the ‘code’ field is not already present.
- Parameters:
data (list) – A list of dictionaries representing LCIA methods with characterization factors.
- Returns:
A list of dictionaries representing the updated LCIA methods with ‘code’ field added to characterization factors.
- Return type:
list
Examples
>>> data = [ ... { ... "exchanges": [ ... { ... "name": "Characterization Factor 1", ... # Other fields needed for activity_hash function ... }, ... { ... "name": "Characterization Factor 2", ... "code": "existing_code", ... # Other fields needed for activity_hash function ... }, ... ], ... } ... ] >>> add_activity_hash_code(data) [ { 'exchanges': [ { 'name': 'Characterization Factor 1', 'code': 'generated_code', # Other fields needed for activity_hash function }, { 'name': 'Characterization Factor 2', 'code': 'existing_code', # Other fields needed for activity_hash function }, ], } ]
- bw2io.strategies.lcia.drop_unlinked_cfs(data)[source]#
Drop characterization factors (CFs) that don’t have an ‘input’ attribute.
Iterates over the LCIA methods in the given data and removes any characterization factors that don’t have an ‘input’ attribute.
- Parameters:
data (list) – A list of dictionaries representing LCIA methods with characterization factors.
- Returns:
A list of dictionaries representing the updated LCIA methods with unlinked characterization factors removed.
- Return type:
list
Examples
>>> data = [ ... { ... "exchanges": [ ... {"name": "Characterization Factor 1", "input": "input_1"}, ... {"name": "Characterization Factor 2"}, ... ], ... } ... ] >>> drop_unlinked_cfs(data) [ { 'exchanges': [ { 'name': 'Characterization Factor 1', 'input': 'input_1', }, ], } ]
- bw2io.strategies.lcia.fix_ecoinvent_38_lcia_implementation(data)[source]#
Update flow names in ecoinvent 3.8 LCIA implementation to correct inconsistencies.
Ecoinvent 3.8 LCIA implementation uses some flow names from 3.7. Updates these flow names when possible and deletes them when not.
- Parameters:
data (list) – A list of dictionaries representing LCIA methods with characterization factors.
- Returns:
A list of dictionaries representing the updated LCIA methods with corrected flow names.
- Return type:
list
Examples
>>> data = [ ... { ... "name": "Method 1", ... "exchanges": [ ... {"name": "Cyfluthrin", "categories": ("soil", "agricultural")}, ... ], ... } ... ] >>> fix_ecoinvent_38_lcia_implementation(data) [ { "name": "Method 1", "exchanges": [ {"name": "Beta-cyfluthrin", "categories": ("soil", "agricultural")}, ], } ]
Notes
The function includes a hardcoded mapping to fix known inconsistencies in flow names. This may not cover all possible inconsistencies and might need to be updated in the future.
- bw2io.strategies.lcia.match_subcategories(data, biosphere_db_name, remove=True)[source]#
Add CFs for biosphere flows with the same top-level categories as a given characterization.
Given a characterization with a top-level category, e.g. (‘air’,), Finds all biosphere flows with the same top-level categories and adds CFs for these flows as well. It doesn’t replace CFs for existing flows with multi-level categories. If remove is set to True, it also deletes the top-level CF, but only if it is unlinked.
- Parameters:
data (list) – A list of dictionaries representing LCIA methods with characterization factors.
biosphere_db_name (str) – The name of the biosphere database to look up flows.
remove (bool, optional) – If True, delete the top-level CF if it is unlinked. Default is True.
- Returns:
A list of dictionaries representing the updated LCIA methods with CFs added for biosphere flows with the same top-level categories.
- Return type:
list
Examples
>>> data = [ ... { ... "name": "Method 1", ... "exchanges": [ ... {"categories": ("air",), "name": "Emission", "unit": "kg", "amount": 1.0}, ... ], ... } ... ] >>> biosphere_db_name = "example_biosphere" >>> match_subcategories(data, biosphere_db_name) [ { 'name': 'Method 1', 'exchanges': [ {'categories': ('air',), 'name': 'Emission', 'unit': 'kg', 'amount': 1.0}, # Additional CFs for biosphere flows with the same top-level category ('air',) ], } ]
- bw2io.strategies.lcia.rationalize_method_names(data)[source]#
Rationalize LCIA method names by removing redundant parts and unifying naming conventions.
Iterates over the LCIA methods in the given data and updates the ‘name’ attribute of each method to remove unnecessary information and make the naming conventions more consistent.
- Parameters:
data (list) – A list of dictionaries representing LCIA methods with method names.
- Returns:
A list of dictionaries representing the updated LCIA methods with rationalized method names.
- Return type:
list
Examples
>>> data = [ ... {"name": ("Method 1 w/o LT", "Total")}, ... {"name": ("Method 2 no LT", "Total")}, ... {"name": ("Method 3", "Total")}, ... ] >>> rationalize_method_names(data) [ {'name': ('Method 1', 'without long-term')}, {'name': ('Method 2', 'without long-term')}, {'name': ('Method 3',)}, ]
- bw2io.strategies.lcia.set_biosphere_type(data)[source]#
Set characterization factor (CF) types to ‘biosphere’ for compatibility with LCI strategies.
Iterates over the LCIA methods in the given data and sets the ‘type’ attribute of each characterization factor to ‘biosphere’. This will overwrite existing ‘type’ values.
- Parameters:
data (list) – A list of dictionaries representing LCIA methods with characterization factors.
- Returns:
A list of dictionaries representing the updated LCIA methods with ‘biosphere’ set as the ‘type’ of characterization factors.
- Return type:
list
Examples
>>> data = [ ... { ... "exchanges": [ ... {"name": "Characterization Factor 1", "type": "original_type"}, ... {"name": "Characterization Factor 2"}, ... ], ... } ... ] >>> set_biosphere_type(data) [ { 'exchanges': [ { 'name': 'Characterization Factor 1', 'type': 'biosphere', }, { 'name': 'Characterization Factor 2', 'type': 'biosphere', }, ], } ]