message_ix
message_ix copied to clipboard
Add timeseries: lvl_spatial leads to an error
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!'
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
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.