+1 vote
137 views
Hi,

I'm a beginner with openLCA and I don't want to create own flows or processes, but I'd like to calculate product systems that I created out of selected processes.

I'm want to use the olca-ipc package for this, Jython would not be an option because it implements an old Python version and as far as I know I can't run it without using the GUI.

On the GitHub of the olca-ipc package I found the example to calculate product systems, but how can I create a product system from a chosen process?
in openLCA by (160 points)

1 Answer

+1 vote
by (3k points)
selected by
 
Best answer

Lucky for you (well maybe not, it is a month later), they recently implemented this in olca-ipc. Here's an example:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import olca
from olca import ipc as ipc
from datetime import datetime
import pytz

client = olca.Client(60000) #default value for this is 8080

all_processes = client.get_descriptors(olca.Process)
#Look for processes that contain some text you want to match
target_processes = [
    x
    for x in all_processes
    if "some string I want to match" in x.name
]

datetime_str = datetime.now(pytz.utc).isoformat()

for olca_proc in target_processes :
    new_system_ref = client.create_product_system(
        process_id=olca_proc.id,
        default_providers="only",
        preferred_type="SYSTEM_PROCESS",
    ) #This returns a reference, not an olca.ProductSystem
    new_system=client.get(olca.ProductSystem,new_system_ref.id)
    new_system.olca_type = olca.schema.ProductSystem.__name__
 
    new_system.description = (
        f"Some description you want"
    )
    #name the product system the same as your process
    new_system.name = olca_proc.name
    model_type_str = f"{olca.ModelType.PRODUCT_SYSTEM}"
    new_system.version = "1.0.0"
    new_system.olca_type = olca.schema.ProductSystem.__name__
    new_system.category_path = []
    new_system.last_change=datetime_str
    client.update(new_system)
by (150 points)
That did the trick :) Thanks a lot !
...