bw2data.data_store#

Classes#

DataStore

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

ProcessedDataStore

Brightway2 data stores that can be processed to NumPy arrays.

Module Contents#

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

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.

_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

_intermediate_dir = 'intermediate'[source]#
_metadata = None[source]#
property filename[source]#
Remove filesystem-unsafe characters and perform unicode normalization on ``self.name`` using :func:`.filesystem.safe_filename`.
metadata[source]#
name[source]#
property registered[source]#
validator = None[source]#
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 override add_geomappings. This method takes the entire dataset, and loads objects to geomapping as needed.

add_geomappings(data)[source]#

Add objects to geomapping, if necessary.

Parameters:

data (*) – The data

datapackage()[source]#
dirpath_processed()[source]#
filename_processed()[source]#
filepath_processed()[source]#
process(**extra_metadata)[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_row(row)[source]#

Translate data into a dictionary suitable for array inputs.

See bw_processing documentation.

validate(data)[source]#

Validate data. Must be called manually.

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

Serialize intermediate data to disk.

Parameters:

data (*) – The data

matrix = 'unknown'[source]#