Skip to content

Commit

Permalink
Fix industrial demand for ammonia when endogenously modelled (#1312)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
koen-vg authored Sep 20, 2024
1 parent 38f2dc7 commit 81da685
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
2 changes: 2 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
======================================

Expand Down
1 change: 1 addition & 0 deletions rules/build_sector.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 23 additions & 15 deletions scripts/build_industrial_energy_demand_per_country_today.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"],
Expand All @@ -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)

Expand Down

0 comments on commit 81da685

Please sign in to comment.