0 votes
36 views

Dear all,

in my OpenLCA IPC python I have two types of flows (besides in or output ;)): from ecoinvent or not

non Ecoinvent:

mass_flow_property=client.get(schema.FlowProperty, name="Mass") # unit Mass
Substrat_flow=schema.new_flow('Substrat',schema.FlowType.PRODUCT_FLOW,mass_flow_property))
SubstratIn=schema.new_input(WProzess,Substrat_flow,inputs["subst_mass"],'kg')

Ecoinvent

argon_gas=client.get(schema.Flow, "a94ce0ad-46f5-407c-b445-671e353875f0") # Flow Argon fluessig
ArgonIn=schema.new_input(WProzess, argon_gas, argon_mass,'kg')
ArgonIn.default_provider=client.get(schema.Process,"aa6e701a-3728-4375-90b2-0e63eda7a627")

 The parameters "argon_mass" and inputs["subst_mass"] are variables regarding amount of flows. 

My question is if the proposed lines for new_input is correct to choose 'kg' for those flows? Unfortunately, right now this approach ends up in an error...:

  File "C:\...\myscript.py", line 72, in <module>
    ArgonIn=schema.new_input(WAMProzess, argon_gas, argon_mass,'kg')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HorwatitschD\AppData\Local\Programs\Python\Python311\Lib\site-packages\olca_schema\__init__.py", line 255, in new_input
    exchange = new_exchange(process, flow, amount, unit)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HorwatitschD\AppData\Local\Programs\Python\Python311\Lib\site-packages\olca_schema\__init__.py", line 229, in new_exchange
    exchange.unit = as_ref(unit)
                    ^^^^^^^^^^^^
  File "C:\Users\HorwatitschD\AppData\Local\Programs\Python\Python311\Lib\site-packages\olca_schema\__init__.py", line 424, in as_ref
    return e if isinstance(e, Ref) else e.to_ref()
                                        ^^^^^^^^
  AttributeError: 'str' object has no attribute 'to_ref'

Looking at the error messages, it seems that the allocation of the unit hasn´t worked... Does somebody has a clue...??

Kind regards

in openLCA by (610 points)

1 Answer

+1 vote
by (6.5k points)
selected ago by
 
Best answer

Hi DiHorw,

Thank you for reaching the community via ask.openlca.org.

The new_input method does not take unit parameter as string but as Ref or Unit.

This unit is optional, and in your case you could omit it. The reason is that I am guessing that your unit group for mass is using kg by default.

If you really need to use a unit:

mass_group = client.get(o.UnitGroup, name='Units of mass')
kg = next((unit for unit in mass_group.units if unit.name == 'kg'), None)

Regards,

François

ago by (610 points)
Thanks a lot! It is not only regarding mass units, where kilograms are dominating. In the case of energy it is kWh, Wh, MJ....
...