pulpo.utils.uncertainty.preparer#

Import of the uncertainty data an impact X(s) = sum_e q_e sum_j b_ej s_j depends on.

Which parameters#

Every entry b_ej of the intervention matrix on a flow e that the LCIA method characterizes, and every characterization factor q_e of the method on a flow that occurs in the intervention matrix. Nothing else can move X: an entry on an uncharacterized flow is multiplied by a CF of exactly zero, and an entry that is zero in B is no coefficient at all. No contribution filter is applied, so the parameter set does not depend on a reference solution.

Technosphere exchanges are not parameters, as of now: A is deterministic and any distribution the database declares for its entries is not read. The closed-form moments and the reduced space both rely on that.

Declared and undeclared#

A parameter is declared when the database or the method gives it a distribution (uncertainty_type > 0) and undeclared otherwise. Undeclared parameters are deterministic in every result (mean = amount, variance 0); they are kept, under 'undeclared', so that the screening of undeclared parameters can rank them. uncertainty_type = 1 (“no uncertainty”) is a declaration of an exact value and is kept under 'declared' with variance 0.

The container (UncertaintyData) is a nested dict:

{'If': {database: {'declared': {(e, j): spec}, 'undeclared': {(e, j): spec}}},
 'Cf': {method:   {'declared': {e: spec},      'undeclared': {e: spec}}}}

with spec a stats_arrays-style dict (uncertainty_type, amount, loc, scale, shape, minimum, maximum, negative) and (e, j) the (flow row, process column) of the entry in B.

Module Contents#

Classes#

UncertaintySpec

One parameter's declared distribution, in stats_arrays' field names.

ParameterBlock

The parameters of one database or method, split by whether they declare a distribution.

UncertaintyData

The uncertainty data of an impact: 'If' per database, 'Cf' for the method.

Functions#

_single_method(worker)

_record(→ UncertaintySpec)

_split(records)

import_declared(→ UncertaintyData)

The parameters of the worker's impact and their declared distributions.

_iter_defined(data)

_validate(spec[, index])

override(→ UncertaintyData)

Declare or replace distributions, e.g. from expert elicitation.

undeclared(→ Dict[str, Dict[str, Dict[ParamIndex, ...)

{group: {subgroup: {index: spec}}} of every undeclared parameter.

counts(→ List[dict])

One row per group, subgroup and family: how many parameters each holds.

Attributes#

class pulpo.utils.uncertainty.preparer.UncertaintySpec[source]#

Bases: TypedDict

Inheritance diagram of pulpo.utils.uncertainty.preparer.UncertaintySpec

One parameter’s declared distribution, in stats_arrays’ field names.

Initialize self. See help(type(self)) for accurate signature.

uncertainty_type: int[source]#
amount: float[source]#
loc: float[source]#
scale: float[source]#
shape: float[source]#
minimum: float[source]#
maximum: float[source]#
negative: bool[source]#
pulpo.utils.uncertainty.preparer.ParamIndex[source]#
class pulpo.utils.uncertainty.preparer.ParameterBlock[source]#

Bases: TypedDict

Inheritance diagram of pulpo.utils.uncertainty.preparer.ParameterBlock

The parameters of one database or method, split by whether they declare a distribution.

Initialize self. See help(type(self)) for accurate signature.

declared: Dict[ParamIndex, UncertaintySpec][source]#
undeclared: Dict[ParamIndex, UncertaintySpec][source]#
class pulpo.utils.uncertainty.preparer.UncertaintyData[source]#

Bases: TypedDict

Inheritance diagram of pulpo.utils.uncertainty.preparer.UncertaintyData

The uncertainty data of an impact: 'If' per database, 'Cf' for the method.

Initialize self. See help(type(self)) for accurate signature.

If: Dict[str, ParameterBlock][source]#
Cf: Dict[str, ParameterBlock][source]#
pulpo.utils.uncertainty.preparer.SUPPORTED_FAMILIES[source]#
pulpo.utils.uncertainty.preparer._SPEC_FIELDS = ('uncertainty_type', 'amount', 'loc', 'scale', 'shape', 'minimum', 'maximum', 'negative')[source]#
pulpo.utils.uncertainty.preparer._single_method(worker)[source]#
pulpo.utils.uncertainty.preparer._record(row) → UncertaintySpec[source]#
pulpo.utils.uncertainty.preparer._split(records)[source]#
pulpo.utils.uncertainty.preparer.import_declared(worker, method=None) → UncertaintyData[source]#

The parameters of the worker’s impact and their declared distributions.

Parameters:
  • worker (PulpoOptimizer) – a worker after get_lci_data().

  • method (str, optional) – the LCIA method; defaults to the worker’s only one.

Returns:

see the module docstring.

Return type:

UncertaintyData

pulpo.utils.uncertainty.preparer._iter_defined(data)[source]#
pulpo.utils.uncertainty.preparer._validate(spec: UncertaintySpec, index=None)[source]#
pulpo.utils.uncertainty.preparer.override(uncertainty_data: UncertaintyData, group: str, subgroup: str, specs: Dict[ParamIndex, UncertaintySpec]) → UncertaintyData[source]#

Declare or replace distributions, e.g. from expert elicitation.

Each spec replaces the parameter’s distribution; amount (the value the deterministic model uses) is kept unless the spec gives one. A parameter that is not in the data raises KeyError: it is not a coefficient of the impact (a zero entry of B, or an uncharacterized flow).

Parameters:
  • uncertainty_data – from import_declared(); modified in place and returned.

  • group – 'If' or 'Cf'.

  • subgroup – the database ('If') or the method ('Cf').

  • specs – {index: spec} with index = (flow row, process column) for 'If' and the flow row for 'Cf'.

pulpo.utils.uncertainty.preparer.undeclared(uncertainty_data: UncertaintyData) → Dict[str, Dict[str, Dict[ParamIndex, UncertaintySpec]]][source]#

{group: {subgroup: {index: spec}}} of every undeclared parameter.

pulpo.utils.uncertainty.preparer.counts(uncertainty_data: UncertaintyData) → List[dict][source]#

One row per group, subgroup and family: how many parameters each holds.