GreenDelta / olca-ipc.py

Mozilla Public License 2.0
29 stars 17 forks source link

not able to add output avoided exchange #30

Closed pwierzgala closed 1 year ago

pwierzgala commented 1 year ago

Problem definition

I'd like to add an avoided (is_avoided_product=True) output (is_input=False) exchange to a process but:

Sample code

import olca_ipc as ipc
import olca_schema as o
from olca_schema import ProcessType, FlowType

flow = o.Flow()
flow.id = 'my flow'
flow.name = 'my flow'
flow.flow_type = FlowType.PRODUCT_FLOW

exchange = o.Exchange()
exchange.id = 'my exchange'
exchange.amount = 1
exchange.flow = flow
exchange.is_avoided_product = True  # incorrect
# exchange.is_avoided_product = False  # correct
exchange.is_input = False

process = o.Process()
process.id = 'my process'
process.name = 'my process'
process.process_type = ProcessType.UNIT_PROCESS
process.exchanges = [exchange]

client = ipc.Client()
client.put(flow)
client.put(process)

process = client.get(model_type=o.Process, uid='my process')
print(process.exchanges[0].is_input)
image
Results in Open LCA

Versions

OpenLCA 2.0.0
olca-ipc==2.0.0
olca-schema==0.0.11
msrocka commented 1 year ago

It is confusing but avoided products should be set with is_input = true. I tried to explain this in the schema documentation now: http://greendelta.github.io/olca-schema/classes/Exchange.html#isavoidedproduct

I also added a test which demonstrates this behavior: https://github.com/GreenDelta/olca-ipc.py/blob/master/tests/test_avoided_flows.py