REGISTER NOW: DdS Autumn School! 🇨🇭 Grosshöchstetten (Switzerland) 🗓️ 6.-11. October 2024

bw2analyzer.contribution#

Module Contents#

Classes#

ContributionAnalysis

class bw2analyzer.contribution.ContributionAnalysis[source]#
annotate(sorted_data, rev_mapping)[source]#

Reverse the mapping from database ids to array indices

annotated_top_emissions(lca, names=True, **kwargs)[source]#

Get list of most damaging biosphere flows in an LCA, sorted by abs(direct impact).

Returns a list of tuples: (lca score, inventory amount, activity). If names is False, they returns the process key as the last element.

annotated_top_processes(lca, names=True, **kwargs)[source]#

Get list of most damaging processes in an LCA, sorted by abs(direct impact).

Returns a list of tuples: (lca score, supply, activity). If names is False, they returns the process key as the last element.

d3_treemap(matrix, rev_bio, rev_techno, limit=0.025, limit_type='percent')[source]#

Construct treemap input data structure for LCA result. Output like:

{
"name": "LCA result",
"children": [{
    "name": process 1,
    "children": [
        {"name": emission 1, "size": score},
        {"name": emission 2, "size": score},
        ],
    }]
}
get_name(key)[source]#
hinton_matrix(lca, rows=5, cols=5)[source]#
sort_array(data, limit=25, limit_type='number', total=None)[source]#

Common sorting function for all top methods. Sorts by highest value first.

Operates in either number or percent mode. In number mode, return limit values. In percent mode, return all values >= (total * limit); where 0 < limit <= 1.

Returns 2-d numpy array of sorted values and row indices, e.g.:

ContributionAnalysis().sort_array((1., 3., 2.))

returns

(
    (3, 1),
    (2, 2),
    (1, 0)
)
Args:
  • data (numpy array): A 1-d array of values to sort.

  • limit (number, default=25): Number of values to return, or percentage cutoff.

  • limit_type (str, default=``number``): Either number or percent.

  • total (number, default=None): Optional specification of summed data total.

Returns:

2-d numpy array of values and row indices.

top_emissions(matrix, **kwargs)[source]#

Return an array of [value, index] biosphere emissions.

top_matrix(matrix, rows=5, cols=5)[source]#

Find most important (i.e. highest summed) rows and columns in a matrix, as well as the most corresponding non-zero individual elements in the top rows and columns.

Only returns matrix values which are in the top rows and columns. Element values are returned as a tuple: (row, col, row index in top rows, col index in top cols, value).

Example:

matrix = [
    [0, 0, 1, 0],
    [2, 0, 4, 0],
    [3, 0, 1, 1],
    [0, 7, 0, 1],
]

In this matrix, the row sums are (1, 6, 5, 8), and the columns sums are (5, 7, 6, 2). Therefore, the top rows are (3, 1) and the top columns are (1, 2). The result would therefore be:

(
    (
        (3, 1, 0, 0, 7),
        (3, 2, 0, 1, 1),
        (1, 2, 1, 1, 4)
    ),
    (3, 1),
    (1, 2)
)
Args:
  • matrix (array or matrix): Any Python object that supports the .sum(axis=) syntax.

  • rows (int): Number of rows to select.

  • cols (int): Number of columns to select.

Returns:

(elements, top rows, top columns)

top_processes(matrix, **kwargs)[source]#

Return an array of [value, index] technosphere processes.