bw2analyzer.comparisons#

Module Contents#

Functions#

aggregated_dict(activity)

Return dictionary of inputs aggregated by input reference product.

compare_activities_by_grouped_leaves(activities, ...)

Compare activities by the impact of their different inputs, aggregated by the product classification of those inputs.

compare_activities_by_lcia_score(activities, lcia_method)

Compare selected activities to see if they are substantially different.

compare_dictionaries(one, two[, rel_tol, abs_tol])

Compare two dictionaries with form {str: float}, and return a set of keys where differences where present.

find_differences_in_inputs(activity[, rel_tol, ...])

Given an Activity, try to see if other activities in the same database (with the same name and

find_leaves(activity, lcia_method[, results, lca_obj, ...])

Traverse the supply chain of an activity to find leaves - places where the impact of that

get_cpc(activity)

get_value_for_cpc(lst, label)

group_leaves(leaves)

Group elements in leaves by their CPC (Central Product Classification) code.

bw2analyzer.comparisons.aggregated_dict(activity)[source]#

Return dictionary of inputs aggregated by input reference product.

bw2analyzer.comparisons.compare_activities_by_grouped_leaves(activities, lcia_method, mode='relative', max_level=4, cutoff=0.0075, output_format='list', str_length=50)[source]#

Compare activities by the impact of their different inputs, aggregated by the product classification of those inputs.

Parameters
  • activities – list of Activity instances.

  • lcia_method – tuple. LCIA method to use when traversing supply chain graph.

  • mode – str. If “relative” (default), results are returned as a fraction of total input. Otherwise, results are absolute impact per input exchange.

  • max_level – int. Maximum level in supply chain to examine.

  • cutoff – float. Fraction of total impact to cutoff supply chain graph traversal at.

  • output_format – str. See below.

  • html (str_length; int. If output_format is) –

  • have. (this controls how many characters each column label can) –

Raises

ValueErroractivities is malformed.

Returns

  • list: Tuple of (column labels, data)

  • html: HTML string that will print nicely in Jupyter notebooks.

  • pandas: a pandas DataFrame.

Return type

Depends on output_format

bw2analyzer.comparisons.compare_activities_by_lcia_score(activities, lcia_method, band=0.1)[source]#

Compare selected activities to see if they are substantially different.

Substantially different means that all LCIA scores lie within a band of band * max_lcia_score.

Inputs:

activities: List of Activity objects. lcia_method: Tuple identifying a Method

Returns

Nothing, but prints to stdout.

bw2analyzer.comparisons.compare_dictionaries(one, two, rel_tol=0.0001, abs_tol=1e-09)[source]#

Compare two dictionaries with form {str: float}, and return a set of keys where differences where present.

Tolerance values are inputs to math.isclose.

bw2analyzer.comparisons.find_differences_in_inputs(activity, rel_tol=0.0001, abs_tol=1e-09, locations=None, as_dataframe=False)[source]#

Given an Activity, try to see if other activities in the same database (with the same name and reference product) have the same input levels.

Tolerance values are inputs to math.isclose.

If differences are present, a difference dictionary is constructed, with the form:

{Activity instance: [(name of input flow (str), amount)]}

Note that this doesn’t reference a specific exchange, but rather sums all exchanges with the same input reference product.

Assumes that all similar activities produce the same amount of reference product.

(x, y), where x is the number of similar activities, and y is a dictionary of the differences. This dictionary is empty if no differences are found.

Parameters
  • activityActivity. Activity to analyze.

  • rel_tol – float. Relative tolerance to decide if two inputs are the same. See above.

  • abs_tol – float. Absolute tolerance to decide if two inputs are the same. See above.

  • locations – list, optional. Locations to restrict comparison to, if present.

  • as_dataframe – bool. Return results as pandas DataFrame.

Returns

dict or pandas.DataFrame.

bw2analyzer.comparisons.find_leaves(activity, lcia_method, results=None, lca_obj=None, amount=1, total_score=None, level=0, max_level=3, cutoff=0.025)[source]#

Traverse the supply chain of an activity to find leaves - places where the impact of that component falls below a threshold value.

Returns a list of (impact of this activity, amount consumed, Activity instance) tuples.

bw2analyzer.comparisons.get_cpc(activity)[source]#
bw2analyzer.comparisons.get_value_for_cpc(lst, label)[source]#
bw2analyzer.comparisons.group_leaves(leaves)[source]#

Group elements in leaves by their CPC (Central Product Classification) code.

Returns a list of (fraction of total impact, specific impact, amount, Activity instance) tuples.