Show storage_content of GenericStorage

Hi,

can anyone tell me how I can see the storage_content of my storage in the results?

I defined my storage this way:

storage = solph.components.GenericStorage(
    label="storage",
    nominal_storage_capacity = hydrogen_storage_capacity,
    inputs={
        b_h2: solph.Flow(
            nominal_value=hydrogen_storage_input_flow,
            variable_costs=hydrogen_storage_variable_costs,
            nonconvex=solph.NonConvex()
        )
    },
    outputs={
        b_h2:solph.Flow(
            nominal_value=hydrogen_storage_output_flow
        )
    },
    loss_rate=hydrogen_storage_loss_rate,
    initial_storage_level=hydrogen_storage_initial_storage_rate,
    #inflow_conversion_factor=0.9,
    #outflow_conversion_factor=0.9
)

And tried several commands like this:

results[(storage, None)]['sequences']["storage_content"]

But I get this error message:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[146], line 1
----> 1 results[(storage, None)]['sequences']["storage_content"]

KeyError: ("<oemof.solph.components._generic_storage.GenericStorage: 'storage'>", None)

In this picture you can see that the node exist:

Thanks for your help.
Kind regards
Luca

Hi @dhorschi,

without seeing the rest of the script, I have to guess. Maybe, you called “convert_keys_to_strings” somewhere? In that case, the storage object is no longer part of the key but it is replaced by its label.

Cheers,
Patrik

Hey @pschoen,

yes, I used “convert_keys_to_strings”.
Does this mean that I have to write “storage” in quotation marks in this case? Unfortunately, that didn’t work either

If you use convert_keys_to_strings without the argument keep_none_type=True, it will also convert None to 'None'.

In most situations, I avoid using convert_keys_to_strings. This is true especially for single-script programs, as in these cases you can almost always have the objects available. (Of course this is a point of personal preference.) One exception is if you want to use the same data analysis code for your freshly optimised energy system and a dataframe restored from csv. In the latter case, the objects are lost, so the other data has to be adjusted.

1 Like