From 1eb3b34cadc034ba1d39b2fc57ad28d4bea7fb08 Mon Sep 17 00:00:00 2001 From: Henry Choi Date: Fri, 10 Jan 2025 10:49:28 +0900 Subject: [PATCH] Add code to keep isolated buses when necessary --- scripts/build_bus_regions.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/build_bus_regions.py b/scripts/build_bus_regions.py index c7f48b7ef..6dc057d28 100644 --- a/scripts/build_bus_regions.py +++ b/scripts/build_bus_regions.py @@ -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