bw2io.utils#
Attributes#
Classes#
Functions#
|
Generate unique ID for ecoinvent3 dataset. |
|
|
|
|
|
Rescale exchanges, including formulas and uncertainty values, by a constant factor. |
|
Standardize an LCIA method name to a length 3 tuple. |
Module Contents#
- class bw2io.utils.ExchangeLinker[source]#
- classmethod activity_hash(act, fields=DEFAULT_FIELDS, case_insensitive=True, strip=True)[source]#
Hash an activity dataset.
Used to import data formats like ecospold 1 (ecoinvent v1-2) and SimaPro, where no unique attributes for datasets are given. This is clearly an imperfect and brittle solution, but there is no other obvious approach at this time.
The fields used can be optionally specified in
fields.No fields are required; an empty string is used if a field isn’t present. All fields are cast to lower case.
- By default, uses the following, in order:
name
categories
unit
reference product
location
- Parameters:
data (*) – The activity dataset data.
fields (*) – Optional list of fields to hash together. Default is
('name', 'categories', 'unit', 'reference product', 'location').case_insensitive (*) – Cast everything to lowercase before computing hash. Default is
True.
- Returns:
A MD5 hash string, hex-encoded.
- classmethod link_activities_to_database(activities, other=None, fields=DEFAULT_FIELDS, relink=False)[source]#
- classmethod link_iterable_by_fields(unlinked, other=None, fields=DEFAULT_FIELDS, kind=None, internal=False, relink=False)[source]#
Generic function to link objects in
unlinkedto objects inotherusing fieldsfields.The database to be linked must have uniqueness for each object for the given
fields.If
kind, limit objects inunlinkedof typekind.If
relink, link to objects which already have aninput. Otherwise, skip already linked objects.If
internal, linkedunlinkedto other objects inunlinked. Each object must have the attributesdatabaseandcode.
- static overwrite_exchange_field_values_with_linked_activity_values(activities, fields=DEFAULT_FIELDS)[source]#
This function goes through all exchanges and copies fields values from the linked activity to the exchange. This might be helpful after linking “soft-matched” fields, such as categories, where a string “(‘air’,)” is treated as identical to a tuple (‘air’,) etc.
- bw2io.utils.es2_activity_hash(activity, flow)[source]#
Generate unique ID for ecoinvent3 dataset.
Despite using a million UUIDs, there is actually no unique ID in an ecospold2 dataset. Datasets are uniquely identified by the combination of activity and flow UUIDs.
- bw2io.utils.rescale_exchange(exc, factor)[source]#
Rescale exchanges, including formulas and uncertainty values, by a constant factor.
No generally recommended, but needed for use in unit conversions. Not well tested.
- bw2io.utils.standardize_method_to_len_3(name, padding='--', joiner=',')[source]#
Standardize an LCIA method name to a length 3 tuple.
nameis the current name.paddingis the string to use for missing fields.