bw_processing.matrix_entry

Classes

MatrixEntry

A single entry destined for a matrix cell.

MatrixName

Standard matrix names used in Brightway.

Functions

create_datapackage_from_entries(data[, fs])

Create a datapackage from a dictionary of MatrixEntry lists.

Module Contents

class bw_processing.matrix_entry.MatrixEntry[source]

A single entry destined for a matrix cell.

Multiple instances with the same (row, col) are summed during matrix construction, so this is not necessarily the final cell value.

Field names and defaults match those expected by bw_processing’s dictionary_formatter. Convert to a plain dict with as_dict() before passing to bw_processing internals.

Parameters:
  • row – Integer row index in the target matrix.

  • col – Integer column index in the target matrix.

  • amount – The numeric value to place at (row, col).

  • flip – If True, multiply the value by -1 when building the matrix.

  • uncertainty_type – Probability distribution type (0 = no uncertainty, 2 = lognormal, 3 = normal, etc. — see stats_arrays for full list).

  • loc – Distribution location parameter. For lognormal this is the log of the median; defaults to NaN (no uncertainty).

  • scale – Distribution scale parameter (e.g. standard deviation).

  • shape – Distribution shape parameter.

  • minimum – Lower bound for distribution sampling.

  • maximum – Upper bound for distribution sampling.

  • negative – Whether the underlying value is negative.

as_dict() dict[source]
amount: float[source]
col: int[source]
flip: bool = False[source]
loc: float = nan[source]
maximum: float = nan[source]
minimum: float = nan[source]
negative: bool = False[source]
row: int[source]
scale: float = nan[source]
shape: float = nan[source]
uncertainty_type: int = 0[source]
class bw_processing.matrix_entry.MatrixName[source]

Bases: str, enum.Enum

Standard matrix names used in Brightway.

Because this is a str enum, members can be used anywhere a plain string is accepted — no .value needed:

MatrixEntry(row=1, col=4, amount=2.5)  # inside a dict keyed by MatrixName
dp.add_entries(matrix=MatrixName.technosphere, entries=[...])

Derived libraries may define additional matrices as plain strings; these three cover the core Brightway LCA workflow.

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

biosphere = 'biosphere_matrix'[source]
characterization = 'characterization_matrix'[source]
technosphere = 'technosphere_matrix'[source]
bw_processing.matrix_entry.create_datapackage_from_entries(data: dict, fs=None, **metadata)[source]

Create a datapackage from a dictionary of MatrixEntry lists.

This is the recommended high-level entry point for building datapackages without working directly with NumPy arrays.

Parameters:
  • data

    Dictionary mapping matrix names to lists of MatrixEntry objects. Use MatrixName members as keys for the standard Brightway matrices; derived libraries may use plain strings for additional matrices:

    {
        MatrixName.technosphere: [
            MatrixEntry(row=1, col=4, amount=2.5),
            MatrixEntry(row=2, col=5, amount=7.0, flip=True),
        ],
        MatrixName.biosphere: [
            MatrixEntry(row=10, col=4, amount=0.3),
        ],
    }
    

  • fs – Optional filesystem. Defaults to an in-memory filesystem.

  • **metadata – Additional keyword arguments passed to create_datapackage() (e.g. name, id_).

Returns:

A Datapackage instance.