From 47134a88d833e2db1c1a6d95fd070ab208d5d5d6 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 10 Apr 2024 18:13:14 +0200 Subject: [PATCH] regions to n.shapes: smooth out remaining issues --- scripts/base_network.py | 2 +- scripts/build_bus_regions.py | 7 +++++-- scripts/cluster_network.py | 3 ++- scripts/simplify_network.py | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/base_network.py b/scripts/base_network.py index 77d3d250..528f04bf 100644 --- a/scripts/base_network.py +++ b/scripts/base_network.py @@ -705,7 +705,7 @@ def _set_shapes(n, country_shapes, offshore_shapes): offshore_shapes = gpd.read_file(offshore_shapes).rename(columns={"name": "idx"}) offshore_shapes["type"] = "offshore" all_shapes = pd.concat([country_shapes, offshore_shapes]) - n.shapes = pd.concat([n.shapes, all_shapes]) + n.shapes = pd.concat([n.shapes, all_shapes], ignore_index=True) def base_network( diff --git a/scripts/build_bus_regions.py b/scripts/build_bus_regions.py index 816c7fad..d26e6ba6 100644 --- a/scripts/build_bus_regions.py +++ b/scripts/build_bus_regions.py @@ -176,7 +176,8 @@ if __name__ == "__main__": gdf = pd.concat(onshore_regions, ignore_index=True) gdf.to_file(snakemake.output.regions_onshore) - index = gdf.index.astype(int) + n.shapes.index.astype(int).max() + 1 + offset = n.shapes.index.astype(int).max() + 1 if not n.shapes.empty else 0 + index = gdf.index.astype(int) + offset n.madd( "Shape", index, @@ -185,11 +186,13 @@ if __name__ == "__main__": component="Bus", type="onshore", ) + if offshore_regions: gdf = pd.concat(offshore_regions, ignore_index=True) gdf.to_file(snakemake.output.regions_offshore) - index = gdf.index.astype(int) + n.shapes.index.astype(int).max() + 1 + offset = n.shapes.index.astype(int).max() + 1 if not n.shapes.empty else 0 + index = gdf.index.astype(int) + offset n.madd( "Shape", index, diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index a2473beb..7a497626 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -443,7 +443,8 @@ def cluster_regions(busmaps, which, input=None, output=None): n.mremove("Shape", remove) # add new clustered regions - index = regions_c.index.astype(int) + n.shapes.index.astype(int).max() + 1 + offset = n.shapes.index.astype(int).max() + 1 if not n.shapes.empty else 0 + index = regions_c.index.astype(int) + offset type = which.split("_")[1] n.madd( "Shape", diff --git a/scripts/simplify_network.py b/scripts/simplify_network.py index 24df7312..6e404192 100644 --- a/scripts/simplify_network.py +++ b/scripts/simplify_network.py @@ -629,4 +629,5 @@ if __name__ == "__main__": busmap_s = reduce(lambda x, y: x.map(y), busmaps[1:], busmaps[0]) busmap_s.to_csv(snakemake.output.busmap) - cluster_regions(busmaps, snakemake.input, snakemake.output) + for which in ["regions_onshore", "regions_offshore"]: + cluster_regions(busmaps, which, snakemake.input, snakemake.output)