0 votes
449 views

Dear all,

I am referring to a question Parameterized calculation setups in python - ask.openLCA - Question and Answer (Q&A) on Life Cycle Assessment (LCA) - A Life Cycle Assessment (LCA) Community in 2020, which matches my needs, but I think there is a change in syntax between OpenLCA 1.x and 2.x.

I have a parametrized model in my database, want to change the parameters via the ParameterReDef and run the calculation by a phyton script. In the documentation there is an example for the redefinition of one parameter. I have adapted the code to my needs to cover this issue but I am not sure if this is the right way.

myPSystem=client.get_descriptors(schema.ProductSystem, "36db6ce6-5575-410d-9933-ecfb66db35f0")
myPSystem_par=client.get_parameters(schema.ProductSystem,"36db6ce6-5575-410d-9933-ecfb66db35f0")
 
# Ansteuern des IPC Servers
setup = schema.CalculationSetup(
        target=myPSystem,
        impact_method=schema.Ref(id="c45bb4f6-8b50-425f-a4f6-c69668d7ac96"),
        parameters=[schema.ParameterRedef(name=myPSystem_par[1].name, value=4000,context=myPSystem_par[1].context),
                    schema.ParameterRedef(name=myPSystem_par[2].name, value=250,context=myPSystem_par[1].context)],
amount=inputs["fnctionalunit"])

Kind regards,

Dieter

in openLCA by (810 points)

1 Answer

+1 vote
by (7.3k points)
Hi Dieter,

This is the way to do it indeed. Be careful, the context of the second parameter redefinition might be wrong as you are using the index 1 and not 2.

Is something not working?

Regards,

François
by (810 points)
Thanks for your fast confirmation! I really was not sure if it is right or wrong (i was confused by the post of 2020). The first parameter on position 0 is a global one which I don´t need so start number will be 1 and ascending.

Kind regards,
Dieter
by (100 points)
Hello,
I tried to implement a similar application. However, I cannot get the ParameterRedef method to work.
Here is a snippet of my code:

myPSystem = client.get_descriptors(schema.ProductSystem)  # I had to get rid of the UUID as it raised an error (2 arguments expected, 3 given)
myPSystem_par = client.get_parameters(schema.ProductSystem, "bb62617b-6bc3-46a6-b7a3-100574780b1b")

bsp_liste = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]

for i in range(len(myPSystem_par)):
    print(bsp_liste[i])
    print(f"Parameter Name: {myPSystem_par[i].name}, Value: {myPSystem_par[i].value}, Context: {myPSystem_par[i].context}")
    # myPSystem_par[i].value = float(bsp_liste[i])
    schema.ParameterRedef(name=myPSystem_par[i].name, value=float(bsp_liste[i]), context=myPSystem_par[i].context)
    print(f"Parameter Name: {myPSystem_par[i].name}, Value: {myPSystem_par[i].value}, Context: {myPSystem_par[i].context}")

The code should display the names and values of the parameters within the product system, then change the values and display the new values. Instead, I get the same result twice (so no redefinition is being done). I also tried to change only one value (so no for loop), but it didn’t work either.

Has anyone else encountered a similar issue and could help me out?

Thanks in advance!

Regards,

Armando
...