Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overlapping bus regions when alternative clustering is selected #1287

Merged
Merged
Show file tree
Hide file tree
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
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
Loading