GreenDelta/openlca-python-tutorial

Creating a setup containing normalization

dontoasty opened this issue · 2 comments

Hi,
I am trying to calculate a setup with a self-created normalization set ('test') using Python. The end result should be a table containing the name of the product system, the impact category (Ozon depletion etc.), the value, the unit and the normalized value. All in seperate columns. Everything works except for the normalization. I do not know how to implement this correctly. Below you can see my code. Unfortunately, I cannot find an answer in the API documentation, I hope you can help. Thank you!

setup = olca.CalculationSetup()
setup.calculation_type = olca.CalculationType.UPSTREAM_ANALYSIS
setup.amount = 0.79                                                   
setup.impact_method = client.find(olca.ImpactMethod, 'EF 3.0 Method')
setup.nw_set = client.find(olca.NwSet, 'test')

result_correspoding_product_system = []
result_category_list =[]
result_value_list = []
result_unit_list = []
result_normalization_list = []

for ps in range(len(product_system_names)):
    setup.product_system = client.find(olca.ProductSystem, product_system_names[ps])
    
    calc_result = client.calculate(setup)
    
    for i in range(len(calc_result.impact_results)):
        result_correspoding_product_system.append(product_system_names[ps])
        result_category_list.append(calc_result.impact_results[i].impact_category.name)
        result_value_list.append(calc_result.impact_results[i].value)
        result_unit_list.append(calc_result.impact_results[i].impact_category.ref_unit)
        result_normalization_list.append(calc_result.impact_results[i].nw_set)
    
    client.dispose(calc_result)

Normalization and weighting sets (nw-sets) are not stand-alone entities in openLCA but are always linked to a LCIA method. Because of this, you cannot get them via find but you need to load them from the LCIA method. olca.find(olca.ImpactMethod, '...') returns a reference to a LCIA method. You can use the ID of that reference to load the full method:

method_ref = client.find(olca.ImpactMethod, 'TRACI [v2.1, February 2014]')
# getting the full method object via IPC can take a bit currently...
method = client.get(olca.ImpactMethod, method_ref.id)

From the method object you can then get the nw-sets:

for nw_set in method.nw_sets:
  print(nw_set.name)

You can set such a nw-set to the calculation setup but I think there is currently no method for getting the normalized and/or weighted results from the calculation result via olca-ipc (?): https://greendelta.github.io/olca-ipc.py/olca/ipc.html

However, applying normalization and weighting on an LCIA result is simple: just apply the corresponding factors from the nw-set on the LCIA result.

Thank you for the answer!
I now tried to create my own nw-set for an impact assessment method, but it does not work. Here's what I tried:

method = client.get(olca.ImpactMethod, 'd07113f5-5b74-3af3-84ae-9548cbceafd3') 

NWF = olca.NwFactor()
NWF.impact_category = ?
NWF.normalisation_factor = 2.5
NWF.weighting_factor = 1.1

NW = olca.NwSet()
NW.factors = [NWF]

method.nw_sets = [NW]
client.update(method)

I do not know how to reference the impact category (e.g. Water use, right?)
I get an "ok" with doing this, but no new-set shows up in the impact assessment method
Thanks for any hints!