bw2io.utils
#
Module Contents#
Functions#
|
Hash an activity dataset. |
|
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. |
Attributes#
- bw2io.utils.activity_hash(data, fields=None, case_insensitive=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.
By default, uses the following, in order: * name * categories * unit * reference product * location
- Parameters
data (dict) – The activity dataset data.
- fieldslist, optional
Optional list of fields to hash together. Default is
('name', 'categories', 'unit', 'reference product', 'location')
.An empty string is used if a field isn’t present. All fields are cast to lower case.
- case_insensitivebool, optional
Cast everything to lowercase before computing hash. Default is
True
.
- Returns
A MD5 hash string, hex-encoded.
- Return type
str
- 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.
- Parameters
activity (str) – The activity UUID.
flow (str) – The flow UUID.
- Returns
The unique ID.
- Return type
str
- bw2io.utils.rescale_exchange(exc, factor)[source]#
Rescale exchanges, including formulas and uncertainty values, by a constant factor.
- Parameters
exc (dict) – The exchange to rescale.
factor (float) – The factor to rescale by.
- Returns
The rescaled exchange.
- Return type
dict
- Raises
AssertionError – If factor is not a number.
AssertionError – If factor is not greater than 0.
AssertionError – If uncertainty type is not in {UndefinedUncertainty.id, NoUncertainty.id, NormalUncertainty.id}.
Warning
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.
- Parameters
name (tuple) – The current name.
padding (str, optional) – The string to use for missing fields. The default is “–“.
joiner (str, optional) – The string to use to join the fields. The default is “,”.
- Returns
The standardized name.
- Return type
tuple