Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions scripts/base_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,30 +1469,43 @@ def build_admin_shapes(

if clustering == "administrative":
logger.info(f"Building bus regions at administrative level {level}")

nuts3_regions["column"] = level_map[level]

# Only keep the values whose keys are in countries
countries_config = admin_levels.get("countries", {})
country_level = {
k: v for k, v in admin_levels.items() if (k != "level") and (k in countries)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it still be necessary to filter out the "level" here? Why can it be removed?

k: v for k, v in countries_config.items() if len(k) == 2 and k in countries
}
subregion_level = {
k: v
for k, v in countries_config.items()
if len(k) > 2 and k[:2] in countries
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that also work for the UK, where it shows up as GB in country list but NUTS codes are UK...?

}

if country_level:
country_level_list = "\n".join(
[f"- {k}: level {v}" for k, v in country_level.items()]
)
logger.info(
f"Setting individual administrative levels for:\n{country_level_list}"
"Setting individual administrative levels for:\n"
+ "\n".join(f"- {k}: level {v}" for k, v in country_level.items())
)
nuts3_regions.loc[
nuts3_regions["country"].isin(country_level.keys()), "column"
nuts3_regions["country"].isin(country_level), "column"
] = (
nuts3_regions.loc[
nuts3_regions["country"].isin(country_level.keys()), "country"
nuts3_regions["country"].isin(country_level), "country"
]
.map(country_level)
.map(level_map)
)

if subregion_level:
logger.info(
"Setting individual administrative levels for subregions:\n"
+ "\n".join(f"- {k}: level {v}" for k, v in subregion_level.items())
)
for k, v in subregion_level.items():
nuts3_regions.loc[nuts3_regions.index.str.startswith(k), "column"] = (
level_map[v]
)

# If GB is in the countries, set the level, aggregate London area to level 1 due to converging issues
if "GB" in countries and level != "bz":
nuts3_regions.loc[nuts3_regions.level1 == "GBI", "column"] = "level1"
Expand Down
Loading