bw2data#
Subpackages#
Submodules#
- bw2data.configuration
- bw2data.data_store
- bw2data.database
- bw2data.errors
- bw2data.fatomic
- bw2data.filesystem
- bw2data.ia_data_store
- bw2data.logs
- bw2data.meta
- bw2data.method
- bw2data.parameters
- bw2data.project
- bw2data.proxies
- bw2data.query
- bw2data.serialization
- bw2data.sqlite
- bw2data.updates
- bw2data.utils
- bw2data.validate
- bw2data.weighting_normalization
Attributes#
Classes#
Base class for all Brightway2 data stores. Subclasses should define: |
|
A manager for an impact assessment method. This class can register or deregister methods, write intermediate data, process data to parameter arrays, validate, and copy methods. |
|
LCIA normalization data - used to transform meaningful units, like mass or damage, into "person-equivalents" or some such thing. |
|
Brightway2 data stores that can be processed to NumPy arrays. In addition to |
|
LCIA weighting data - used to combine or compare different impact categories. |
Functions#
|
A method that returns a database class instance. The default database type is SingleFileDatabase. JSONDatabase stores each process dataset in indented JSON in a separate file. Database types are specified in databases[database_name]['backend']. |
|
Convert a Database to another backend. |
|
|
|
Set the Brightway2 data directory to |
Package Contents#
- class bw2data.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.
- _intermediate_dir = 'intermediate'#
- _metadata = None#
- property filename#
- Remove filesystem-unsafe characters and perform unicode normalization on ``self.name`` using :func:`.utils.safe_filename`.
- metadata#
- name#
- property registered#
- validator = None#
- class bw2data.Method[source]#
Bases:
bw2data.ia_data_store.ImpactAssessmentDataStore
A manager for an impact assessment method. This class can register or deregister methods, write intermediate data, process data to parameter arrays, validate, and copy methods.
The Method class never holds intermediate data, but it can load or write intermediate data. The only attribute is name, which is the name of the method being managed.
Instantiation does not load any data. If this method is not yet registered in the metadata store, a warning is written to
stdout.Methods are hierarchally structured, and this structure is preserved in the method name. It is a tuple of strings, like
('ecological scarcity 2006', 'total', 'natural resources').The data schema for IA methods is:
Schema([Any( [valid_tuple, maybe_uncertainty], # site-generic [valid_tuple, maybe_uncertainty, object] # regionalized )])
- where:
valid_tuple (tuple): A dataset identifier, like
("biosphere", "CO2").maybe_uncertainty (uncertainty dict or number): Either a number or an uncertainty dictionary.
object (object, optional) is a location identifier, used only for regionalized LCIA.
- Parameters:
name (*) – Name of impact assessment method to manage.
- write(data, process=True)[source]#
Serialize intermediate data to disk.
Sets the metadata key
num_cfsautomatically.
- _metadata#
- dtype_fields#
- validator#
- class bw2data.Normalization(name)[source]#
Bases:
bw2data.ia_data_store.ImpactAssessmentDataStore
LCIA normalization data - used to transform meaningful units, like mass or damage, into “person-equivalents” or some such thing.
The data schema for IA normalization is:
Schema([ [valid_tuple, maybe_uncertainty] ])
- where:
valid_tupleis a dataset identifier, like("biosphere", "CO2")maybe_uncertaintyis either a number or an uncertainty dictionary
- add_mappings(data)[source]#
Add each normalization flow (should be biosphere flows) to global mapping
- process_data(row)[source]#
Return values that match
dtype_fields, as well as number or uncertainty dictionary
- _metadata#
- dtype_fields#
- validator#
- class bw2data.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
- base_uncertainty_fields#
- property dtype#
- Returns both the generic ``base_uncertainty_fields`` plus class-specific ``dtype_fields``. ``dtype`` determines the columns of the :ref:`processed array <processing-data>`.
- dtype_fields = None#
- class bw2data.Weighting(name)[source]#
Bases:
bw2data.ia_data_store.ImpactAssessmentDataStore
LCIA weighting data - used to combine or compare different impact categories.
The data schema for weighting is a one-element list:
Schema(All( [uncertainty_dict], Length(min=1, max=1) ))
- process_data(row)[source]#
Return an empty tuple (as
dtype_fieldsis empty), and the weighting uncertainty dictionary.
- _metadata#
- dtype_fields = []#
- validator#
- bw2data.Database(name, backend=None)#
A method that returns a database class instance. The default database type is SingleFileDatabase. JSONDatabase stores each process dataset in indented JSON in a separate file. Database types are specified in databases[database_name][‘backend’].
New database types can be registered with the config object:
config.backends['backend type string'] = MyNewBackendClass
Warning
Registering new backends must be done each time you start the Python interpreter.
To test whether an object is a database subclass, do:
from bw2data.backends import LCIBackend isinstance(my_database, LCIBackend)
- bw2data.convert_backend(database_name, backend)[source]#
Convert a Database to another backend.
bw2data currently supports the default and json backends.
- Parameters:
database_name (*) – Name of database.
backend (*) – Type of database. backend should be recoginized by DatabaseChooser.
Returns False if the old and new backend are the same. Otherwise returns an instance of the new Database object.