# bw2calc.lca#

## Module Contents#

### Classes#

 LCA A static LCI or LCIA calculation.

### Attributes#

class bw2calc.lca.LCA(demand, method=None, weighting=None, normalization=None, database_filepath=None, log_config=None, presamples=None, seed=None, override_presamples_seed=False)[source]#

Bases: object

A static LCI or LCIA calculation.

Following the general philosophy of Brightway2, and good software practices, there is a clear separation of concerns between retrieving and formatting data and doing an LCA. Building the necessary matrices is done with MatrixBuilder objects (matrixbuilders). The LCA class only does the LCA calculations themselves.

Create a new LCA calculation.

Parameters
• demand (*) – The demand or functional unit. Needs to be a dictionary to indicate amounts, e.g. {("my database", "my process"): 2.5}.

• method (*) – LCIA Method tuple, e.g. ("My", "great", "LCIA", "method"). Can be omitted if only interested in calculating the life cycle inventory.

Returns

A new LCA object

property score[source]#

The LCIA score as a float.

Note that this is a property, so it is foo.lca, not foo.score()

build_demand_array(demand=None)[source]#

Turn the demand dictionary into a NumPy array of correct size.

Parameters

demand (*) – Demand dictionary. Optional, defaults to self.demand.

Returns

A 1-dimensional NumPy array

decompose_technosphere()[source]#

Factorize the technosphere matrix into lower and upper triangular matrices, $$A=LU$$. Does not solve the linear system $$Ax=B$$.

Doesn’t return anything, but creates self.solver.

Warning

Incorrect results could occur if a technosphere matrix was factorized, and then a new technosphere matrix was constructed, as self.solver would still be the factorized older technosphere matrix. You are responsible for deleting self.solver when doing these types of advanced calculations.

fix_dictionaries()[source]#

Fix technosphere and biosphere dictionaries from this:

{mapping integer id: matrix row/column index}

To this:

{(database, key): matrix row/column index}

This isn’t needed for the LCA calculation itself, but is helpful when interpreting results.

Doesn’t require any arguments or return anything, but changes self.activity_dict, self.product_dict and self.biosphere_dict.

get_array_filepaths()[source]#

Use utility functions to get all array filepaths

lci(factorize=False, builder=TBMBuilder)[source]#

Calculate a life cycle inventory.

1. Load LCI data, and construct the technosphere and biosphere matrices.

2. Build the demand array

3. Solve the linear system to get the supply array and life cycle inventory.

Parameters
• factorize (*) – Factorize the technosphere matrix. Makes additional calculations with the same technosphere matrix much faster. Default is False; not useful is only doing one LCI calculation.

• builder (*) – Default is bw2calc.matrices.TechnosphereBiosphereMatrixBuilder, which is fine for most cases. Custom matrix builders can be used to manipulate data in creative ways before building the matrices.

Warning

Custom matrix builders should inherit from TechnosphereBiosphereMatrixBuilder, because technosphere inputs need to have their signs flipped to be negative, as we do $$A^{-1}f$$ directly instead of $$(I - A^{-1})f$$.

Doesn’t return anything, but creates self.supply_array and self.inventory.

lci_calculation()[source]#

The actual LCI calculation.

Separated from lci to be reusable in cases where the matrices are already built, e.g. redo_lci and Monte Carlo classes.

lcia(builder=MatrixBuilder)[source]#

Calculate the life cycle impact assessment.

1. Load and construct the characterization matrix

2. Multiply the characterization matrix by the life cycle inventory

Parameters

builder (*) – Default is bw2calc.matrices.MatrixBuilder, which is fine for most cases. Custom matrix builders can be used to manipulate data in creative ways before building the characterization matrix.

Doesn’t return anything, but creates self.characterized_inventory.

lcia_calculation()[source]#

The actual LCIA calculation.

Separated from lcia to be reusable in cases where the matrices are already built, e.g. redo_lcia and Monte Carlo classes.

Load data and create technosphere and biosphere matrices.

Load data and create characterization matrix.

This method will filter out regionalized characterization factors. This filtering needs access to bw2data - therefore, regionalized methods will cause incorrect results if bw2data is not importable.

Load weighting data, a 1-element array.

normalization_calculation()[source]#

The actual normalization calculation.

Creates self.normalized_inventory.

normalize()[source]#

Multiply characterized inventory by flow-specific normalization factors.

rebuild_biosphere_matrix(vector)[source]#

Build a new biosphere matrix using the same row and column indices, but different values. Useful for Monte Carlo iteration or sensitivity analysis.

Parameters

vector (*) – 1-dimensional NumPy array with length (# of biosphere parameters), in same order as self.bio_params.

Doesn’t return anything, but overwrites self.biosphere_matrix.

rebuild_characterization_matrix(vector)[source]#

Build a new characterization matrix using the same row and column indices, but different values. Useful for Monte Carlo iteration or sensitivity analysis.

Parameters

vector (*) – 1-dimensional NumPy array with length (# of characterization parameters), in same order as self.cf_params.

Doesn’t return anything, but overwrites self.characterization_matrix.

rebuild_technosphere_matrix(vector)[source]#

Build a new technosphere matrix using the same row and column indices, but different values. Useful for Monte Carlo iteration or sensitivity analysis.

Parameters

vector (*) – 1-dimensional NumPy array with length (# of technosphere parameters), in same order as self.tech_params.

Doesn’t return anything, but overwrites self.technosphere_matrix.

redo_lci(demand=None)[source]#

Redo LCI with same databases but different demand.

Parameters

demand (*) – A demand dictionary.

Doesn’t return anything, but overwrites self.demand_array, self.supply_array, and self.inventory.

Warning

If you want to redo the LCIA as well, use redo_lcia(demand) directly.

redo_lcia(demand=None)[source]#

Redo LCIA, optionally with new demand.

Parameters

demand (*) – New demand dictionary. Optional, defaults to self.demand.

Doesn’t return anything, but overwrites self.characterized_inventory. If demand is given, also overwrites self.demand_array, self.supply_array, and self.inventory.

reverse_dict()[source]#

Construct reverse dicts from technosphere and biosphere row and col indices to activity_dict/product_dict/biosphere_dict keys.

Returns

(reversed self.activity_dict, self.product_dict and self.biosphere_dict)

solve_linear_system()[source]#

Master solution function for linear system $$Ax=B$$.

To most numerical analysts, matrix inversion is a sin.

—Nicolas Higham, Accuracy and Stability of Numerical Algorithms, Society for Industrial and Applied Mathematics, Philadelphia, PA, USA, 2002, p. 260.

We use UMFpack, which is a very fast solver for sparse matrices.

If the technosphere matrix has already been factorized, then the decomposed technosphere (self.solver) is reused. Otherwise the calculation is redone completely.

switch_method(method)[source]#

Switch to LCIA method method

switch_normalization(normalization)[source]#

Switch to LCIA normalization normalization

switch_weighting(weighting)[source]#

Switch to LCIA weighting weighting

to_dataframe(cutoff=200)[source]#

Return all nonzero elements of characterized inventory as Pandas dataframe

top_activities(**kwargs)[source]#

Call bw2analyzer.ContributionAnalyses.annotated_top_processes

top_emissions(**kwargs)[source]#

Call bw2analyzer.ContributionAnalyses.annotated_top_emissions

weight()[source]#

Multiply characterized inventory by weighting value.

Can be done with or without normalization.

weighting_calculation()[source]#

The actual weighting calculation.

Multiples weighting value by normalized inventory, if available, otherwise by characterized inventory.

Creates self.weighted_inventory.