Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix industrial demand for ammonia when endogenously modelled #1312

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading