From 0ebb440841c23cf2d7bd95810a1ec4e935f1e164 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Fri, 4 Aug 2023 23:00:41 +0100 Subject: [PATCH] bug fix in interconnectors, added timeseries output --- rules/postprocess.smk | 2 ++ scripts/plot_timeseries.py | 10 ++++++++-- scripts/prepare_network.py | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/rules/postprocess.smk b/rules/postprocess.smk index a6d421f9..df4f20eb 100644 --- a/rules/postprocess.smk +++ b/rules/postprocess.smk @@ -154,6 +154,8 @@ rule plot_timeseries: timeseries_england_short=RESULTS + "graphs/timeseries-short-england_s{simpl}_{gb_regions}_ec_l{ll}_{opts}_{flexopts}_{fes}_{year}.pdf", # emission_timeseries=RESULTS + "graphs/timeseries-emissions_s{simpl}_{gb_regions}_ec_l{ll}_{opts}_{fes_scenario}_{planning_horizons}.pdf", co2_barplot=RESULTS + "graphs/barplot-co2_s{simpl}_{gb_regions}_ec_l{ll}_{opts}_{flexopts}_{fes}_{year}.pdf", + timeseries_inflow=RESULTS + "timeseries/timeseries-inflow_s{simpl}_{gb_regions}_ec_l{ll}_{opts}_{flexopts}_{fes}_{year}.csv", + timeseries_outflow=RESULTS + "timeseries/timeseries-outflow_s{simpl}_{gb_regions}_ec_l{ll}_{opts}_{flexopts}_{fes}_{year}.csv", threads: 1 resources: mem_mb=10000, diff --git a/scripts/plot_timeseries.py b/scripts/plot_timeseries.py index 813961f3..def942e8 100644 --- a/scripts/plot_timeseries.py +++ b/scripts/plot_timeseries.py @@ -202,6 +202,7 @@ def make_co2_barplot(n): tech_colors["AC"] = tech_colors["AC-AC"] tech_colors["GAS CCS"] = tech_colors["power-to-H2"] tech_colors["grid battery"] = tech_colors["battery"] + tech_colors["electricity demand"] = tech_colors["Electric load"] overrides = override_component_attrs(snakemake.input.overrides) n = pypsa.Network(snakemake.input.network, override_component_attrs=overrides) @@ -280,12 +281,16 @@ def intersection(lst1, lst2): outflow["DAC"] = - c.pnl.p2[subset.index].sum(axis=1) - load *= 1e-3 inflow *= 1e-3 outflow *= 1e-3 total = inflow.sum(axis=1) + outflow.sum(axis=1) - load + outflow["electricity demand"] = -load + + if target == "gb": + inflow.to_csv(snakemake.output.timeseries_inflow) + outflow.to_csv(snakemake.output.timeseries_outflow) # make whole year plot fig, ax = plt.subplots(1, 1, figsize=(16, 6)) @@ -314,7 +319,7 @@ def intersection(lst1, lst2): color="black", label="Kirchhoff Check", linestyle="--", - ) + ) ax.set_ylabel("Generation (GW)") @@ -323,6 +328,7 @@ def intersection(lst1, lst2): f"{ scenario_mapper[snakemake.wildcards.fes]};" f"{ snakemake.wildcards.year}" ) + ax.set_title(title) handles, labels = plt.gca().get_legend_handles_labels() by_label = dict(zip(labels, handles)) diff --git a/scripts/prepare_network.py b/scripts/prepare_network.py index acee2163..52f7acb2 100755 --- a/scripts/prepare_network.py +++ b/scripts/prepare_network.py @@ -1163,6 +1163,9 @@ def add_import_export_balance(n): n.links.loc[index, "bus2"] = "import export tracker" n.links.loc[index, "efficiency2"] = 1. + # swap bus0 and bus1 where the GB bus is bus1 + swap_index = dc.loc[index].loc[dc.loc[index].bus1.str.contains("GB")].index + n.links.loc[swap_index, ["bus0", "bus1"]] = n.links.loc[swap_index, ["bus1", "bus0"]].values if __name__ == "__main__":