Accessing total emissins after optimization

Dear all,

I have not been able to access the total emissions using the syntax provided in the documentation:
om.oemof.solph._models.Model.integral_limit_${keyword}()
I already get the first syntax error because the om "Model object has no attribute ‘oemof’ "

Any help would be greatly appreciated.
Also I wish you all a good start to the new year :smiley:

Hello Moritz,

a happy new year to you too.
From your post, I assume you succeeded in creating the constraint.

Now accessing the value after optimization is not so straightforward.

First, let me explain your error, assuming om is the name of your model, i.e. is of instance oemof.solph._models.Model. Now the problem is that you try to run through the module / import levels again, although you are already at oemof.solph._models.Model when writing om (sorry, the formulation here is a bit sloppy).

So om.integral_limit_${keyword} is what you need to access the constraint. The Model instance does carry all constraints resp. blocks as attributes that you can access.
Nonetheless, you will then access only the pyomo constraint object which will yield sort of a cryptic string representation and not the emission value you are interested in. You can use the pprint() method to get some insights, but this is more interesting for your model setup as it won’t yield the value after optimization.

To retrieve the value, try the following after your optimization:

import pyomo.environ as pyo
pyo.value(om.integral_limit_${keyword})

I hope this works for you and helps.

Best,
Johannes

P.S.: It would be helpful if you quoted the part of the oemof.solph docs where your code is from. If it is erroneous, it should be fixed in the docs.

Hi Johannes,

thanks for your quick answer, however this formulation still seems to cause a syntax error (i.e. I’m told that the bracket around value is not close). Any ideas? Would I have to replace keyword with “emission_factor”?

Cheers,

Moritz

Also here is a link to the documentation page where I found the suggestion for the code:
https://oemof-solph.readthedocs.io/en/latest/_modules/oemof/solph/constraints/integral_limit.html#
See here under general_integral_limit :slight_smile:

${keyword} was meant to be a placeholder for a custom limit, e.g. a space limit. That would be named integral_limit_space. The emission_limit is actually predefined in the constraints module. It collects all flows with an emission_factor attribute.

Thus, accessing the value of the emission limit would be
pyo.value(om.emission_limit).

Hope that helps / works.