From 15e986a0ec166dc3285aa5cba6eee5721c006ae6 Mon Sep 17 00:00:00 2001 From: Jonas Hoersch Date: Sun, 10 Feb 2019 16:08:39 +0100 Subject: [PATCH] make_summary: Update summary creation for new line volume/cost constraints Fixes #4. --- Snakefile | 9 ++++++++- scripts/make_summary.py | 15 +++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Snakefile b/Snakefile index 8d43dc91..6c6a7c88 100644 --- a/Snakefile +++ b/Snakefile @@ -268,11 +268,18 @@ rule plot_network: def input_make_summary(w): # It's mildly hacky to include the separate costs input as first entry + if w.ll.endswith("all"): + ll = config["scenario"]["ll"] + if len(w.ll) == 4: + ll = [l for l in ll if l[0] == w.ll[0]] + else: + ll = w.ll return ([COSTS] + expand("results/networks/{network}_s{simpl}_{clusters}_l{ll}_{opts}.nc", network=w.network, + ll=ll, **{k: config["scenario"][k] if getattr(w, k) == "all" else getattr(w, k) - for k in ["simpl", "clusters", "l", "opts"]})) + for k in ["simpl", "clusters", "opts"]})) rule make_summary: input: input_make_summary diff --git a/scripts/make_summary.py b/scripts/make_summary.py index 49ae577e..4f44f8aa 100644 --- a/scripts/make_summary.py +++ b/scripts/make_summary.py @@ -353,7 +353,7 @@ outputs = ["costs", def make_summaries(networks_dict, country='all'): - columns = pd.MultiIndex.from_tuples(networks_dict.keys(),names=["simpl","clusters","lv","opts"]) + columns = pd.MultiIndex.from_tuples(networks_dict.keys(),names=["simpl","clusters","ll","opts"]) dfs = {} @@ -401,15 +401,22 @@ if __name__ == "__main__": w = getattr(snakemake.wildcards, key) return snakemake.config["scenario"][key] if w == "all" else [w] - networks_dict = {(simpl,clusters,lv,opts) : ('results/networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc' + if snakemake.wildcards.ll.endswith("all"): + ll = snakemake.config["scenario"]["ll"] + if len(snakemake.wildcards.ll) == 4: + ll = [l for l in ll if l[0] == snakemake.wildcards.ll[0]] + else: + ll = [snakemake.wildcards.ll] + + networks_dict = {(simpl,clusters,l,opts) : ('results/networks/{network}_s{simpl}_{clusters}_l{ll}_{opts}.nc' .format(network=snakemake.wildcards.network, simpl=simpl, clusters=clusters, opts=opts, - lv=lv)) + ll=l)) for simpl in expand_from_wildcard("simpl") for clusters in expand_from_wildcard("clusters") - for lv in expand_from_wildcard("lv") + for l in ll for opts in expand_from_wildcard("opts")} print(networks_dict)