bw2io.utils#

Module Contents#

Classes#

ExchangeLinker

Functions#

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

activity_hash

class bw2io.utils.ExchangeLinker[source]#
field_funcs[source]#
re_sub[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.

static format_nonunique_key_error(obj, fields, others)[source]#

Generic function to link objects in unlinked to objects in other using fields fields.

The database to be linked must have uniqueness for each object for the given fields.

If kind, limit objects in unlinked of type kind.

If relink, link to objects which already have an input. Otherwise, skip already linked objects.

If internal, linked unlinked to other objects in unlinked. Each object must have the attributes database and code.

static parse_field(field_value, case_insensitive=True, strip=True, re_sub=re_sub)[source]#
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.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.

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.

name is the current name. padding is the string to use for missing fields.

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