Skip to content

Commit 7798215

Browse files
JulianGeislindnemi
andauthored
Export missing variables for trade and policy (#85)
* export firs trade variables * add plotting for trade and issing policy variables * added Trade|Secondary Energy|Liquids|Hydrogen|Volume and Trade|Primary Energy|Gas|Volume * undo config changes * fix undo config changes * cleanup --------- Co-authored-by: Michael Lindner <michaellindner@posteo.de>
1 parent 40efe61 commit 7798215

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

workflow/Snakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ rule plot_ariadne_variables:
378378
policy_carbon = RESULTS + "ariadne/policy_carbon.png",
379379
investment_energy_supply = RESULTS + "ariadne/investment_energy_supply.png",
380380
elec_val_2020 = RESULTS + "ariadne/elec_val_2020.png",
381+
trade = RESULTS + "ariadne/trade.png",
381382
script:
382383
"scripts/plot_ariadne_variables.py"
383384

workflow/scripts/export_ariadne_variables.py

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import os
88
import re
9+
import sys
910

1011
paths = ["workflow/submodules/pypsa-eur/scripts", "../submodules/pypsa-eur/scripts"]
1112
for path in paths:
@@ -2971,6 +2972,74 @@ def get_policy(n):
29712972

29722973
var["Price|Carbon"] = \
29732974
-n.global_constraints.loc["CO2Limit", "mu"] - n.global_constraints.loc["co2_limit-DE", "mu"]
2975+
2976+
var["Price|Carbon|EU-wide Regulation All Sectors"] = \
2977+
-n.global_constraints.loc["CO2Limit", "mu"]
2978+
2979+
# Price|Carbon|EU-wide Regulation Non-ETS
2980+
2981+
var["Price|Carbon|National Climate Target"] = \
2982+
-n.global_constraints.loc["co2_limit-DE", "mu"]
2983+
2984+
# Price|Carbon|National Climate Target Non-ETS
2985+
2986+
return var
2987+
2988+
def get_trade(n, region):
2989+
var = pd.Series()
2990+
2991+
def get_net_export_links(n, region, carriers):
2992+
exporting = n.links.index[
2993+
(n.links.carrier.isin(carriers)) &
2994+
(n.links.bus0.str[:2] == region) &
2995+
(n.links.bus1.str[:2] != region)]
2996+
exporting_p = n.links_t.p0.loc[: , exporting].multiply(n.snapshot_weightings.generators, axis=0).values.sum()
2997+
2998+
importing = n.links.index[
2999+
(n.links.carrier.isin(carriers)) &
3000+
(n.links.bus0.str[:2] != region) &
3001+
(n.links.bus1.str[:2] == region)]
3002+
importing_p = n.links_t.p0.loc[: , importing].multiply(n.snapshot_weightings.generators, axis=0).values.sum()
3003+
3004+
return (exporting_p - importing_p) * MWh2PJ
3005+
3006+
# Trade|Primary Energy|Biomass|Volume
3007+
# Trade|Secondary Energy|Electricity|Volume
3008+
exporting_ac = n.lines.index[
3009+
(n.lines.carrier == "AC") &
3010+
(n.lines.bus0.str[:2] == region) &
3011+
(n.lines.bus1.str[:2] != region)]
3012+
exporting_p_ac = n.lines_t.p0.loc[: , exporting_ac].multiply(n.snapshot_weightings.generators, axis=0).values.sum()
3013+
3014+
importing_ac = n.lines.index[
3015+
(n.lines.carrier == "AC") &
3016+
(n.lines.bus0.str[:2] != region) &
3017+
(n.lines.bus1.str[:2] == region)]
3018+
importing_p_ac = n.lines_t.p0.loc[: , importing_ac].multiply(n.snapshot_weightings.generators, axis=0).values.sum()
3019+
3020+
var["Trade|Secondary Energy|Electricity|Volume"] = \
3021+
((exporting_p_ac - importing_p_ac) * MWh2PJ + get_net_export_links(n, region, ["DC"]))
3022+
3023+
# Trade|Secondary Energy|Hydrogen|Volume
3024+
h2_carriers = ["H2 pipeline", "H2 pipeline (Kernnetz)", "H2 pipeline retrofitted"]
3025+
var["Trade|Secondary Energy|Hydrogen|Volume"] = \
3026+
get_net_export_links(n, region, h2_carriers)
3027+
3028+
# Trade|Secondary Energy|Liquids|Hydrogen|Volume
3029+
var["Trade|Secondary Energy|Liquids|Hydrogen|Volume"] = \
3030+
get_net_export_links(n, "DE", ["renewable oil"])
3031+
3032+
# Trade|Secondary Energy|Gases|Hydrogen|Volume
3033+
# Trade|Primary Energy|Coal|Volume
3034+
# Trade|Primary Energy|Gas|Volume
3035+
kwargs = {
3036+
'groupby': n.statistics.groupers.get_name_bus_and_carrier,
3037+
'nice_names': False,
3038+
}
3039+
var["Trade|Primary Energy|Gas|Volume"] = \
3040+
get_net_export_links(n, region, ["gas pipeline", "gas pipeline new"]) * _get_gas_fossil_fraction(n, region, kwargs)
3041+
3042+
# Trade|Primary Energy|Oil|Volume
29743043

29753044
return var
29763045

@@ -3016,6 +3085,7 @@ def get_ariadne_var(n, industry_demand, energy_totals, costs, region, year):
30163085
length_factor=snakemake.params.length_factor
30173086
),
30183087
get_policy(n),
3088+
get_trade(n, region),
30193089
])
30203090

30213091
return var
@@ -3108,6 +3178,7 @@ def get_data(
31083178
networks = [pypsa.Network(n) for n in snakemake.input.networks]
31093179

31103180
if "debug" == "debug":# For debugging
3181+
var = pd.Series()
31113182
n = networks[2]
31123183
c = costs[2]
31133184
region="DE"
@@ -3166,4 +3237,3 @@ def get_data(
31663237
with pd.ExcelWriter(snakemake.output.exported_variables) as writer:
31673238
df.to_excel(writer, sheet_name="data", index=False)
31683239
meta.to_frame().T.to_excel(writer, sheet_name="meta", index=False)
3169-

workflow/scripts/plot_ariadne_variables.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def elec_val_plot(df, savepath):
224224
"Detailed Primary Energy in PJ_yr",
225225
savepath=snakemake.output.primary_energy_detailed,
226226
select_regex="Primary Energy\|[^|]*\|[^|]*$",
227-
drop_regex="^(?!.*(CCS|Price)).+"
227+
drop_regex="^(?!.*(CCS|Price|Volume)).+"
228228
)
229229

230230
side_by_side_plot(
@@ -245,7 +245,7 @@ def elec_val_plot(df, savepath):
245245
# Secondary Energy|Something|Something (exactly two pipes)
246246
select_regex="Secondary Energy\|[^|]*\|[^|]*$",
247247
# Not ending in Fossil or Renewables (i.e., categories)
248-
drop_regex="^(?!.*(Fossil|Renewables|Losses|Price)).+"
248+
drop_regex= "^(?!.*(Fossil|Renewables|Losses|Price|Volume)).+"
249249
)
250250

251251
side_by_side_plot(
@@ -388,3 +388,11 @@ def elec_val_plot(df, savepath):
388388

389389
elec_val_plot(df, savepath=snakemake.output.elec_val_2020)
390390

391+
within_plot(
392+
df[df.index.get_level_values("Variable").str.startswith('Trade')],
393+
dfremind,
394+
title = "Trade",
395+
savepath=snakemake.output.trade,
396+
unit="PJ/yr",
397+
)
398+

0 commit comments

Comments
 (0)