Skip to content

Individual NUTS level definition not working in clustering.administrative.countries config setting #2207

Description

@gianvicolux

Version Checks (indicate both or one)

  • I have confirmed this bug exists on the lastest release of PyPSA-Eur.

  • I have confirmed this bug exists on the current master branch of PyPSA-Eur.

Issue Description

Specifying the individual NUTS levels for some countries as a dictionary in clustering.administrative.countries config setting, seems not to working as expected in the clustering documentation.

In particular, the level defined in clustering.administrative.level is applied also to the countries in clustering.administrative.countries , despite they have a different level.

This seems to be due to this part of code in build_admin_shapes in base_network.py:

country_level = {
         k: v for k, v in admin_levels.items() if (k != "level") and (k in countries)
}

Instead, it might work changing it into:

country_level = {
         k: v for k, v in admin_levels.get("countries", {}).items()
         if k in countries
}

Reproducible Example

When using this setting:

clustering:
  mode: administrative
  administrative:
    level: bz
    countries: {'DE': 2}

and checking the admin_shapes.geojson:

admin_shapes = gpd.read_file("[...]/admin_shapes.geojson")
display(admin_shapes[admin_shapes["country"] == "DE"].admin)

one would see DE00.

Expected Behavior

When using this setting:

clustering:
  mode: administrative
  administrative:
    level: bz
    countries: {'DE': 2}

and checking the admin_shapes.geojson:

admin_shapes = gpd.read_file("[...]/admin_shapes.geojson")
display(admin_shapes[admin_shapes["country"] == "DE"].admin)

one would expect:

DE11
DE12
...
DEG0

Installed Versions

Too long to post.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions