From fd026f40727325eeea05f147a6d56195a71d6795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=B6rsch?= Date: Tue, 10 Jul 2018 16:31:57 +0200 Subject: [PATCH] Store the busmaps underlying the simplification process as busmap_s --- Snakefile | 6 ++++-- scripts/cluster_network.py | 3 +++ scripts/simplify_network.py | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Snakefile b/Snakefile index 1aa1c669..739fb0c4 100644 --- a/Snakefile +++ b/Snakefile @@ -100,7 +100,8 @@ rule simplify_network: output: network='networks/{network}_s{simpl}.nc', regions_onshore="resources/regions_onshore_{network}_s{simpl}.geojson", - regions_offshore="resources/regions_offshore_{network}_s{simpl}.geojson" + regions_offshore="resources/regions_offshore_{network}_s{simpl}.geojson", + clustermaps='resources/clustermaps_{network}_s{simpl}.h5' benchmark: "benchmarks/simplify_network/{network}_s{simpl}" threads: 1 resources: mem_mb=4000 @@ -110,7 +111,8 @@ rule cluster_network: input: network='networks/{network}_s{simpl}.nc', regions_onshore="resources/regions_onshore_{network}_s{simpl}.geojson", - regions_offshore="resources/regions_offshore_{network}_s{simpl}.geojson" + regions_offshore="resources/regions_offshore_{network}_s{simpl}.geojson", + clustermaps='resources/clustermaps_{network}_s{simpl}.h5' output: network='networks/{network}_s{simpl}_{clusters}.nc', regions_onshore="resources/regions_onshore_{network}_s{simpl}_{clusters}.geojson", diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 9147bd00..bb9d1065 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -206,6 +206,9 @@ if __name__ == "__main__": clustering.network.export_to_netcdf(snakemake.output.network) with pd.HDFStore(snakemake.output.clustermaps, model='w') as store: + with pd.HDFStore(snakemake.input.clustermaps) as clustermaps: + for attr in clustermaps.keys(): + store.put(attr, clustermaps[attr], format="table", index=False) for attr in ('busmap', 'linemap', 'linemap_positive', 'linemap_negative'): store.put(attr, getattr(clustering, attr), format="table", index=False) diff --git a/scripts/simplify_network.py b/scripts/simplify_network.py index a5300690..9ef2fc74 100644 --- a/scripts/simplify_network.py +++ b/scripts/simplify_network.py @@ -219,4 +219,8 @@ if __name__ == "__main__": n.export_to_netcdf(snakemake.output.network) + busemap_s = reduce(lambda x, y: x.map(y), busmaps[1:], busmaps[0]) + with pd.HDFStore(snakemake.output.clustermaps, model='w') as store: + store.put('busmap_s', busemap_s, format="table", index=False) + cluster_regions(busmaps, snakemake.input, snakemake.output)