+1 vote

In the screenshot, I show the code generating the output in the console for the unit process at the right. the values in the unit process are correct (ie match the external spreadsheet), but the values that the code reports are different. The inputs in the process are all based on parameters. I have similar code in the IPC that returns the same incorrect values. I am not sure what could be the cause. I have closed and opened the database and still have the same problem. Thanks.

in openLCA by (610 points)

1 Answer

0 votes
by (13.6k points)
selected by
Best answer

When an exchange has a formula, the amount field is not always updated when a parameter value changes. The truth is in the formula then, not in the amount field. The formulas are interpreted and the updated values are displayed when a process is opened in the user interface. Also, all formulas are evaluated in the calculation of course (with possible re-definitions of local and global parameter values of the calculation setup).

When a process is modified and saved, the current formula values are written into the amount fields. But when a global parameter changes, we do not update all amount fields. As the processes would change then, we also would have to increment the versions, last change timestamps with possible effects on data exchange with the collaboration server etc.


In the openLCA Python editor, you can create a formula interpreter. You need to register all processes that have local parameters and formulas you want to evaluate as interpreter scopes. In the example below it simply registers all processes and then evaluates the formula of one process in its scope:

process_ids = set()
for p in db.getDescriptors(Process):
interpreter = ParameterTable.interpreter(db, process_ids, set())
process = db.get(Process, "43ba4a27-a674-4a7c-bc84-b05a431bcb55")
scope = interpreter.getScopeOrGlobal(process.id)
for e in process.exchanges:
  if e.formula is not None and e.formula != "":
    value = scope.eval(e.formula)
    print("%s = %.4f" % (e.formula, value))

by (610 points)
thank you!  Does this work for the IPC interface?  or is the syntax different? I have Python code using pandas to format the output as tables and would like to create an interpreter in that environment.