bw2io.strategies.generic
#
Module Contents#
Functions#
|
Add database name to datasets |
Assign only product as reference product. |
|
Convert activity parameters from dictionary to list of dictionaries |
|
Generic number conversion function convert to floats. Return to integers. |
|
Drop fields like '' but keep zero and NaN. |
|
|
This is the nuclear option - use at your own risk! |
|
|
|
Generic function to link objects in |
|
Link technosphere exchanges using |
|
Normalize units in datasets and their exchanges |
|
Use |
|
Split unlinked exchanges in |
- bw2io.strategies.generic.assign_only_product_as_production(db)[source]#
Assign only product as reference product.
Skips datasets that already have a reference product or no production exchanges. Production exchanges must have a
name
and an amount.Will replace the following activity fields, if not already specified:
ânameâ - name of reference product
âunitâ - unit of reference product
âproduction amountâ - amount of reference product
- bw2io.strategies.generic.convert_activity_parameters_to_list(data)[source]#
Convert activity parameters from dictionary to list of dictionaries
- bw2io.strategies.generic.convert_uncertainty_types_to_integers(db)[source]#
Generic number conversion function convert to floats. Return to integers.
- bw2io.strategies.generic.drop_falsey_uncertainty_fields_but_keep_zeros(db)[source]#
Drop fields like ââ but keep zero and NaN.
Note that this doesnât strip False, which behaves exactly like 0.
- bw2io.strategies.generic.drop_unlinked(db)[source]#
This is the nuclear option - use at your own risk!
- bw2io.strategies.generic.link_iterable_by_fields(unlinked, other=None, fields=None, kind=None, internal=False, relink=False)[source]#
Generic function to link objects in
unlinked
to objects inother
using fieldsfields
.The database to be linked must have uniqueness for each object for the given
fields
.If
kind
, limit the exchanges inunlinked
objects to types inkind
.If
relink
, link to objects which already have aninput
. Otherwise, skip already linked objects.If
internal
, linkedunlinked
to other objects inunlinked
. Each object must have the attributesdatabase
andcode
.
- bw2io.strategies.generic.link_technosphere_by_activity_hash(db, external_db_name=None, fields=None)[source]#
Link technosphere exchanges using
activity_hash
function.If
external_db_name
, link against a different database; otherwise link internally.If
fields
, link using only certain fields.
- bw2io.strategies.generic.normalize_units(db)[source]#
Normalize units in datasets and their exchanges
- bw2io.strategies.generic.set_code_by_activity_hash(db, overwrite=False)[source]#
Use
activity_hash
to set dataset code.By default, wonât overwrite existing codes, but will if
overwrite
isTrue
.
- bw2io.strategies.generic.split_exchanges(data, filter_params, changed_attributes, allocation_factors=None)[source]#
Split unlinked exchanges in
data
which satisfyfilter_params
into new exchanges with changed attributes.changed_attributes
is a list of dictionaries with the attributes that should be changed.allocation_factors
is an optional list of floats to allocate the original exchange amount to the respective copies defined inchanged_attributes
. They donât have to sum to one. Ifallocation_factors
are not defined, then exchanges are split equally.Resets uncertainty to
UndefinedUncertainty
(0).To use this function as a strategy, you will need to curry it first using
functools.partial
.Example usage:
split_exchanges( [ {'exchanges': [{ 'name': 'foo', 'location': 'bar', 'amount': 20 }, { 'name': 'food', 'location': 'bar', 'amount': 12 }]} ], {'name': 'foo'}, [{'location': 'A'}, {'location': 'B', 'cat': 'dog'} ] >>> [ {'exchanges': [{ 'name': 'food', 'location': 'bar', 'amount': 12 }, { 'name': 'foo', 'location': 'A', 'amount': 12., 'uncertainty_type': 0 }, { 'name': 'foo', 'location': 'B', 'amount': 8., 'uncertainty_type': 0, 'cat': 'dog', }]} ]