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#
- datadict
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#
- str
A MD5 hash string, hex-encoded.
- 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#
- activitystr
The activity UUID.
- flowstr
The flow UUID.
Returns#
- str
The unique ID.
- bw2io.utils.rescale_exchange(exc, factor)[source]#
Rescale exchanges, including formulas and uncertainty values, by a constant factor.
Parameters#
- excdict
The exchange to rescale.
- factorfloat
The factor to rescale by.
Returns#
- dict
The rescaled exchange.
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}.
Warnings#
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#
- nametuple
The current name.
- paddingstr, optional
The string to use for missing fields. The default is âââ.
- joinerstr, optional
The string to use to join the fields. The default is â,â.
Returns#
- tuple
The standardized name.