bw2data.data_store#
Classes#
Base class for all Brightway2 data stores. Subclasses should define: |
|
Brightway2 data stores that can be processed to NumPy arrays. In addition to |
Module Contents#
- class bw2data.data_store.DataStore(name)[source]#
Bases:
objectBase class for all Brightway2 data stores. Subclasses should define:
metadata: A serialized-dict instance, e.g.
databasesormethods. The custom is that each type of data store has a new metadata store, so the data storeFoowould have a metadata storefoos.validator: A data validator. Optional. See bw2data.validate.
- 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.
- register(**kwargs)[source]#
Register an object with the metadata store. Takes any number of keyword arguments.
- class bw2data.data_store.ProcessedDataStore(name)[source]#
Bases:
DataStore
Brightway2 data stores that can be processed to NumPy arrays. In addition to
metadataand (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 theamountfield 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.- add_mappings(data)[source]#
Add objects to
mappingorgeomapping, 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
processeddirectory.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.
- write(data, process=True)[source]#
Serialize intermediate data to disk.
- Parameters:
data (*) – The data