bw2calc.matrices
#
Module Contents#
Classes#
The class, and its subclasses, load structured arrays, manipulate them, and generate SciPy sparse matrices. |
|
Subclass of |
|
Subclass of |
- class bw2calc.matrices.MatrixBuilder[source]#
Bases:
object
The class, and its subclasses, load structured arrays, manipulate them, and generate SciPy sparse matrices.
Matrix builders use an array of row indices, an array of column indices, and an array of values to create a coordinate (coo) matrix, which is then converted to a compressed sparse row (csr) matrix.
See the following for more information on structured arrays:
These classes are not instantiated, and have only classmethods. They are not really true classes, but more organizational. In other words, you should use:
MatrixBuilder.build(args)
and not:
mb = MatrixBuilder() mb.build(args)
- classmethod build(paths, data_label, row_id_label, row_index_label, col_id_label=None, col_index_label=None, row_dict=None, col_dict=None, one_d=False, drop_missing=True)[source]#
Build a sparse matrix from NumPy structured array(s).
See more detailed documentation at building-matrices.
This method does the following:
TODO: Update
Load and concatenate the structured arrays files in filepaths
paths
using the functionutils.load_arrays()
into a parameter array.If not
row_dict
, usebuild_dictionary()
to buildrow_dict
from the parameter array columnrow_id_label
.Using the
row_id_label
and therow_dict
, use the methodadd_matrix_indices()
to add matrix indices to therow_index_label
column.If not
one_d
, do the same tocol_dict
andcol_index_label
, usingcol_id_label
.If not
one_d
, usebuild_matrix()
to build a sparse matrix usingdata_label
for the matrix data values, androw_index_label
andcol_index_label
for row and column indices.Else if
one_d
, usebuild_diagonal_matrix()
to build a diagonal matrix usingdata_label
for diagonal matrix data values androw_index_label
as row/column indices.Return the loaded parameter arrays from step 1, row and column dicts from steps 2 & 4, and matrix from step 5 or 6.
- Parameters
paths (*) β List of array filepaths to load.
data_label (*) β Label of column in parameter arrays with matrix data values.
row_id_label (*) β Label of column in parameter arrays with row ID values, i.e. the integer values returned from
mapping
.row_index_label (*) β Label of column in parameter arrays where matrix row indices will be stored.
col_id_label (*) β Label of column in parameter arrays with column ID values, i.e. the integer values returned from
mapping
. Not needed for diagonal matrices.col_index_label (*) β Label of column in parameter arrays where matrix column indices will be stored. Not needed for diagonal matrices.
row_dict (*) β Mapping dictionary linking
row_id_label
values torow_index_label
values. Will be built if not given.col_dict (*) β Mapping dictionary linking
col_id_label
values tocol_index_label
values. Will be built if not given.one_d (*) β Build diagonal matrix.
drop_missing (*) β Remove rows from the parameter array which arenβt mapped by
row_dict
orcol_dict
. Default isTrue
. Advanced use only.
- Returns
A numpy parameter array, the row mapping dictionary, the column mapping dictionary, and a COO sparse matrix.
- class bw2calc.matrices.SingleMatrixBuilder[source]#
Bases:
MatrixBuilder
Subclass of
MatrixBuilder
that supports consumption (i.e. multiply by -1).
- class bw2calc.matrices.TechnosphereBiosphereMatrixBuilder[source]#
Bases:
MatrixBuilder
Subclass of
MatrixBuilder
that separates technosphere and biosphere parameters- classmethod get_biosphere_inputs_mask(array)[source]#
Get boolean mask of biosphere flows from
array
(i.e. the ones to include when building the biosphere matrix).
- classmethod get_technosphere_inputs_mask(array)[source]#
Get boolean mask of technosphere inputs from
array
(i.e. the ones to include when building the technosphere matrix).