calliope-project / calliope

A multi-scale energy systems modelling framework

Home Page:https://www.callio.pe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some backend component attributes need to be serialised before saving to NetCDF

brynpickering opened this issue · comments

Problem description

Each component in the backend dataset (e.g., the energy_cap variable dataarray) has its own attributes; a combination of useful metadata (the description of the variable) and internally useful stuff, like whether the variable has coordinate data attached to the string representation of objects in its array. One thing which may be considered as useful metadata, but was initially conceived for internal processing, is "references". This is a set of the other components in the backend in which the component in question is referenced. "cost" is referenced in the objective, "carrier_prod" is referenced in the "cost" expression, etc.

These attributes make their way out of the backend dataset and into the model results dataset by way of variables and global expressions.

So, this "references" set needs to be serialised manually for every array before the netcdf can be saved to file, OR it is dropped since it is loses its relevance once it is outside the backend dataset.

I would be more in favour of dropping it, but I don't know if others can see value in keeping it in the results. When loading a model with results from file, it would allow you to see e.g., which constraints carrier_prod was used in, even though you would no longer have access to the constraint objects (until you run model.build()).

Calliope version

0.7.0-dev.

The particular case of references would be solved by it being a list rather than a set. However, the issue still exists that we do not look into individual array attrs when serialising data types that cannot be handled by NetCDF.

Fixed in #489