From d468ef1d934877e498f25a72153e37cd155db5f8 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Thu, 5 Oct 2023 17:15:24 +0100 Subject: [PATCH] added import export balance based on FES --- scripts/_fes_helpers.py | 19 +++++++++++++++++++ scripts/prepare_network.py | 22 +++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/scripts/_fes_helpers.py b/scripts/_fes_helpers.py index ae080a6d..099303ec 100644 --- a/scripts/_fes_helpers.py +++ b/scripts/_fes_helpers.py @@ -484,3 +484,22 @@ def get_commercial_demand(scenario, year): reference = df.loc[scenario_mapper[scenario], 2022] * 1e-3 return reference, value + + +def get_import_export_balance(scenario, year): + """Get GB trade balance with mainland Europe, Norway, Ireland through interconnectors""" + + col = string.ascii_uppercase.index("O") + + df = ( + pd.read_excel(data_file, + sheet_name="FL.15", + header=4, + index_col=0, + usecols=[col+i for i in range(31)], + ) + ).iloc[1:5] + + df.columns = range(2022, 2052) + + return df.loc[scenario_mapper[scenario], year] * 1e6 diff --git a/scripts/prepare_network.py b/scripts/prepare_network.py index d305d1c4..8e2f2bab 100755 --- a/scripts/prepare_network.py +++ b/scripts/prepare_network.py @@ -83,6 +83,7 @@ get_battery_capacity, get_industrial_demand, get_commercial_demand, + get_import_export_balance, ) from pypsa.descriptors import expand_series @@ -1159,28 +1160,31 @@ def add_batteries(n, costs=None, opts=[]): ) -def add_import_export_balance(n): - - n.add( - "Bus", - "import export tracker", - carrier="import export tracker", - ) +def add_import_export_balance(n, fes, year): cc = pd.read_csv(snakemake.input["capacity_constraints"], index_col=1) total_p_nom = cc.at["DC", "value"] max_hours = snakemake.config["flexibility"]["balance_link_max_hours"] + balance = get_import_export_balance(fes, year) + e_nom = abs(balance) + e_max_pu = pd.Series(1., n.snapshots) e_max_pu.iloc[0] = 0. - e_max_pu.iloc[-1] = 0. + e_max_pu.iloc[-1] = balance / max(max_hours * total_p_nom, e_nom) + + n.add( + "Bus", + "import export tracker", + carrier="import export tracker", + ) n.add( "Store", "import export tracker", bus="import export tracker", carrier="import export tracker", - e_nom=max_hours * total_p_nom, + e_nom=max(max_hours * total_p_nom, e_nom), e_max_pu=e_max_pu, e_min_pu=-e_max_pu, )