message_ix icon indicating copy to clipboard operation
message_ix copied to clipboard

Add timeseries: lvl_spatial leads to an error

Open tzipperle opened this issue 6 years ago • 1 comments

If I add a further spatial level (eg. state: Vienna) is it not possible to add a timeseries. I have added a short code example with the austrian tutorial: https://github.com/tzipperle/message_ix/blob/test-timeseries/tutorial/Austrian_energy_system/austria-add_timeseries.ipynb

So I added the spatial level:

country = "Austria"
state = "Vienna"
scenario.add_set("node", [country, state, "state"])
scenario.add_set("lvl_spatial", ["country", "state"])
scenario.add_set("map_spatial_hierarchy", ["state", state, "World"])
scenario.add_set("map_spatial_hierarchy", ["country", country, "state"])
at.ac.iiasa.ixmp.exceptions.IxExceptionPyRaisable
Traceback (most recent call last)
<ipython-input-44-991cd1855e1c> in <module>()
----> 1 scenario.add_timeseries(ts)

~\AppData\Local\Continuum\anaconda3\envs\message\lib\site-packages\ixmp\core.py in add_timeseries(self, df, meta)
    348                           java.Double(float(df.value[i])))
    349             # add the final iteration of the loop
--> 350             self._jobj.addTimeseries(region, variable, time, jData, unit, meta)
    351 
    352         # if in 'IAMC-style' format

at.ac.iiasa.ixmp.exceptions.IxExceptionPyRaisable: at.ac.iiasa.ixmp.exceptions.IxException: The node 'Vienna' does not exist in the database!'

tzipperle avatar Apr 16 '18 13:04 tzipperle

Thanks @tzipperle for identifying this issue - it's not directly a bug, more a missing feature at this point. The nodes in a Scenario set and the timeseries are not linked and are stored in different places in the database.

A quickfix would be to open the underlying HSQL db and add Vienna to the table IAMC_NODES.

The bigger fix will be to link the two structures for spatial hierarchy. This should be linked to a clean MESSAGEix postprocessing module.

I added an issue in the ixmp repository -> https://github.com/iiasa/ixmp/issues/28

danielhuppmann avatar Apr 16 '18 14:04 danielhuppmann

This looks to me like it has been solved in the meantime by iiasa/ixmp#125. And if I now insert the following in the austria_load_scenario notebook after load the scenario and removing existing solutions, but before solving again, it works without errors:

scenario.check_out()
country = "Austria"
state = "Vienna"
scenario.add_set("node", [country, state, "state"])
scenario.add_set("lvl_spatial", ["country", "state"])
scenario.add_set("map_spatial_hierarchy", ["state", state, "World"])
scenario.add_set("map_spatial_hierarchy", ["country", country, "state"])

So I'll close this issue.

glatterf42 avatar Mar 21 '23 08:03 glatterf42