bw2data.backends.iotable#
Attributes#
Exceptions#
Base class for exceptions in Brightway2 |
Classes#
IO tables have too much data to store each value in a database; instead, we only store the processed data in NumPy arrays. |
|
A base class for LCI backends. |
Functions#
Package Contents#
- exception bw2data.backends.iotable.UnknownObject[source]#
Bases:
BW2Exception
Base class for exceptions in Brightway2
Initialize self. See help(type(self)) for accurate signature.
- class bw2data.backends.iotable.ActivityDataset[source]#
Bases:
peewee.Model
- code#
- data#
- database#
- location#
- name#
- product#
- type#
- class bw2data.backends.iotable.ExchangeDataset[source]#
Bases:
peewee.Model
- data#
- input_code#
- input_database#
- output_code#
- output_database#
- type#
- class bw2data.backends.iotable.IOTableBackend[source]#
Bases:
bw2data.backends.peewee.SQLiteBackend
IO tables have too much data to store each value in a database; instead, we only store the processed data in NumPy arrays.
Activities will not seem to have any activities.
- write(products, exchanges, includes_production=False, **kwargs)[source]#
Write IO data to disk in two different formats.
Product data is stored in SQLite as normal activities. Exchange data is written directly to NumPy structured arrays.
productsis a dictionary of product datasets in the normal format.exchangesis a list of exchanges with the format(input code, output code, type, value).
- class bw2data.backends.iotable.SQLiteBackend(*args, **kwargs)[source]#
Bases:
bw2data.backends.base.LCIBackendA base class for LCI backends.
Subclasses must support at least the following calls:
load()write(data)
In addition, they should specify their backend with the
backendattribute (a unicode string).LCIBackendprovides the following, which should not need to be modified:renamecopyfind_dependentsrandomprocess
For new classes to be recognized by the
DatabaseChooser, they need to be registered with theconfigobject, e.g.:config.backends['backend type string'] = BackendClass
Instantiation does not load any data. If this database is not yet registered in the metadata store, a warning is written to
stdout.The data schema for databases in voluptuous is:
exchange = { Required("input"): valid_tuple, Required("type"): basestring, } exchange.update(uncertainty_dict) lci_dataset = { Optional("categories"): Any(list, tuple), Optional("location"): object, Optional("unit"): basestring, Optional("name"): basestring, Optional("type"): basestring, Optional("exchanges"): [exchange] } db_validator = Schema({valid_tuple: lci_dataset}, extra=True)
- where:
valid_tupleis a dataset identifier, like("ecoinvent", "super strong steel")uncertainty_fieldsare fields from an uncertainty dictionary.
Processing a Database actually produces two parameter arrays: one for the exchanges, which make up the technosphere and biosphere matrices, and a geomapping array which links activities to locations.
- Parameters:
*name* (unicode string) β Name of the database to manage.
- load(*args, **kwargs)[source]#
Load the intermediate data for this database.
If
load()does not return a dictionary, then the returned object must have at least the following dictionary-like methods:__iter____contains____getitem____setitem____delitem____len__keys()values()items()items()
However, this method must support the keyword argument
as_dict, and.load(as_dict=True)must return a normal dictionary with all Database data. This is necessary for JSON serialization.It is recommended to subclass
collections.{abc.}MutableMapping(seeSynchronousJSONDictfor an example of data loaded on demand).
- process()[source]#
Process inventory documents to NumPy structured arrays.
Use a raw SQLite3 cursor instead of Peewee for a ~2 times speed advantage.
- random(filters=True, true_random=False)[source]#
True random requires loading and sorting data in SQLite, and can be resource-intensive.
- search(string, **kwargs)[source]#
Search this database for
string.The searcher include the following fields:
name
comment
categories
location
reference product
stringcan include wild cards, e.g."trans*".By default, the
namefield is given the most weight. The full weighting set is called theboostdictionary, and the default weights are:{ "name": 5, "comment": 1, "product": 3, "categories": 2, "location": 3 }
Optional keyword arguments:
limit: Number of results to return.boosts: Dictionary of field names and numeric boosts - see default boost values above. New values must be in the same format, but with different weights.filter: Dictionary of criteria that search results must meet, e.g.{'categories': 'air'}. Keys must be one of the above fields.mask: Dictionary of criteria that exclude search results. Same format asfilter.facet: Field to facet results. Must be one ofname,product,categories,location, ordatabase.proxy: ReturnActivityproxies instead of raw Whoosh documents. Default isTrue.
Returns a list of
Activitydatasets.
- write(data, process=True)[source]#
Write
datato database.datamust be a dictionary of the form:{ ('database name', 'dataset code'): {dataset} }
Writing a database will first deletes all existing data.
- _filters#
- _order_by = None#
- property _searchable#
- backend = 'sqlite'#
- filters#
- order_by#