+2 votes
2.2k 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 (170 points)

1 Answer

+2 votes
by (5.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 (14.0k points)
In addition, there is also a function for creating a linked product system directly from a process now: https://greendelta.github.io/olca-ipc.py/olca/ipc.html#olca.ipc.Client.create_product_system

This version is not uploaded on PyPi yet because there are some other things that I want to include in the next release... (I hope I can get this ready next week). But you can use this function when you install the version from the Github master branch.
by (170 points)
I just cloned it and tried it. Works like a charm, thanks a lot for the continued development of the olca-ipc.py!

@mjamieson thanks a lot for finding the function and connecting it to the question, I really was giving up on that one!
by (190 points)
Nice one! I also had Problems with creating product systems with the olca-ipc and was working on a troublesome workaround.  Thanks for posting this answer.

When I install olca-ipc from the linked github repository the function "client.create_product_system" works fine. However with that installation of olca-ipc, I run into errors when including or deleting processes (errormessage: -32602: Invalid params: params must be an object with valid @id and @type). My guess is thats due to the work in progress on this olca-ipc version because when I install it from the python package index, including and deleting processes works fine (but there is no function create_product_system).
Do you experience similar errors ? Or is it something with my installation of the module ?
by (5.3k points)
Once you get the process you want, you need to fix the olca_type for that process. In my version, any process types are being returned with olca_type=''. Try target_process.olca_type=olca.schema.Process.__name__ before deleting
by (190 points)
That did the trick :) Thanks a lot !
by (720 points)
edited by
I am new to ipc and not sure how to get the linked github installation, advice appreciated.
...