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/
208 stars 167 forks source link

fix: :bug: Fix IDs of 9 countries, using the smallest geometry that contains them #921

Closed AndreCNF closed 7 months ago

AndreCNF commented 8 months ago

Changes proposed in this Pull Request

Maps 9 countries' ISO Alpha 2 codes to working IDs. These countries would fail otherwise. The new IDs were chosen via a geopandas contains operation, selecting the smallest geometry from get_geom_sitemap that fully contains the country.

e.g.

# load PyPSA Earth's GeoDataFrame
eo_gdf = get_geom_sitemap()
# find the smallest geometry that contains a country
country = failed_countries[0]
country_aws_gdf = naturalearth_gdf.loc[naturalearth_gdf[COUNTRY_ID_COLUMN] == country]
matches_gdf = eo_gdf.loc[eo_gdf.contains(country_aws_gdf.iloc[0].geometry)]
matches_gdf["area"] = matches_gdf.area
matches_gdf.sort_values(by="area", ascending=True, inplace=True)
matches_gdf

Checklist

AndreCNF commented 8 months ago

As comments, do you need these codes for your study?

Yes, we're running models over every country in the world at TransitionZero and we've noticed issues for these 9 countries.

davide-f commented 7 months ago

Many thanks for the contribution! Ready to merge :D congratulations, you will soon be a new contributor to the community :)