bw2io.strategies.ecospold1_allocation#
Functions#
Take a dataset, which has multiple outputs, and return a list of allocated datasets. |
|
|
Convert integer activity codes to strings and delete integer codes from exchanges. |
|
Delete integer codes from the input data dictionary. |
|
This strategy allocates multioutput datasets to new datasets. |
Module Contents#
- bw2io.strategies.ecospold1_allocation.allocate_exchanges(ds)[source]#
Take a dataset, which has multiple outputs, and return a list of allocated datasets.
The allocation data structure looks like:
{ 'exchanges': [integer codes for biosphere flows, ...], 'fraction': out of 100, 'reference': integer codes }
We assume that the allocation factor for each coproduct is always 100 percent.
- Parameters:
ds (dict) – A dataset that has multiple outputs.
- Returns:
A list of allocated datasets.
- Return type:
list of dict
Examples
>>> ds = {'name': 'Dataset A', 'exchanges': [{'name': 'Output 1', 'code': 1, 'type': 'production'}, ... {'name': 'Output 2', 'code': 2}, ... {'name': 'Output 3', 'code': 3}], ... 'allocations': [{'exchanges': [2], 'fraction': 50.0, 'reference': 1}, ... {'exchanges': [3], 'fraction': 50.0, 'reference': 1}]} >>> allocate_exchanges(ds) [{'name': 'Dataset A', 'exchanges': [{'name': 'Output 1', 'code': 1, 'type': 'production'}, {'name': 'Output 2', 'code': 2, 'type': 'from'}, {'name': 'Output 3', 'code': 3, 'type': 'from'}]}, {'name': 'Dataset A: Output 2', 'exchanges': [{'name': 'Output 2', 'code': 2, 'type': 'production'}], 'allocations': [{'exchanges': [2], 'fraction': 100.0, 'reference': 2}]}, {'name': 'Dataset A: Output 3', 'exchanges': [{'name': 'Output 3', 'code': 3, 'type': 'production'}], 'allocations': [{'exchanges': [3], 'fraction': 100.0, 'reference': 3}]}]
- bw2io.strategies.ecospold1_allocation.clean_integer_codes(data)[source]#
Convert integer activity codes to strings and delete integer codes from exchanges.
- Parameters:
data (list of dict) – List of datasets, where each dataset is a dictionary containing information about the dataset, such as its name, description, and exchanges.
- Returns:
The cleaned list of datasets, where integer activity codes have been converted to strings and integer codes have been deleted from exchanges.
- Return type:
list of dict
Examples
>>> data = [{'name': 'Dataset A', 'description': '...', 'code': 123}, ... {'name': 'Dataset B', 'description': '...', 'exchanges': [{'code': 456, 'amount': 1.0}]}] >>> clean_integer_codes(data) [{'name': 'Dataset A', 'description': '...', 'code': '123'}, {'name': 'Dataset B', 'description': '...', 'exchanges': [{'amount': 1.0}]}]
- bw2io.strategies.ecospold1_allocation.delete_integer_codes(data)[source]#
Delete integer codes from the input data dictionary.
- Parameters:
data (list[dict]) – A list of dictionaries, where each dictionary represents a row of data. Each dictionary should have a name key, and optionally a code and or exchanges key.
- Returns:
The updated list of dictionaries with any integer code keys removed from the dictionaries and their exchanges keys
- Return type:
list[dict]
Examples
>>> data = [{'name': 'test', 'code': 1}, {'name': 'test2', 'exchanges': [{'code': 2}]}] >>> delete_integer_codes(data) >>> data == [{'name': 'test'}, {'name': 'test2', 'exchanges': [{}]}]
- bw2io.strategies.ecospold1_allocation.es1_allocate_multioutput(data)[source]#
This strategy allocates multioutput datasets to new datasets.
This deletes the multioutput dataset, breaking any existing linking. This shouldn’t be a concern, as you shouldn’t link to a multioutput dataset in any case.
Note that multiple allocations for the same product and input will result in undefined behavior.
- Parameters:
data (list of dict) – List of datasets, where each dataset is a dictionary containing information about the dataset, such as its name, description, and exchanges.
- Returns:
The new list of datasets, where multioutput datasets have been allocated to new datasets.
- Return type:
list of dict
Examples
>>> data = [{'name': 'Dataset A', 'exchanges': [{'name': 'Output 1', 'amount': 1.0}, ... {'name': 'Output 2', 'amount': 2.0}], ... 'allocations': [{'name': 'Activity 1', 'product': 'Output 1', 'input': 'Input 1'}, ... {'name': 'Activity 2', 'product': 'Output 2', 'input': 'Input 2'}]}, ... {'name': 'Dataset B', 'exchanges': [{'name': 'Output 1', 'amount': 1.0}], ... 'allocations': [{'name': 'Activity 3', 'product': 'Output 1', 'input': 'Input 3'}]}] >>> es1_allocate_multioutput(data) [{'name': 'Dataset A: Output 1', 'exchanges': [{'name': 'Output 1', 'amount': 1.0}], 'allocations': [{'name': 'Activity 1', 'product': 'Output 1', 'input': 'Input 1'}]}, {'name': 'Dataset A: Output 2', 'exchanges': [{'name': 'Output 2', 'amount': 2.0}], 'allocations': [{'name': 'Activity 2', 'product': 'Output 2', 'input': 'Input 2'}]}, {'name': 'Dataset B', 'exchanges': [{'name': 'Output 1', 'amount': 1.0}], 'allocations': [{'name': 'Activity 3', 'product': 'Output 1', 'input': 'Input 3'}]}]