Skip to content

Commit

Permalink
regions to n.shapes: smooth out remaining issues
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianHofmann committed Apr 10, 2024
1 parent 9686407 commit 47134a8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/base_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions scripts/build_bus_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ def voronoi_partition_pts(points, outline):
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,
Expand All @@ -185,11 +186,13 @@ def voronoi_partition_pts(points, outline):
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,
Expand Down
3 changes: 2 additions & 1 deletion scripts/cluster_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion scripts/simplify_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,5 @@ def cluster(
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)

0 comments on commit 47134a8

Please sign in to comment.