Skip to content

Commit

Permalink
Merge pull request #1287 from choiHenry/AC_drop_overlapping_bus_regions
Browse files Browse the repository at this point in the history
Fix overlapping bus regions when alternative clustering is selected
  • Loading branch information
davide-f authored Jan 10, 2025
2 parents ef525ee + 8c7ec24 commit 1f79db0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This part of documentation collects descriptive release notes to capture the mai

* Prevent computation of powerplantmatching if replace option is selected for custom_powerplants `PR #1281 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1281>`__

* Fix overlapping bus regions when alternative clustering is selected `PR #1287 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1287>`__

PyPSA-Earth 0.6.0
=================
Expand Down
20 changes: 20 additions & 0 deletions scripts/build_bus_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,26 @@ 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
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.warning(
f"The number of remaining of buses are less than the number of administrative clusters suggested!"
)

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

0 comments on commit 1f79db0

Please sign in to comment.