Module Contents#



Base class for single and multi LCA classes

class bw2calc.lca_base.LCABase[source]#


Inheritance diagram of bw2calc.lca_base.LCABase

Base class for single and multi LCA classes

property activity_dict[source]#
property biosphere_dict[source]#
property product_dict[source]#
check_selective_use(matrix_label: str) Tuple[bool, bool][source]#
decompose_technosphere() None[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.


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.

has(label: str) bool[source]#

Shortcut to find out if matrix data for type {label}_matrix is present in the given data objects.

Returns a boolean. Will return True even if data for a zero-dimensional matrix is given.


Use one-shot approach to efficiently calculate the inverse of the technosphere matrix by simultaneously solving Ax=b for all b.

Technosphere matrix inversion is often not the most efficient approach. See brightway-lca/brightway2-calc#35

See Intel forum for a discussion on why we use this approach.


Set a flag to use the current values as first element when iterating.

When creating the class instance, we already use the first index. This method allows us to use the values for the first index.

Note that the methods .lci_calculation() and .lcia_calculation() will be called on the current values, even if these calculations have already been done.

lci(demand: dict | None = None, factorize: bool = False) None[source]#

Calculate a life cycle inventory.

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


  2. Build the demand array

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


  • factorize (bool, optional): 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 (MatrixBuilder object, optional): 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 matrices.

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

lcia(demand: dict | None = None) None[source]#

Calculate the life cycle impact assessment.

  1. Load and construct the characterization matrix

  2. Multiply the characterization matrix by the life cycle inventory

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

load_lci_data(nonsquare_ok=False) None[source]#

Load inventory data and create technosphere and biosphere matrices.

normalize() None[source]#

Multiply characterized inventory by flow-specific normalization factors.

redo_lci(demand: dict | None = None) None[source]#

Redo LCI with same databases but different demand.

  • demand (dict): A demand dictionary.

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


If you want to redo the LCIA as well, use

redo_lcia(demand) directly.

redo_lcia(demand: dict | None = None) None[source]#

Redo LCIA, optionally with new demand.

  • demand (dict, optional): 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.

remap_inventory_dicts() None[source]#

Remap self.dicts.activity|product|biosphere and self.demand from database integer IDs to keys ((database name, code)).

Uses remapping dictionaries in self.remapping_dicts.

solve_linear_system(demand: numpy.ndarray | None = None) None[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 pypardiso or 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.

weight() None[source]#

Multiply characterized inventory by weighting value.

Can be done with or without normalization.

weighting() None[source]#

Backwards compatibility. Switching to verb form consistent with .normalize.