REGISTER NOW: DdS Autumn School! 🇨🇭 Grosshöchstetten (Switzerland) 🗓️ 6.-11. October 2024

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.

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.

property filename[source]#

Remove filesystem-unsafe characters and perform unicode normalization on self.name using filesystem.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.

Args:
  • name (object): 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.

Args:
  • data (object): 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 override add_geomappings. This method takes the entire dataset, and loads objects to geomapping as needed.

matrix = 'unknown'[source]#
add_geomappings(data)[source]#

Add objects to geomapping, if necessary.

Args:
  • data (object): 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.

Args:
  • data (object): The data