Co-authored-by: Fabian Hofmann <hofmann@fias.uni-frankfurt.de>
This commit is contained in:
Martha Frysztacki 2021-08-26 16:00:08 +02:00 committed by GitHub
parent f30ca8a18a
commit a6d2a0a99d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -331,28 +331,22 @@ def aggregate_to_substations(n, buses_i=None):
logger.info("Aggregating buses that are no substations or have no valid offshore connection") logger.info("Aggregating buses that are no substations or have no valid offshore connection")
buses_i = list(set(n.buses.index)-set(n.generators.bus)-set(n.loads.bus)) buses_i = list(set(n.buses.index)-set(n.generators.bus)-set(n.loads.bus))
busmap = n.buses.index.to_series() weight = pd.concat({'Line': n.lines.length/n.lines.s_nom.clip(1e-3),
'Link': n.links.length/n.links.p_nom.clip(1e-3)})
index = [np.append(["Line" for c in range(len(n.lines))],
["Link" for c in range(len(n.links))]),
np.append(n.lines.index, n.links.index)]
#under_construction lines should be last choice, but weight should be < inf in case no other node is reachable, hence 1e-3
weight = pd.Series(np.append((n.lines.length/n.lines.s_nom.apply(lambda b: b if b>0 else 1e-3)).values,
(n.links.length/n.links.p_nom.apply(lambda b: b if b>0 else 1e-3)).values),
index=index)
adj = n.adjacency_matrix(branch_components=['Line', 'Link'], weights=weight) adj = n.adjacency_matrix(branch_components=['Line', 'Link'], weights=weight)
dist = dijkstra(adj, directed=False, indices=n.buses.index.get_indexer(buses_i)) bus_indexer = n.buses.index.get_indexer(buses_i)
dist[:, n.buses.index.get_indexer(buses_i)] = np.inf #bus in buses_i should not be assigned to different bus in buses_i dist = pd.DataFrame(dijkstra(adj, directed=False, indices=bus_indexer), buses_i, n.buses.index)
#restrict to same country: dist[buses_i] = np.inf # bus in buses_i should not be assigned to different bus in buses_i
for bus in buses_i:
country_buses = n.buses[~n.buses.country.isin([n.buses.loc[bus].country])].index
dist[n.buses.loc[buses_i].index.get_indexer([bus]),n.buses.index.get_indexer(country_buses)] = np.inf
assign_to = dist.argmin(axis=1) for c in n.buses.country.unique():
busmap.loc[buses_i] = n.buses.iloc[assign_to].index incountry_b = n.buses.country == c
dist.loc[incountry_b, ~incountry_b] = np.inf
busmap = n.buses.index.to_series()
busmap.loc[buses_i] = dist.idxmin(1)
clustering = get_clustering_from_busmap(n, busmap, clustering = get_clustering_from_busmap(n, busmap,
bus_strategies=dict(country=_make_consense("Bus", "country")), bus_strategies=dict(country=_make_consense("Bus", "country")),