PyPSA / atlite

Atlite: A Lightweight Python Package for Calculating Renewable Power Potentials and Time Series
https://atlite.readthedocs.io
265 stars 89 forks source link

unmanaged out of shape exception in hydro: index 0 is out of bounds for axis 0 with size 0 #188

Open davide-f opened 2 years ago

davide-f commented 2 years ago

Dear developers, In the hydro function, I experience the exeption "index 0 is out of bounds..." in hydro.py#34 as some of the plants that I am passing to the hydro function are outside the region delimited by the hydrobasins.

Description

The issue should arise for any problem concerning hydro.py, assuming to give a point in plants outside the region delimited by hydrobasins.

Expected Behavior

I think it would be useful to avoid this issue and simply put a 0.0 for such cases.

Actual Behavior

Currently, instead, the algorithm stops and the exception is thrown

Error Message

File "C:\ProgramData\Miniconda3\envs\toast\lib\site-packages\atlite\convert.py", line 596, in hydro basins = hydrom.determine_basins(plants, hydrobasins, show_progress=show_progress) File "C:\ProgramData\Miniconda3\envs\toast\lib\site-packages\atlite\hydro.py", line 75, in determine_basins hid = find_basin(shapes, p.lon, p.lat) File "C:\ProgramData\Miniconda3\envs\toast\lib\site-packages\atlite\hydro.py", line 34, in find_basin return hids[0] File "C:\ProgramData\Miniconda3\envs\toast\lib\site-packages\pandas\core\indexes\base.py", line 4604, in getitem return getitem(key) IndexError: index 0 is out of bounds for axis 0 with size 0

Your Environment

FabianHofmann commented 2 years ago

thanks for reporting @davide-f, since you seem to have dived into the code a bit, would you mind making a PR on this issue?

FabianHofmann commented 1 year ago

closing this, please reopen if issue remains