bw2calc.dense_lca#
Classes#
Convert the technosphere_matrix to a numpy array and solve with numpy.linalg. |
Module Contents#
- class bw2calc.dense_lca.DenseLCA(demand: dict, method: tuple | None = None, weighting: str | None = None, normalization: str | None = None, data_objs: Iterable[pathlib.Path | fsspec.AbstractFileSystem | bw_processing.DatapackageBase] | None = None, remapping_dicts: Iterable[dict] | None = None, log_config: dict | None = None, seed_override: int | None = None, use_arrays: bool | None = False, use_distributions: bool | None = False, selective_use: dict | None = False)[source]#
Bases:
bw2calc.lca.LCA
Convert the technosphere_matrix to a numpy array and solve with numpy.linalg.
Create a new LCA calculation object.
Compatible with Brightway2 and 2.5 semantics. Can be static, stochastic, or iterative (scenario-based), depending on the
data_objs
input data..This class supports both stochastic and static LCA, and can use a variety of ways to describe uncertainty. The input flags use_arrays and use_distributions control some of this stochastic behaviour. See the [documentation for matrix_utils](brightway-lca/matrix_utils) for more information on the technical implementation.
- Parameters:
demand (dict[object: float]) – The demand for which the LCA will be calculated. The keys can be Brightway Node instances, (database, code) tuples, or integer ids.
method (tuple) – Tuple defining the LCIA method, such as (‘foo’, ‘bar’). Only needed if not passing data_objs.
weighting (string) – Tuple defining the LCIA weighting, such as (‘foo’, ‘bar’). Only needed if not passing data_objs.
weighting – String defining the LCIA normalization, such as ‘foo’. Only needed if not passing data_objs.
data_objs (list[bw_processing.Datapackage]) – List of bw_processing.Datapackage objects. Can be loaded via bw2data.prepare_lca_inputs or constructed manually. Should include data for all needed matrices.
remapping_dicts (dict[str, dict]) – Dict of remapping dictionaries that link Brightway Node ids to (database, code) tuples. remapping_dicts can provide such remapping for any of activity, product, biosphere.
log_config (dict) – Optional arguments to pass to logging. Not yet implemented.
seed_override (int) – RNG seed to use in place of Datapackage seed, if any.
use_arrays (bool) – Use arrays instead of vectors from the given data_objs
use_distributions (bool) – Use probability distributions from the given data_objs
selective_use (dict[str, dict]) – Dictionary that gives more control on whether use_arrays or use_distributions should be used. Has the form {matrix_label: {“use_arrays”|”use_distributions”: bool}. Standard matrix labels are technosphere_matrix, biosphere_matrix, and characterization_matrix.
- 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 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.