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

Bug fix: simplify_network.py (simplify_links) - By adding preceding converter removal #1381

Merged
merged 5 commits into from
Oct 23, 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 @@ -78,6 +78,8 @@ Upcoming Release

* Bugfix: demand for ammonia was double-counted at current/near-term planning horizons when ``sector['ammonia']`` was set to ``True``.

* Bugfix: Bug when multiple DC links are connected to the same DC bus and the DC bus is connected to an AC bus via converter. In this case, the DC links were wrongly simplified, completely dropping the shared DC bus. Bug fixed by adding preceding converter removal. Other functionalities are not impacted.

PyPSA-Eur 0.13.0 (13th September 2024)
======================================

Expand Down
40 changes: 40 additions & 0 deletions scripts/simplify_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,44 @@ def find_closest_bus(n, x, y, tol=2000):
return None


def remove_converters(n: pypsa.Network) -> pypsa.Network:
"""
Remove all converters from the network and remap all buses that were originally connected to the
converter to the connected AC bus. Preparation step before simplifying links.

Parameters:
n (pypsa.Network): The network object.

Returns:
n (pypsa.Network): The network object with all converters removed.
"""
# Extract converters
converters = n.links.query("carrier == ''")[["bus0", "bus1"]]
converters["bus0_carrier"] = converters["bus0"].map(n.buses.carrier)
converters["bus1_carrier"] = converters["bus1"].map(n.buses.carrier)

converters["ac_bus"] = converters.apply(
lambda x: x["bus1"] if x["bus1_carrier"] == "AC" else x["bus0"], axis=1
)

converters["dc_bus"] = converters.apply(
lambda x: x["bus1"] if x["bus1_carrier"] == "DC" else x["bus0"], axis=1
)

# Dictionary for remapping
dict_dc_to_ac = dict(zip(converters["dc_bus"], converters["ac_bus"]))

# Remap all buses that were originally connected to the converter to the connected AC bus
n.links["bus0"] = n.links["bus0"].replace(dict_dc_to_ac)
n.links["bus1"] = n.links["bus1"].replace(dict_dc_to_ac)

# Remove all converters from network.links and associated dc buses from network.buses
n.links = n.links.loc[~n.links.index.isin(converters.index)]
n.buses = n.buses.loc[~n.buses.index.isin(converters["dc_bus"])]

return n


if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
Expand All @@ -391,6 +429,8 @@ def find_closest_bus(n, x, y, tol=2000):
linetype_380 = snakemake.config["lines"]["types"][380]
n, trafo_map = simplify_network_to_380(n, linetype_380)

n = remove_converters(n)

n, simplify_links_map = simplify_links(n, params.p_max_pu)

busmaps = [trafo_map, simplify_links_map]
Expand Down
Loading