bw2calc.matrices#
Classes#
The class, and its subclasses, load structured arrays, manipulate them, and generate SciPy sparse matrices. |
|
Subclass of |
|
Subclass of |
Module Contents#
- class bw2calc.matrices.MatrixBuilder[source]#
Bases:
objectThe 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
pathsusing the functionutils.load_arrays()into a parameter array.If not
row_dict, usebuild_dictionary()to buildrow_dictfrom the parameter array columnrow_id_label.Using the
row_id_labeland therow_dict, use the methodadd_matrix_indices()to add matrix indices to therow_index_labelcolumn.If not
one_d, do the same tocol_dictandcol_index_label, usingcol_id_label.If not
one_d, usebuild_matrix()to build a sparse matrix usingdata_labelfor the matrix data values, androw_index_labelandcol_index_labelfor row and column indices.Else if
one_d, usebuild_diagonal_matrix()to build a diagonal matrix usingdata_labelfor diagonal matrix data values androw_index_labelas 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_labelvalues torow_index_labelvalues. Will be built if not given.col_dict (*) – Mapping dictionary linking
col_id_labelvalues tocol_index_labelvalues. 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_dictorcol_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
MatrixBuilderthat supports consumption (i.e. multiply by -1).
- class bw2calc.matrices.TechnosphereBiosphereMatrixBuilder[source]#
Bases:
MatrixBuilder
Subclass of
MatrixBuilderthat 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).