bw2data.data_store#

Module Contents#

Classes#

DataStore

Base class for all Brightway2 data stores. Subclasses should define:

ProcessedDataStore

Brightway2 data stores that can be processed to NumPy arrays. In addition to metadata and (optionally) validator, subclasses should define:

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 or methods. The custom is that each type of data store has a new metadata store, so the data store Foo would have a metadata store foos.

  • validator: A data validator. Optional. See bw2data.validate.

property filename[source]#

Remove filesystem-unsafe characters and perform unicode normalization on self.name using utils.safe_filename().

property registered[source]#
_intermediate_dir = 'intermediate'[source]#
_metadata[source]#
metadata[source]#
validator[source]#
_get_metadata()[source]#
_set_metadata(value)[source]#
backup()[source]#

Save a backup to backups folder.

Returns

File path of backup.

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.

deregister()[source]#

Remove an object from the metadata store. Does not delete any files.

load()[source]#

Load the intermediate data for this object.

Returns

The intermediate data.

register(**kwargs)[source]#

Register an object with the metadata store. Takes any number of keyword arguments.

validate(data)[source]#

Validate data. Must be called manually.

write(data)[source]#

Serialize intermediate data to disk.

Parameters

data (*) – The data

class bw2data.data_store.ProcessedDataStore(name)[source]#

Bases: DataStore

Inheritance diagram of bw2data.data_store.ProcessedDataStore

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 method process_data. This function takes rows of data, and returns the correct values for the custom dtype fields (as a tuple), and the amount 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-specific dtype_fields. dtype determines the columns of the processed array.

base_uncertainty_fields = [(), (), (), (), (), (), (), ()][source]#
dtype_fields[source]#
add_mappings(data)[source]#

Add objects to mapping or geomapping, if necessary.

Parameters

data (*) – The data

as_uncertainty_dict(value)[source]#

Convert floats to stats_arrays uncertainty dict, if necessary

dtype_field_order(dtype=None)[source]#
filepath_processed()[source]#
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.

abstract process_data(row)[source]#

Translate data into correct order

validate(data)[source]#

Validate data. Must be called manually.

write(data, process=True)[source]#

Serialize intermediate data to disk.

Parameters

data (*) – The data