0 votes
343 views

I am trying to update the allocation factors using python. I can find the allocation values but I do not know how to relate the internal exchange id to the actual table. Below is the casual allocation table with confidential numbers removed. How to a link the internal id to the flows? In my code below I examined the properties of "c" and the product only tells my the column header (1-Bioethan...), and the exchange which I believe is related to the rows (Alpha amylase) only provides a internal id. Is there anyway to relate the internal id to the flow? Can I use the exchange id somehow to identify the flow? I have looked at the https://greendelta.github.io/olca-ipc.py/olca/index.html but I can't seem to figure out how the exchange relates to the flow.

import olca
from olca.schema import Process, Exchange
from olca import _allocation_of
from olca.ipc import ModelType
client = olca.Client(8080)
Production = client.find(Process, '1- Bioethanol production, at bioethanol plant')
Production2 = client.get(Production.olca_type, Production.id, Production.name)
print(Production2.olca_type)

x=Production2.allocation_factors
with open('readme.txt', 'w') as f:
    for line in x:
        f.write(str(line))
        f.write('\n')

for c in x:
    if c.allocation_type.name == 'CAUSAL_ALLOCATION':
        print(c.value)

in openLCA by (230 points)
edited by

1 Answer

0 votes
by (230 points)

The AllocationFactor Class uses get ExchangeRef which only provides the internal ID. If the code is changed to use Exchange instead of ExchangeRef you are able to determine the flow id. Not sure if this will cause problems elsewhere but it works for now.

def read_json(self, json: dict): super(AllocationFactor, self).read_json(json) val = json.get('allocationType') if val is not None: self.allocation_type = AllocationType(val) val = json.get('product') if val is not None: self.product = Ref() self.product.read_json(val) val = json.get('value') if val is not None: self.value = val val = json.get('formula') if val is not None: self.formula = val val = json.get('exchange') if val is not None: self.exchange = ExchangeRef() self.exchange.read_json(val)

https://greendelta.github.io/olca-ipc.py/olca/schema.html#olca.schema.AllocationFactor

...