diff --git a/etrago/cluster/spatial.py b/etrago/cluster/spatial.py index 45ca52f0..57d483e7 100755 --- a/etrago/cluster/spatial.py +++ b/etrago/cluster/spatial.py @@ -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 diff --git a/etrago/tools/utilities.py b/etrago/tools/utilities.py index 47c9b3a1..d7b995b3 100755 --- a/etrago/tools/utilities.py +++ b/etrago/tools/utilities.py @@ -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