bw2data.backends.single_file#

Submodules#

Package Contents#

Classes#

Activity

A MutableMapping is a generic container for associating

Exchange

Simple proxy for an exchange between activity datasets. Makes manipulation and use in command line more convenient.

SingleFileDatabase

A data store for LCI databases where each database is stored as a pickle file.

class bw2data.backends.single_file.Activity(key, data={})[source]#

Bases: bw2data.proxies.ActivityProxyBase

Inheritance diagram of bw2data.backends.single_file.Activity

A MutableMapping is a generic container for associating key/value pairs.

This class provides concrete generic implementations of all methods except for __getitem__, __setitem__, __delitem__, __iter__, and __len__.

biosphere()#
exchanges()#
save()#
technosphere()#
upstream(*args, **kwargs)#
class bw2data.backends.single_file.Exchange(data, *args, **kwargs)[source]#

Bases: bw2data.proxies.ExchangeProxyBase

Inheritance diagram of bw2data.backends.single_file.Exchange

Simple proxy for an exchange between activity datasets. Makes manipulation and use in command line more convenient.

Warning

This proxy is read only! To save changes to a dataset, you will need to work with the raw database data.

Usually these proxies are created by the activity, but you can instantiate one with the dictionary of exchange data and an Activity proxy of the consuming activity:

exchange = Exchange({"my exchange data": "goes here"})

Properties:

  • input: Returns activity

  • output: Returns activity

  • amount

  • uncertainty: Returns dictionary of uncertainty data

  • uncertainty_type: Returns stats_arrays uncertainty type

  • unit

save()#
class bw2data.backends.single_file.SingleFileDatabase(name)[source]#

Bases: bw2data.backends.base.LCIBackend

Inheritance diagram of bw2data.backends.single_file.SingleFileDatabase

A data store for LCI databases where each database is stored as a pickle file.

Databases are automatically versioned. See below for reversion, etc. methods

Parameters

*name* (str) – Name of the database to manage.

property filename#

Remove filesystem-unsafe characters and perform unicode normalization on self.name using utils.safe_filename().

property version#

The current version number (integer) of this database.

Returns

Version number

backend = 'singlefile'#
validator#
filename_for_version(version=None)#

Filename for given version; Default is current version.

Returns

Filename (not path)

filepath_intermediate(version=None)#
get(code)#

Get Activity proxy for this dataset

load(version=None, **kwargs)#

Load the intermediate data for this database.

Can also load previous versions of this database’s intermediate data.

Parameters

version (*) – Version of the database to load. Default version is the latest version.

Returns

The intermediate data, a dictionary.

make_latest_version()#

Make the current version the latest version.

Requires loading data because a new intermediate data file is created.

register(**kwargs)#

Register a database with the metadata store.

Databases must be registered before data can be written.

revert(version)#

Return data to a previous state.

Warning

Reverting can lead to data loss, e.g. if you revert from version 3 to version 1, and then save your database, you will overwrite version 2. Use make_latest_version() before saving, which will set the current version to 4.

Parameters

version (*) – Number of the version to revert to.

versions()#

Get a list of available versions of this database.

Returns

List of (version, datetime created) tuples.

write(data, process=True)#

Serialize data to disk.

Parameters

data (*) – Inventory data