pypsa-meets-earth / pypsa-earth

PyPSA-Earth: A flexible Python-based open optimisation model to study energy system futures around the world.
https://pypsa-earth.readthedocs.io/en/latest/
207 stars 167 forks source link

Simplify network lead to a bug in GADM shapes #382

Open pz-max opened 2 years ago

pz-max commented 2 years ago

Checklist

Describe the Bug

Summary of bugs:

I am running PyPSA-Africa for Nigeria with the GADM clustering option which retrieves GADM shapes also known as administrative zones. See the automatic download: gadm-shapes Creating the regions_onshore looks still fine. I am not sure yet what the colour change means. Maybe it is indicating an error? One bug is that black hole inside Africa! regions_onshore Nevertheless, the real bug appears when running simplify_network.py which then creates networks/elec_s{simpl}.nc. As you can see, hovering over one shape, it seems that some shapes are combined. regions_onshore_elec_s

One needs to debug simplify_network and investigate the step where this occurs. We need to find a solution to this issue.

jome1 commented 1 week ago

I think I know now why some shapes are weirdly combined when hovering over them and why the there is the color change. (or at least it is a puzzle piece :)

It is because the single polygons do not conterminous properly anymore. To see this, you have to zoom in a lot (maybe use QGIS to better analyse). In the script build_shapes.py the GADM zones are downloaded and then simplified. During this simplification holes and overlaps between the polygons can occur. (See https://github.com/pypsa-meets-earth/pypsa-earth/issues/1051)

The simplification in the script build_shapes.py is done with shapely.simplify

To solve this problem, shared boarders of conterminous (neighbouring) polygons should not be simplified or the neighbouring polygons have to be simplified to the same line.

I did a little internet search. Maybe shapely.snap could help to solve this problem. Here is also a helpful mini thread about this phenomenon