PyPSA-Eur Tutorial KeyError in add_electricity

139 views
Skip to first unread message

Markus Millinger

unread,
Dec 15, 2020, 7:52:55 AM12/15/20
to py...@googlegroups.com

Dear all,


I am trying to run through the PyPSA-Eur tutorial but keep getting the error below.

If I add 'AL' in the yaml the KeyError becomes 'AT', so it seems to go through the countries.


I saw that there were recent KeyErrors because of pandas updates so I tried downgrading but it did not help.


Any helpful advice would be greatly appreciated!


Best regards

Markus




INFO:pypsa.io:Imported network base.nc has buses, lines, links, transformers
INFO:__main__:Load data scaled with scalling factor 1.0.
Traceback (most recent call last):
  File "/home/markus/miniconda3/envs/pypsa-eur/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 2895, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas/_libs/index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 101, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 1675, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 1683, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'AL'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/markus/projects/pypsa-eur/.snakemake/scripts/tmprwohbzrd.add_electricity.py", line 566, in <module>
    attach_load(n)
  File "/home/markus/projects/pypsa-eur/.snakemake/scripts/tmprwohbzrd.add_electricity.py", line 239, in attach_load
    load = pd.concat([upsample(cntry, group) for cntry, group
  File "/home/markus/projects/pypsa-eur/.snakemake/scripts/tmprwohbzrd.add_electricity.py", line 239, in <listcomp>
    load = pd.concat([upsample(cntry, group) for cntry, group
  File "/home/markus/projects/pypsa-eur/.snakemake/scripts/tmprwohbzrd.add_electricity.py", line 220, in upsample
    l = opsd_load[cntry]
  File "/home/markus/miniconda3/envs/pypsa-eur/lib/python3.8/site-packages/pandas/core/frame.py", line 2902, in __getitem__
    indexer = self.columns.get_loc(key)
  File "/home/markus/miniconda3/envs/pypsa-eur/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 2897, in get_loc
    raise KeyError(key) from err
KeyError: 'AL'



Markus Millinger

Space, Earth and Environment
Physical Resource Theory
Chalmers University of Technology
412 96 Göteborg, Sweden

Fabian Neumann

unread,
Dec 15, 2020, 9:52:14 AM12/15/20
to Markus Millinger, py...@googlegroups.com
Hi Markus,

when changing (esp. adding) countries, it's a good idea to delete the
folders resources / networks / results

This is because the intermediary files are often filtered by the country
selection, but snakemake does not see that countries are missing when
you change them in the config.

The combination ["AL", "DE"] fails for me already in
`build_bus_regions`. Probably because they are not connected. An edge
case we hadn't tested.

The combination ["AT", "DE"] runs through without problems.

Maybe deleting the abovementioned folders already solves your problem.
If not, we can explore further.

Best wishes,

Fabian N
> --
> You received this message because you are subscribed to the Google
> Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pypsa+un...@googlegroups.com
> <mailto:pypsa+un...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pypsa/d7061784456d41eeb1ea31a1819d15d5%40chalmers.se
> <https://groups.google.com/d/msgid/pypsa/d7061784456d41eeb1ea31a1819d15d5%40chalmers.se?utm_medium=email&utm_source=footer>.

Markus Millinger

unread,
Dec 16, 2020, 2:03:49 AM12/16/20
to Fabian Neumann, py...@googlegroups.com

Hi Fabian,


thanks a million, deleting the files in those folders worked a charm! Thanks for the swift and nice reply.

The problem seems to have been that I had run the big problem with all countries (unsuccessfully, my internet at home could not handle the download of the 5 GB file.) So some parameters were saved for more countries than needed when only running for Germany. This caused a problem at the add_electricity stage for me. (Although I admit I was tinkering around a bit so there may also be other causes.)


Wouldn't it be handy though for the functions to run if there is information available for more countries than needed (provided that this was actually the issue)? Having to download the files anew requires a fast connection which is not always given and a hurdle especially in less speedy regions of the world.


Best regards

Markus


Markus Millinger

Space, Earth and Environment
Physical Resource Theory
Chalmers University of Technology
412 96 Göteborg, Sweden


From: Fabian Neumann <fabian....@kit.edu>
Sent: 15 December 2020 15:52:08
To: Markus Millinger; py...@googlegroups.com
Subject: Re: [pypsa] PyPSA-Eur Tutorial KeyError in add_electricity
 
Reply all
Reply to author
Forward
0 new messages