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>
This commit is contained in:
Micha 2024-09-08 11:46:09 +02:00 committed by GitHub
parent b32816973f
commit 9f0e46860c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View File

@ -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)

View File

@ -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]