From 1993ec9150d839786649414389793aa5114f2ed1 Mon Sep 17 00:00:00 2001 From: Kay-Robert Dormann Date: Fri, 1 Nov 2024 12:36:10 +0100 Subject: [PATCH 1/2] WIP: single clusters added to cluster.identify --- amep/cluster.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/amep/cluster.py b/amep/cluster.py index e4dced0..a60be2d 100644 --- a/amep/cluster.py +++ b/amep/cluster.py @@ -1036,18 +1036,18 @@ def identify( particle_idx = set(np.arange(len(coords))) clustered_idx = set() - n = 0 + cluster_id = 0 for cl in sorted_clusters: - for i in cl: - idx[i] = n + idx[i] = cluster_id clustered_idx.add(i) - - n += 1 + cluster_id += 1 # add leftover single particles for k in particle_idx - clustered_idx: - idx[k] = n - n += 1 + idx[k] = cluster_id + sorted_clusters.append([k]) + cluster_id += 1 + idx=np.array(idx, dtype=int) return sorted_clusters, idx From 92442e6f6903fbc3f05e269a3666063e235cb2bf Mon Sep 17 00:00:00 2001 From: Kay-Robert Dormann Date: Fri, 1 Nov 2024 13:49:50 +0100 Subject: [PATCH 2/2] fixes #85 --- amep/cluster.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/amep/cluster.py b/amep/cluster.py index a60be2d..2052b10 100644 --- a/amep/cluster.py +++ b/amep/cluster.py @@ -940,7 +940,8 @@ def identify( sorted_clusters : list List of lists, where each list contains the indices of the particles that belong to the same cluster. The list is sorted by the number of - particles in each cluster. + particles in each cluster. Single particles are also included as + clusters in this list. idx : numpy.ndarray Array of shape (N,) containing the cluster ID for each particle. N is the total number of particles.