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
Package Contents#
Classes#
Base class for all Brightway2 data stores. Subclasses should define: |
|
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 |
Attributes#
- class bw2data.DataStore(name)[source]#
Bases:
object
Base class for all Brightway2 data stores. Subclasses should define:
metadata: A serialized-dict instance, e.g.
databases
ormethods
. The custom is that each type of data store has a new metadata store, so the data storeFoo
would have a metadata storefoos
.validator: A data validator. Optional. See bw2data.validate.
- property filename#
Remove filesystem-unsafe characters and perform unicode normalization on
self.name
usingutils.safe_filename()
.
- property registered#
- _intermediate_dir = 'intermediate'#
- _metadata#
- metadata#
- validator#
- _get_metadata()#
- _set_metadata(value)#
- backup()#
Save a backup to
backups
folder.- Returns
File path of backup.
- copy(name)#
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()#
Remove an object from the metadata store. Does not delete any files.
- load()#
Load the intermediate data for this object.
- Returns
The intermediate data.
- register(**kwargs)#
Register an object with the metadata store. Takes any number of keyword arguments.
- validate(data)#
Validate data. Must be called manually.
- write(data)#
Serialize intermediate data to disk.
- Parameters
data (*) â The data
- class bw2data.IndexManager(database_path, dir_name='whoosh')#
Bases:
object
- _format_dataset(ds)#
- add_dataset(ds)#
- add_datasets(datasets)#
- create()#
- delete_database()#
- delete_dataset(ds)#
- get()#
- update_dataset(ds)#
- class bw2data.JsonWrapper[source]#
Bases:
object
- classmethod dump(data, filepath)#
- classmethod dump_bz2(data, filepath)#
- classmethod dumps(data)#
- classmethod load(file)#
- classmethod load_bz2(filepath)#
- classmethod loads(data)#
- class bw2data.Normalization[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_tuple
is a dataset identifier, like("biosphere", "CO2")
maybe_uncertainty
is either a number or an uncertainty dictionary
- _metadata#
- dtype_fields = [(), ()]#
- validator#
- add_mappings(data)#
Add each normalization flow (should be biosphere flows) to global mapping
- process_data(row)#
Return values that match
dtype_fields
, as well as number or uncertainty dictionary
- class bw2data.ProcessedDataStore(name)[source]#
Bases:
DataStore
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 methodprocess_data
. This function takes rows of data, and returns the correct values for the custom dtype fields (as a tuple), and theamount
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#
Returns both the generic
base_uncertainty_fields
plus class-specificdtype_fields
.dtype
determines the columns of the processed array.
- base_uncertainty_fields = [(), (), (), (), (), (), (), ()]#
- dtype_fields#
- add_mappings(data)#
Add objects to
mapping
orgeomapping
, if necessary.- Parameters
data (*) â The data
- as_uncertainty_dict(value)#
Convert floats to
stats_arrays
uncertainty dict, if necessary
- dtype_field_order(dtype=None)#
- filepath_processed()#
- process()#
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)#
Translate data into correct order
- validate(data)#
Validate data. Must be called manually.
- write(data, process=True)#
Serialize intermediate data to disk.
- Parameters
data (*) â The data
- class bw2data.Searcher(database)#
Bases:
object
- search(string, limit=25, facet=None, proxy=True, boosts=None, filter=None, mask=None)#
- class bw2data.Weighting[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) ))
- _metadata#
- dtype_fields = []#
- validator#
- process_data(row)#
Return an empty tuple (as
dtype_fields
is empty), and the weighting uncertainty dictionary.
- write(data)#
Because of DataStore assumptions, need a one-element list
- 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)#
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.
- bw2data.get_activity(key)#
- bw2data.set_data_dir(dirpath, permanent=True)[source]#
Set the Brightway2 data directory to
dirpath
.If
permanent
isTrue
, then setdirpath
as the default data directory.Creates
dirpath
if needed. Also creates basic directories, and resets metadata.
- bw2data.parameters#