|
6 | 6 | import numpy as np |
7 | 7 | import os |
8 | 8 | import re |
| 9 | +import sys |
9 | 10 |
|
10 | 11 | paths = ["workflow/submodules/pypsa-eur/scripts", "../submodules/pypsa-eur/scripts"] |
11 | 12 | for path in paths: |
@@ -2971,6 +2972,74 @@ def get_policy(n): |
2971 | 2972 |
|
2972 | 2973 | var["Price|Carbon"] = \ |
2973 | 2974 | -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 |
2974 | 3043 |
|
2975 | 3044 | return var |
2976 | 3045 |
|
@@ -3016,6 +3085,7 @@ def get_ariadne_var(n, industry_demand, energy_totals, costs, region, year): |
3016 | 3085 | length_factor=snakemake.params.length_factor |
3017 | 3086 | ), |
3018 | 3087 | get_policy(n), |
| 3088 | + get_trade(n, region), |
3019 | 3089 | ]) |
3020 | 3090 |
|
3021 | 3091 | return var |
@@ -3108,6 +3178,7 @@ def get_data( |
3108 | 3178 | networks = [pypsa.Network(n) for n in snakemake.input.networks] |
3109 | 3179 |
|
3110 | 3180 | if "debug" == "debug":# For debugging |
| 3181 | + var = pd.Series() |
3111 | 3182 | n = networks[2] |
3112 | 3183 | c = costs[2] |
3113 | 3184 | region="DE" |
@@ -3166,4 +3237,3 @@ def get_data( |
3166 | 3237 | with pd.ExcelWriter(snakemake.output.exported_variables) as writer: |
3167 | 3238 | df.to_excel(writer, sheet_name="data", index=False) |
3168 | 3239 | meta.to_frame().T.to_excel(writer, sheet_name="meta", index=False) |
3169 | | - |
|
0 commit comments