Merge pull request #1067 from PyPSA/fix_DC_cluster_issue

fix_DC_cluster_issue
This commit is contained in:
Fabian Neumann 2024-05-19 20:19:31 +02:00 committed by GitHub
commit cf8ee69f94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -272,14 +272,15 @@ def _add_links_from_tyndp(buses, links, links_tyndp, europe_shape):
if links_tyndp.empty:
return buses, links
tree = spatial.KDTree(buses[["x", "y"]])
tree_buses = buses.query("carrier=='AC'")
tree = spatial.KDTree(tree_buses[["x", "y"]])
_, ind0 = tree.query(links_tyndp[["x1", "y1"]])
ind0_b = ind0 < len(buses)
links_tyndp.loc[ind0_b, "bus0"] = buses.index[ind0[ind0_b]]
ind0_b = ind0 < len(tree_buses)
links_tyndp.loc[ind0_b, "bus0"] = tree_buses.index[ind0[ind0_b]]
_, ind1 = tree.query(links_tyndp[["x2", "y2"]])
ind1_b = ind1 < len(buses)
links_tyndp.loc[ind1_b, "bus1"] = buses.index[ind1[ind1_b]]
ind1_b = ind1 < len(tree_buses)
links_tyndp.loc[ind1_b, "bus1"] = tree_buses.index[ind1[ind1_b]]
links_tyndp_located_b = (
links_tyndp["bus0"].notnull() & links_tyndp["bus1"].notnull()