Skip to content

Commit

Permalink
bug fix in interconnectors, added timeseries output
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasFrankenQ committed Aug 4, 2023
1 parent 2295d10 commit 0ebb440
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions rules/postprocess.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions scripts/plot_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -314,7 +319,7 @@ def intersection(lst1, lst2):
color="black",
label="Kirchhoff Check",
linestyle="--",
)
)

ax.set_ylabel("Generation (GW)")

Expand All @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions scripts/prepare_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 0ebb440

Please sign in to comment.