base_network.py: connect new tyndp links only to closest AC bus

This commit is contained in:
Philipp Glaum 2024-05-17 14:46:20 +02:00
parent 27009f5060
commit ac48fdaaf4

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