Skip to content

Commit

Permalink
Make possible to cluster just the interest area
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosEpia committed Apr 4, 2024
1 parent 8704ea1 commit b327cf0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions etrago/cluster/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,17 @@ def kmedoids_dijkstra_clustering(

settings = etrago.args["network_clustering"]

if n_clusters is False:
busmap = pd.Series(
range(len(buses)), index=buses.index, name="final_assignment"
)
busmap.index.name = "bus_id"
busmap = busmap.apply(str)

medoid_idx = pd.Series(busmap.index, index=busmap.values, name=0)

return busmap, medoid_idx

# n_jobs was deprecated for the function fit(). scikit-learn recommends
# to use threadpool_limits:
# https://scikit-learn.org/stable/computing/parallelism.html
Expand Down
11 changes: 10 additions & 1 deletion etrago/tools/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3013,7 +3013,16 @@ def select_elec_network(etrago, apply_on="grid_model"):
elec_network_buses = elec_network_buses[
~elec_network_buses.isin(foreign_buses.index)
]
n_clusters = settings["n_clusters_AC"] - num_neighboring_country
if settings["n_clusters_AC"] is False:
n_clusters = False
else:
n_clusters = (
settings["n_clusters_AC"] - num_neighboring_country
)
assert (
n_clusters > 1
), f"""'n_clusters_AC' must be greater than the number of foreign
countries({num_neighboring_country})"""

elec_network = network_based_on_buses(
etrago.network, elec_network_buses
Expand Down

0 comments on commit b327cf0

Please sign in to comment.