bw2io.strategies.json_ld_lcia#

Module Contents#

Functions#

json_ld_lcia_add_method_metadata(data)

Add metadata of the Life Cycle Impact Assessment (LCIA) method to the corresponding impact categories.

json_ld_lcia_convert_to_list(data)

Convert the Life Cycle Impact Assessment (LCIA) categories in the given data to a list.

json_ld_lcia_reformat_cfs_as_exchanges(data)

Reformat the impact factors of Life Cycle Impact Assessment (LCIA) methods as exchanges.

json_ld_lcia_set_method_metadata(data)

Update the metadata of Life Cycle Impact Assessment (LCIA) methods in the given data.

bw2io.strategies.json_ld_lcia.json_ld_lcia_add_method_metadata(data)[source]#

Add metadata of the Life Cycle Impact Assessment (LCIA) method to the corresponding impact categories.

Iterates over the LCIA methods and adds metadata from the method to each of its impact categories. The metadata includes the method’s name, description, version, and lastChange.

Parameters#

datadict

A dictionary containing LCIA methods and their impact categories.

Returns#

dict

A dictionary with the updated LCIA impact categories containing the parent method metadata.

Examples#

>>> data = {

… “lcia_methods”: { … “method_1”: { … “name”: “LCIA Method 1”, … “description”: “Sample LCIA Method 1”, … “version”: “1.0”, … “lastChange”: “2021-01-01”, … “impactCategories”: [ … {“@id”: “category_1”}, … {“@id”: “category_2”}, … ], … }, … }, … “lcia_categories”: { … “category_1”: {}, … “category_2”: {}, … }, … } >>> json_ld_lcia_add_method_metadata(data) {

‘lcia_methods’: {
‘method_1’: {

‘name’: ‘LCIA Method 1’, ‘description’: ‘Sample LCIA Method 1’, ‘version’: ‘1.0’, ‘lastChange’: ‘2021-01-01’, ‘impactCategories’: [

{‘@id’: ‘category_1’}, {‘@id’: ‘category_2’},

],

},

}, ‘lcia_categories’: {

‘category_1’: {
‘parent’: {

‘name’: ‘LCIA Method 1’, ‘description’: ‘Sample LCIA Method 1’, ‘version’: ‘1.0’, ‘lastChange’: ‘2021-01-01’,

},

}, ‘category_2’: {

‘parent’: {

‘name’: ‘LCIA Method 1’, ‘description’: ‘Sample LCIA Method 1’, ‘version’: ‘1.0’, ‘lastChange’: ‘2021-01-01’,

},

},

},

}

bw2io.strategies.json_ld_lcia.json_ld_lcia_convert_to_list(data)[source]#

Convert the Life Cycle Impact Assessment (LCIA) categories in the given data to a list.

Takes the LCIA categories from the input data dictionary and returns them as a list.

Parameters#

datadict

A dictionary containing the LCIA categories with their respective keys.

Returns#

list

A list of dictionaries representing the LCIA categories.

Examples#

>>> data = {
...     "lcia_categories": {
...         "category_1": {"name": "LCIA Category 1"},
...         "category_2": {"name": "LCIA Category 2"},
...     }
... }
>>> json_ld_lcia_convert_to_list(data)
[{'name': 'LCIA Category 1'}, {'name': 'LCIA Category 2'}]
bw2io.strategies.json_ld_lcia.json_ld_lcia_reformat_cfs_as_exchanges(data)[source]#

Reformat the impact factors of Life Cycle Impact Assessment (LCIA) methods as exchanges.

Modifies the given LCIA methods data by renaming the ‘impactFactors’ field to ‘exchanges’ and updating the fields within each exchange.

Parameters#

datalist

A list of dictionaries representing LCIA methods with impact factors.

Returns#

list

A list of dictionaries representing the updated LCIA methods with reformatted exchanges.

Examples#

>>> data = [
...     {
...         "impactFactors": [
...             {
...                 "value": 1.0,
...                 "unit": {"name": "kg"},
...             }
...         ],
...     }
... ]
>>> json_ld_lcia_reformat_cfs_as_exchanges(data)
[
    {
        'exchanges': [
            {
                'amount': 1.0,
                'unit': 'kg',
            }
        ],
    }
]
bw2io.strategies.json_ld_lcia.json_ld_lcia_set_method_metadata(data)[source]#

Update the metadata of Life Cycle Impact Assessment (LCIA) methods in the given data.

Processes the metadata of the LCIA methods in the given data, removing unnecessary fields, renaming fields, setting units, and updating the name and description.

datalist

A list of dictionaries representing LCIA methods with metadata.

list

A list of dictionaries representing the updated LCIA methods with modified metadata.

>>> data = [
...     {
...         "@context": "http://www.example.com",
...         "@type": "LCIA",
...         "referenceUnitName": "kg",
...         "@id": "method_1",
...         "name": "LCIA Method 1",
...         "description": "Sample LCIA Method 1",
...         "parent": {
...             "name": "Parent Method",
...             "description": "Sample parent method",
...         },
...     }
... ]
>>> json_ld_lcia_set_method_metadata(data)
[
    {
        'unit': 'kg',
        'id': 'method_1',
        'name': ('Parent Method', 'LCIA Method 1'),
        'description': 'Sample LCIA Method 1
Sample parent method’,
‘parent’: {

‘name’: ‘Parent Method’, ‘description’: ‘Sample parent method’,

},

}

]