From 5a7d9a9f15b6275cf84c2bf143517439d96133b6 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Wed, 15 Nov 2023 22:42:16 -0500 Subject: [PATCH] Guard against an empty list. --- histomicstk/features/compute_intensity_features.py | 6 +++++- histomicstk/features/compute_morphometry_features.py | 8 ++++++-- histomicstk/features/graycomatrixext.py | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/histomicstk/features/compute_intensity_features.py b/histomicstk/features/compute_intensity_features.py index 93d9cba12..d7cd4c20e 100644 --- a/histomicstk/features/compute_intensity_features.py +++ b/histomicstk/features/compute_intensity_features.py @@ -1,4 +1,6 @@ """Compute intensity features in labeled image.""" +import warnings + import numpy as np @@ -123,7 +125,9 @@ def compute_intensity_features( # conditionally execute calculations if x in the features list def _conditional_execution(feature, func, *args, **kwargs): if feature in feature_list: - fdata.at[i, feature] = func(*args, **kwargs) + with warnings.catch_warnings(): + warnings.simplefilter('ignore', RuntimeWarning) + fdata.at[i, feature] = func(*args, **kwargs) def _return_input(x): return x diff --git a/histomicstk/features/compute_morphometry_features.py b/histomicstk/features/compute_morphometry_features.py index b286c8418..4ca8ec895 100644 --- a/histomicstk/features/compute_morphometry_features.py +++ b/histomicstk/features/compute_morphometry_features.py @@ -206,8 +206,12 @@ def boxcount(arr, k): counts.append(boxcount(Z, size)) # Fit the successive log(sizes) with log (counts) + coeffs = [0] with warnings.catch_warnings(): warnings.simplefilter('ignore', np.RankWarning) - coeffs = np.polyfit(np.log(sizes), np.log(counts), 1) - + if len(counts): + try: + coeffs = np.polyfit(np.log(sizes), np.log(counts), 1) + except TypeError: + pass return -coeffs[0] diff --git a/histomicstk/features/graycomatrixext.py b/histomicstk/features/graycomatrixext.py index 9e4a81a36..81dc4f5d4 100644 --- a/histomicstk/features/graycomatrixext.py +++ b/histomicstk/features/graycomatrixext.py @@ -209,7 +209,7 @@ def graycomatrixext(im_input, im_roi_mask=None, cur_glcm += cur_glcm.T # normalize if asked - if normed: + if normed and cur_glcm.sum(): cur_glcm /= cur_glcm.sum() glcm[:, :, i] = cur_glcm