From d3b1ddd2b8924bc99e8b7203b42cff792596cebd Mon Sep 17 00:00:00 2001 From: kapoorlab Date: Fri, 3 Nov 2023 18:25:43 +0100 Subject: [PATCH] handle empty clusters --- src/napatrackmater/Trackvector.py | 9 +++++++++ src/napatrackmater/_version.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/napatrackmater/Trackvector.py b/src/napatrackmater/Trackvector.py index 5ae503bf..c513a3d4 100644 --- a/src/napatrackmater/Trackvector.py +++ b/src/napatrackmater/Trackvector.py @@ -907,6 +907,15 @@ def unsupervised_clustering( track_arrays_array.index(track_arrays) ] shape_dynamic_cosine_distance = pdist(clusterable_track_array, metric=metric) + if ( + np.isnan(shape_dynamic_cosine_distance).any() + or np.isinf(shape_dynamic_cosine_distance).any() + ): + print( + "Cosine distance matrix contains NaN or infinite values. Returning an empty linkage matrix." + ) + return + shape_dynamic_linkage_matrix = linkage( shape_dynamic_cosine_distance, method=method ) diff --git a/src/napatrackmater/_version.py b/src/napatrackmater/_version.py index d71742ca..17532934 100644 --- a/src/napatrackmater/_version.py +++ b/src/napatrackmater/_version.py @@ -1,2 +1,2 @@ -__version__ = version = "4.4.1" -__version_tuple__ = version_tuple = (4, 4, 1) +__version__ = version = "4.4.2" +__version_tuple__ = version_tuple = (4, 4, 2)