bw2io.utils#

Attributes#

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(→ dict)

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.

Module Contents#

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.format_for_logging(obj)[source]#
bw2io.utils.load_json_data_file(filename)[source]#
bw2io.utils.rescale_exchange(exc: dict, factor: float) dict[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:

ValueError – If factor is not a number.

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

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