Skip to content

Commit

Permalink
Fix overlapping bus regions when alternative clustering is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
choiHenry committed Jan 9, 2025
1 parent ef525ee commit 2c9c29f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scripts/build_bus_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ def get_gadm_shape(
crs=country_shapes.crs,
).dropna(axis="index", subset=["geometry"])

if snakemake.params.alternative_clustering:
# determine isolated buses
n.determine_network_topology()
non_isolated_buses = n.buses.duplicated(subset=["sub_network"], keep=False)
isolated_buses = n.buses[~non_isolated_buses].index
# drop isolated buses
onshore_regions = onshore_regions[~onshore_regions.name.isin(isolated_buses)]
# drop duplicates based on shape_id
onshore_regions = onshore_regions.drop_duplicates('shape_id')

if len(onshore_regions) < len(gadm_country):
logger.error(
f"The number of remaining of buses are less than the number of administrative clusters suggested!"
)
raise ValueError("Insufficient buses to match administrative clusters!")

onshore_regions = pd.concat([onshore_regions], ignore_index=True).to_file(
snakemake.output.regions_onshore
)
Expand Down

0 comments on commit 2c9c29f

Please sign in to comment.