bw2calc.multi_lca#

Attributes#

Classes#

DemandsValidator

MultiLCA

Perform LCA on multiple demands, impact categories, and normalization and weighting sets.

Module Contents#

class bw2calc.multi_lca.DemandsValidator[source]#

Bases: pydantic.BaseModel

demands: dict[str, dict[int, float]][source]#
class bw2calc.multi_lca.MultiLCA(demands: dict[str, dict[int, float]], method_config: dict | bw2calc.method_config.MethodConfig, data_objs: Iterable[pathlib.Path | fsspec.AbstractFileSystem | bw_processing.DatapackageBase], 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 = None)[source]#

Bases: bw2calc.lca.LCABase

Perform LCA on multiple demands, impact categories, and normalization and weighting sets.

Builds only one technosphere and biosphere matrix which can cover all demands.

Main differences from the base LCA class:

  • Many attributes are plural, such as supply_arrays, inventories, characterization_matrices`

  • demands must be a dictionary with str keys, e.g. {‘my truck’: {12345: 1}}

  • demands must have integer IDs; you can’t pass (‘database’, ‘code’) or Activity objects.

  • Calculation results are a dictionary with keys of functional units and impact categories

The calculation procedure is the same as for singular LCA: lci(), lcia(), and next(). See the LCA documentation for these methods and their input arguments.

Parameters:
  • demands (dict[str, dict[int, float]]) – The demands for which the LCA will be calculated. The keys identify functional unit sets.

  • method_config (dict | MethodConfig) – Dictionary satisfying the MethodConfig specification or MethodConfig instance.

  • data_objs (list[bw_processing.Datapackage]) – List of bw_processing.Datapackage objects. 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.

build_demand_array(demands: dict | None = None) 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

abstract decompose_technosphere() None[source]#
filter_package_by_identifier(data_objs: Iterable[bw_processing.DatapackageBase], identifier: list[str]) list[bw_processing.DatapackageBase][source]#

Filter the datapackage resources in data_objs whose “identifier” attribute equals input argument identifier.

Used in splitting up impact categories, normalization, and weighting matrices.

lci() None[source]#
lci_calculation() None[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() None[source]#
lcia_calculation() None[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_lcia_data(data_objs: Iterable[bw_processing.DatapackageBase] | None = None) None[source]#

Load data and create characterization matrices.

This method will filter out regionalized characterization factors.

load_normalization_data(data_objs: Iterable[bw_processing.DatapackageBase] | None = None) None[source]#

Load normalization data.

load_weighting_data(data_objs: Iterable[bw_processing.DatapackageBase] | None = None) None[source]#

Load weighting data.

normalization_calculation() None[source]#

The actual normalization calculation.

Creates self.normalized_inventories.

redo_lci() None[source]#
redo_lcia() None[source]#
weighting_calculation() None[source]#

The actual weighting calculation.

Multiplies weighting value by normalized inventories, if available, otherwise by

characterized inventories.

Creates self.weighted_inventories.

config[source]#
demands[source]#
dicts[source]#
matrix_labels = ['technosphere_mm', 'biosphere_mm'][source]#
matrix_list_labels = ['characterization_mm_dict', 'normalization_mm_dict', 'weighting_mm_dict'][source]#
packages[source]#
remapping_dicts[source]#
property scores: dict[source]#

The LCIA score as a float.

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

seed_override = None[source]#
selective_use[source]#
use_arrays = False[source]#
use_distributions = False[source]#
bw2calc.multi_lca.logger[source]#