From 67b451037031e46be910887ab11876f80b61d728 Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Thu, 19 Sep 2024 15:16:24 +0200 Subject: [PATCH 1/2] Fix industrial demand for ammonia when endogenously modelled In calculating industrial energy demand today, demand for ammonia must be resolved into just "ammonia" when endogenously modelled, or into electricity and hydrogen if not. --- rules/build_sector.smk | 1 + ...ustrial_energy_demand_per_country_today.py | 38 +++++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 4ba1f45b4..8de040ff1 100755 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -716,6 +716,7 @@ rule build_industrial_energy_demand_per_country_today: params: countries=config_provider("countries"), industry=config_provider("industry"), + ammonia=config_provider("sector", "ammonia", default=False), input: transformation_output_coke=resources("transformation_output_coke.csv"), jrc="data/jrc-idees-2021", diff --git a/scripts/build_industrial_energy_demand_per_country_today.py b/scripts/build_industrial_energy_demand_per_country_today.py index ef559efa2..5ff91351c 100644 --- a/scripts/build_industrial_energy_demand_per_country_today.py +++ b/scripts/build_industrial_energy_demand_per_country_today.py @@ -133,6 +133,9 @@ def get_subsector_data(sheet): df["hydrogen"] = 0.0 + if snakemake.params.ammonia: + df["ammonia"] = 0.0 + df["other"] = df["all"] - df.loc[df.index != "all"].sum() return df @@ -153,14 +156,6 @@ def get_subsector_data(sheet): def separate_basic_chemicals(demand, production): - - ammonia = pd.DataFrame( - { - "hydrogen": production["Ammonia"] * params["MWh_H2_per_tNH3_electrolysis"], - "electricity": production["Ammonia"] - * params["MWh_elec_per_tNH3_electrolysis"], - } - ).T chlorine = pd.DataFrame( { "hydrogen": production["Chlorine"] * params["MWh_H2_per_tCl"], @@ -174,16 +169,29 @@ def separate_basic_chemicals(demand, production): } ).T - demand["Ammonia"] = ammonia.unstack().reindex(index=demand.index, fill_value=0.0) demand["Chlorine"] = chlorine.unstack().reindex(index=demand.index, fill_value=0.0) demand["Methanol"] = methanol.unstack().reindex(index=demand.index, fill_value=0.0) - demand["HVC"] = ( - demand["Basic chemicals"] - - demand["Ammonia"] - - demand["Methanol"] - - demand["Chlorine"] - ) + demand["HVC"] = demand["Basic chemicals"] - demand["Methanol"] - demand["Chlorine"] + + # Deal with ammonia separately, depending on whether it is modelled endogenously. + ammonia_exo = pd.DataFrame( + { + "hydrogen": production["Ammonia"] * params["MWh_H2_per_tNH3_electrolysis"], + "electricity": production["Ammonia"] + * params["MWh_elec_per_tNH3_electrolysis"], + } + ).T + + if snakemake.params.ammonia: + ammonia = pd.DataFrame( + {"ammonia": production["Ammonia"] * params["MWh_NH3_per_tNH3"]} + ).T + else: + ammonia = ammonia_exo + + demand["Ammonia"] = ammonia.unstack().reindex(index=demand.index, fill_value=0.0) + demand["HVC"] -= ammonia_exo.unstack().reindex(index=demand.index, fill_value=0.0) demand.drop(columns="Basic chemicals", inplace=True) From e46a3c3268b38db99fdfc264a6accb49e1086daf Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Thu, 19 Sep 2024 16:07:17 +0200 Subject: [PATCH 2/2] Add release note --- doc/release_notes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index ef265859f..18741d613 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -75,6 +75,8 @@ Upcoming Release * Resolved a problem where excluding certain countries from `countries` configuration led to clustering errors. +* Bugfix: demand for ammonia was double-counted at current/near-term planning horizons when ``sector['ammonia']`` was set to ``True``. + PyPSA-Eur 0.13.0 (13th September 2024) ======================================