bw2data.data_store
#
Module Contents#
Classes#
Base class for all Brightway2 data stores. Subclasses should define: |
|
Brightway2 data stores that can be processed to NumPy arrays. In addition to |
- class bw2data.data_store.DataStore(name)[source]#
Bases:
object
Base class for all Brightway2 data stores. Subclasses should define:
metadata: A serialized-dict instance, e.g.
databases
ormethods
. The custom is that each type of data store has a new metadata store, so the data storeFoo
would have a metadata storefoos
.validator: A data validator. Optional. See bw2data.validate.
- property filename[source]#
Remove filesystem-unsafe characters and perform unicode normalization on
self.name
usingutils.safe_filename()
.
- copy(name)[source]#
Make a copy of this object with a new
name
.This method only changes the name, but not any of the data or metadata.
- Parameters
name (*) – Name of the new object.
- Returns
The new object.
- class bw2data.data_store.ProcessedDataStore(name)[source]#
Bases:
DataStore
Brightway2 data stores that can be processed to NumPy arrays. In addition to
metadata
and (optionally)validator
, subclasses should define:dtype_fields: A list of fields to construct a NumPy structured array, e.g.
[('foo', np.int), ('bar', np.float)]
. Fields names must be bytestrings, not unicode (i.e.b"foo"
instead of"foo"
). Uncertainty fields (base_uncertainty_fields
) are added automatically.
In order to use
dtype_fields
, subclasses should override the methodprocess_data
. This function takes rows of data, and returns the correct values for the custom dtype fields (as a tuple), and theamount
field with its associated uncertainty. This second part is a little flexible - if there is no uncertainty, a number can be returned; otherwise, an uncertainty dictionary should be returned.Subclasses should also override
add_mappings
. This method takes the entire dataset, and loads objects to mapping or geomapping as needed.- property dtype[source]#
Returns both the generic
base_uncertainty_fields
plus class-specificdtype_fields
.dtype
determines the columns of the processed array.
- add_mappings(data)[source]#
Add objects to
mapping
orgeomapping
, if necessary.- Parameters
data (*) – The data
- process()[source]#
Process intermediate data from a Python dictionary to a stats_arrays array, which is a NumPy Structured Array. A structured array (also called record array) is a heterogeneous array, where each column has a different label and data type.
Processed arrays are saved in the
processed
directory.If the uncertainty type is no uncertainty, undefined, or not specified, then the ‘amount’ value is used for ‘loc’ as well. This is needed for the random number generator.
Doesn’t return anything, but writes a file to disk.