From 81da6859ee691a7a80cd9309a23eaa740fb661c0 Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek <74298901+koen-vg@users.noreply.github.com> Date: Fri, 20 Sep 2024 08:54:19 +0200 Subject: [PATCH] Fix industrial demand for ammonia when endogenously modelled (#1312) * 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. * Add release note --- doc/release_notes.rst | 2 + rules/build_sector.smk | 1 + ...ustrial_energy_demand_per_country_today.py | 38 +++++++++++-------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index ef265859..18741d61 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) ====================================== diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 4ba1f45b..8de040ff 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 ef559efa..5ff91351 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 industrial_energy_demand_per_country(country, year, jrc_dir): 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 industrial_energy_demand_per_country(country, year, jrc_dir): 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)