From 9f0e46860c3e92d99d6527dedb8e2954b0b20cff Mon Sep 17 00:00:00 2001 From: Micha Date: Sun, 8 Sep 2024 11:46:09 +0200 Subject: [PATCH] bugfix: determine bus_carrier locally instead of overwriting n.stores (#1262) * bugfix: determine bus_carrier locally instead of overwriting n.stores * add release_note * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- doc/release_notes.rst | 2 ++ scripts/solve_network.py | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 325462ad..f8460e14 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -11,6 +11,8 @@ Release Notes .. Upcoming Release .. ================ +* bugfix: The carrier of stores was silently overwritten by their bus_carrier as a side effect when building the co2 constraints + * bugfix: The oil generator was incorrectly dropped when the config `oil_refining_emissions` was greater than zero. This was the default behaviour in 0.12.0. PyPSA-Eur 0.12.0 (30th August 2024) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index c70d4d3c..bdc10dd1 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -330,8 +330,8 @@ def add_carbon_constraint(n, snapshots): continue # stores - n.stores["carrier"] = n.stores.bus.map(n.buses.carrier) - stores = n.stores.query("carrier in @emissions.index and not e_cyclic") + bus_carrier = n.stores.bus.map(n.buses.carrier) + stores = n.stores[bus_carrier.isin(emissions.index) & ~n.stores.e_cyclic] if not stores.empty: last = n.snapshot_weightings.reset_index().groupby("period").last() last_i = last.set_index([last.index, last.timestep]).index @@ -356,8 +356,8 @@ def add_carbon_budget_constraint(n, snapshots): continue # stores - n.stores["carrier"] = n.stores.bus.map(n.buses.carrier) - stores = n.stores.query("carrier in @emissions.index and not e_cyclic") + bus_carrier = n.stores.bus.map(n.buses.carrier) + stores = n.stores[bus_carrier.isin(emissions.index) & ~n.stores.e_cyclic] if not stores.empty: last = n.snapshot_weightings.reset_index().groupby("period").last() last_i = last.set_index([last.index, last.timestep]).index @@ -1000,8 +1000,8 @@ def add_co2_atmosphere_constraint(n, snapshots): continue # stores - n.stores["carrier"] = n.stores.bus.map(n.buses.carrier) - stores = n.stores.query("carrier in @emissions.index and not e_cyclic") + bus_carrier = n.stores.bus.map(n.buses.carrier) + stores = n.stores[bus_carrier.isin(emissions.index) & ~n.stores.e_cyclic] if not stores.empty: last_i = snapshots[-1] lhs = n.model["Store-e"].loc[last_i, stores.index]