From 0f9ab014ce99ef3d253732a444514a040b2faa43 Mon Sep 17 00:00:00 2001 From: Sarniak Date: Wed, 4 Jun 2025 13:59:16 +0200 Subject: [PATCH] Fix for normalize function in thresh_utility.py --- CHANGES.txt | 1 + pythresh/thresholds/thresh_utility.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index cba8e11..28ebf86 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -96,3 +96,4 @@ v<1.0.0>, <01/27/2024> -- Updated all thresholder tests v<1.0.0>, <01/27/2024> -- Updated all thresholder examples v<1.0.0>, <01/27/2024> -- Updated docs with shift to V1 v<1.0.0>, <01/27/2024> -- Updated docs with datatables +v<1.0.0>, <06/04/2025> -- Fix for normalize function in thresh_utility.py diff --git a/pythresh/thresholds/thresh_utility.py b/pythresh/thresholds/thresh_utility.py index a3a2304..0813963 100644 --- a/pythresh/thresholds/thresh_utility.py +++ b/pythresh/thresholds/thresh_utility.py @@ -19,9 +19,13 @@ def normalize(data, min_val=None, max_val=None): if min_val is None or max_val is None: min_val, max_val = get_min_max(data) - # Adjust test data to be 0 or greater to avoid method failures normed = (data - min_val) / (max_val - min_val) + + # Ensure normalization is within [0, 1]. + if np.isscalar(normed): + normed = np.array([normed]) normed[normed < 0] = 0 + normed[normed > 1] = 1 return normed