Skip to content

Commit

Permalink
Guard against an empty list.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Nov 16, 2023
1 parent ff9c05d commit 5a7d9a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion histomicstk/features/compute_intensity_features.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Compute intensity features in labeled image."""
import warnings

import numpy as np


Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions histomicstk/features/compute_morphometry_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 216 in histomicstk/features/compute_morphometry_features.py

View check run for this annotation

Codecov / codecov/patch

histomicstk/features/compute_morphometry_features.py#L215-L216

Added lines #L215 - L216 were not covered by tests
return -coeffs[0]
2 changes: 1 addition & 1 deletion histomicstk/features/graycomatrixext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5a7d9a9

Please sign in to comment.