bw2analyzer.utils#
Functions#
|
Calculate contribution analysis (for technosphere processes) for all inventory datasets in one database for one LCIA method. |
Return generator with values a-z, then aa-az, ba-bz, then aaa-aaz, aba-abz, etc. |
|
|
Traverse a supply chain graph, and calculate the LCA scores of each component. Prints the result with the format: |
|
Traverse a supply chain graph, and prints the inputs of each component. |
|
Traverse a supply chain graph, and calculate the LCA scores of each component. Adds a dictionary to |
Module Contents#
- bw2analyzer.utils.contribution_for_all_datasets_one_method(database, method, progress=True)[source]#
Calculate contribution analysis (for technosphere processes) for all inventory datasets in one database for one LCIA method.
- Parameters:
*database* (str) – Name of database
*method* (tuple) – Method tuple
- Returns:
NumPy array of relative contributions. Each column sums to one. Lookup dictionary, dataset keys to row/column indices
- bw2analyzer.utils.infinite_alphabet()[source]#
Return generator with values a-z, then aa-az, ba-bz, then aaa-aaz, aba-abz, etc.
- bw2analyzer.utils.print_recursive_calculation(activity, lcia_method, amount=1, max_level=3, cutoff=0.01, string_length=130, file_obj=None, tab_character=' ', use_matrix_values=False, _lca_obj=None, _total_score=None, __level=0, __first=True)[source]#
Traverse a supply chain graph, and calculate the LCA scores of each component. Prints the result with the format:
{tab_character * level }{fraction of total score} ({absolute LCA score for this input} | {amount of input}) {input activity}
- Parameters:
activity –
Activity. The starting point of the supply chain graph.lcia_method – tuple. LCIA method to use when traversing supply chain graph.
amount – int. Amount of
activityto assess.max_level – int. Maximum depth to traverse.
cutoff – float. Fraction of total score to use as cutoff when deciding whether to traverse deeper.
string_length – int. Maximum length of printed string.
file_obj – File-like object (supports
.write), optional. Output will be written to this object if provided.tab_character – str. Character to use to indicate indentation.
use_matrix_values – bool. Take exchange values from the matrix instead of the exchange instance
amount. Useful for Monte Carlo, but can be incorrect if there is more than one exchange from the same pair of nodes.
- Normally internal args:
_lca_obj:
LCA. Can give an instance of the LCA class (e.g. when doing regionalized or Monte Carlo LCA) _total_score: float. Needed if specifying_lca_obj.- Internal args (used during recursion, do not touch);
__level: int. __first: bool.
- Returns:
Nothing. Prints to
sys.stdoutorfile_obj
- bw2analyzer.utils.print_recursive_supply_chain(activity, amount=1, max_level=2, cutoff=0, string_length=130, file_obj=None, tab_character=' ', __level=0)[source]#
Traverse a supply chain graph, and prints the inputs of each component.
This function is only for exploration; use
bw2calc.GraphTraversalfor a better performing function.The results displayed here can also be incorrect if
- Parameters:
activity –
Activity. The starting point of the supply chain graph.amount – int. Supply chain inputs will be scaled to this value.
max_level – int. Max depth to search for.
cutoff – float. Inputs with amounts less than
amount * cutoffwill not be printed or traversed further.string_length – int. Maximum length of each line.
file_obj – File-like object (supports
.write), optional. Output will be written to this object if provided.tab_character – str. Character to use to indicate indentation.
__level – int. Current level of the calculation. Only used internally, do not touch.
- Returns:
Nothing. Prints to
stdoutorfile_obj
- bw2analyzer.utils.recursive_calculation_to_object(activity, lcia_method, amount=1, max_level=3, cutoff=0.01, as_dataframe=False, root_label='root', use_matrix_values=False, _lca_obj=None, _total_score=None, __result_list=None, __level=0, __label='', __parent=None)[source]#
Traverse a supply chain graph, and calculate the LCA scores of each component. Adds a dictionary to
result_listof the form:- {
‘label’: Label of this branch. Starts with nothing, then A, AA, AB, AAA, AAB, etc. ‘score’: Absolute score of this activity ‘fraction’: Fraction of total score of this activity ‘amount’: Input amount of the reference product of this activity ‘name’: Name of this activity ‘key’: Activity key ‘root_label’: Starting label of root element for recursion.
}
- Parameters:
activity –
Activity. The starting point of the supply chain graph.lcia_method – tuple. LCIA method to use when traversing supply chain graph.
amount – int. Amount of
activityto assess.max_level – int. Maximum depth to traverse.
cutoff – float. Fraction of total score to use as cutoff when deciding whether to traverse deeper.
as_dataframe – Return results as a list (default) or a pandas
DataFrameuse_matrix_values – bool. Take exchange values from the matrix instead of the exchange instance
amount. Useful for Monte Carlo, but can be incorrect if there is more than one exchange from the same pair of nodes.
- Internal args (used during recursion, do not touch):
__result_list: list. __level: int. __label: str. __parent: str.
- Returns:
List of dicts