From becca8e5c16df32be9c3db732fe45dfc1e796302 Mon Sep 17 00:00:00 2001 From: CarlosEpia Date: Thu, 29 Jun 2023 10:59:28 +0200 Subject: [PATCH] save k-medoids clustering busmap --- etrago/appl.py | 2 +- etrago/cluster/spatial.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/etrago/appl.py b/etrago/appl.py index 35e12edf..ed288aac 100644 --- a/etrago/appl.py +++ b/etrago/appl.py @@ -704,7 +704,7 @@ def run_etrago(args, json_path): print(datetime.datetime.now()) - spatial_resolution = [20, 300, 30, 40, 50, 100, 150, 200, 250, 400, 500, 600] + spatial_resolution = [50, 100, 300, 500] spatial_method = ['kmedoids-dijkstra'] diff --git a/etrago/cluster/spatial.py b/etrago/cluster/spatial.py index ef7d2262..4dc198c1 100755 --- a/etrago/cluster/spatial.py +++ b/etrago/cluster/spatial.py @@ -698,6 +698,10 @@ def kmedoids_dijkstra_clustering(etrago, buses, connections, weight, n_clusters) distances = distances.apply(pd.to_numeric) medoid_idx = distances.idxmin() + if n_clusters > 5: + busmap_medoid = busmap.map(medoid_idx) + medoids_n = etrago.args["network_clustering"]["n_clusters_AC"] + busmap_medoid.to_csv(f'relocated_clus/busmap_medoid_{medoids_n}.csv') import datetime print(' ') @@ -716,6 +720,13 @@ def kmedoids_dijkstra_clustering(etrago, buses, connections, weight, n_clusters) busmap.index.name = "bus_id" + + if n_clusters > 5: + medoid_idx_copy = medoid_idx.copy() + medoid_idx_copy.index = medoid_idx_copy.index.map(str) + busmap_dijkstra = busmap.map(medoid_idx_copy) + medoids_n = etrago.args["network_clustering"]["n_clusters_AC"] + busmap_dijkstra.to_csv(f'relocated_clus/busmap_dijkstra_{medoids_n}.csv') else: df = pd.read_csv(settings["k_busmap"])