REGISTER NOW: DdS Autumn School! 🇨🇭 Grosshöchstetten (Switzerland) 🗓️ 6.-11. October 2024

bw2io.utils#

Module Contents#

Functions#

activity_hash(data[, fields, case_insensitive])

Hash an activity dataset.

es2_activity_hash(activity, flow)

Generate unique ID for ecoinvent3 dataset.

format_for_logging(obj)

load_json_data_file(filename)

rescale_exchange(exc, factor)

Rescale exchanges, including formulas and uncertainty values, by a constant factor.

standardize_method_to_len_3(name[, padding, joiner])

Standardize an LCIA method name to a length 3 tuple.

Attributes#

DEFAULT_FIELDS

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.format_for_logging(obj)[source]#
bw2io.utils.load_json_data_file(filename)[source]#
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.

bw2io.utils.DEFAULT_FIELDS = ('name', 'categories', 'unit', 'reference product', 'location')[source]#