Skip to content

Commit

Permalink
Add code to keep isolated buses when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
choiHenry committed Jan 10, 2025
1 parent 2c9c29f commit 1eb3b34
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions scripts/build_bus_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,19 @@ def get_gadm_shape(
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')

non_isolated_regions = onshore_regions[~onshore_regions.name.isin(isolated_buses)]
isolated_regions = onshore_regions[onshore_regions.name.isin(isolated_buses)]

# Combine regions while prioritizing non-isolated ones
onshore_regions = (
pd.concat([non_isolated_regions, isolated_regions])
.drop_duplicates("shape_id", keep="first")
)

if len(onshore_regions) < len(gadm_country):
logger.error(
logger.warning(
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 1eb3b34

Please sign in to comment.