rename no_substations
This commit is contained in:
parent
c53d49d8f8
commit
d6830d3c48
@ -319,14 +319,16 @@ def remove_stubs(n):
|
|||||||
|
|
||||||
return n, busmap
|
return n, busmap
|
||||||
|
|
||||||
def aggregate_to_substations(n):
|
def aggregate_to_substations(n, buses_i=None):
|
||||||
logger.info("Aggregating buses that are no substations or have a no valid offshore connection")#
|
# can be used to aggregate a selection of buses to electrically closest neighbors
|
||||||
|
# if no buses are given, nodes that are no substations or without offshore connection are aggregated
|
||||||
|
|
||||||
|
if buses_i is None:
|
||||||
|
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))
|
||||||
|
|
||||||
busmap = n.buses.index.to_series()
|
busmap = n.buses.index.to_series()
|
||||||
|
|
||||||
no_substations = list(set(n.buses.index)-set(n.generators.bus)-set(n.loads.bus))
|
|
||||||
|
|
||||||
|
|
||||||
index = [np.append(["Line" for c in range(len(n.lines))],
|
index = [np.append(["Line" for c in range(len(n.lines))],
|
||||||
["Link" for c in range(len(n.links))]),
|
["Link" for c in range(len(n.links))]),
|
||||||
np.append(n.lines.index, n.links.index)]
|
np.append(n.lines.index, n.links.index)]
|
||||||
@ -337,16 +339,16 @@ def aggregate_to_substations(n):
|
|||||||
|
|
||||||
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(no_substations))
|
dist = dijkstra(adj, directed=False, indices=n.buses.index.get_indexer(buses_i))
|
||||||
dist[:, n.buses.index.get_indexer(no_substations)] = np.inf #no_substations should not be assigned to other no_substations
|
dist[:, n.buses.index.get_indexer(buses_i)] = np.inf #bus in buses_i should not be assigned to different bus in buses_i
|
||||||
|
|
||||||
#restrict to same country:
|
#restrict to same country:
|
||||||
for bus in no_substations:
|
for bus in buses_i:
|
||||||
country_buses = n.buses[~n.buses.country.isin([n.buses.loc[bus].country])].index
|
country_buses = n.buses[~n.buses.country.isin([n.buses.loc[bus].country])].index
|
||||||
dist[n.buses.loc[no_substations].index.get_indexer([bus]),n.buses.index.get_indexer(country_buses)] = np.inf
|
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)
|
assign_to = dist.argmin(axis=1)
|
||||||
busmap.loc[no_substations] = n.buses.iloc[assign_to].index
|
busmap.loc[buses_i] = n.buses.iloc[assign_to].index
|
||||||
|
|
||||||
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")),
|
||||||
|
Loading…
Reference in New Issue
Block a user