From 4de0c8b7d7c1ce3a132f9b77a987a71f2f5bb6b6 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Wed, 19 Nov 2025 18:48:20 +0100 Subject: [PATCH] allow vmin/vmax = None for "no limit" --- dap/algos/thresh.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/dap/algos/thresh.py b/dap/algos/thresh.py index 844b995..66ac3b1 100644 --- a/dap/algos/thresh.py +++ b/dap/algos/thresh.py @@ -6,17 +6,16 @@ def calc_apply_threshold(results, data, value=None, copy=False): if not apply_threshold: return data - for k in ("threshold_min", "threshold_max"): - if k not in results: - return data + threshold_min = results.get("threshold_min") + threshold_max = results.get("threshold_max") + + if threshold_min is None and threshold_max is None: + return data if value is None: threshold_value = results.get("threshold_value", "NaN") value = 0 if threshold_value == "0" else np.nan #TODO - threshold_min = float(results["threshold_min"]) - threshold_max = float(results["threshold_max"]) - if copy: data = data.copy() # do the following in-place changes on a copy @@ -30,10 +29,13 @@ def threshold(data, vmin, vmax, replacement): """ threshold data in place by replacing values < vmin and values > vmax with replacement """ - # if vmin > vmax, data will be overwritten entirely -- better to ensure vmin < vmax by switching them if needed - vmin, vmax = sorted((vmin, vmax)) - data[data < vmin] = replacement - data[data > vmax] = replacement + if vmin is not None and vmax is not None: + # if vmin > vmax, data will be overwritten entirely -- better to ensure vmin < vmax by switching them if needed + vmin, vmax = sorted((vmin, vmax)) + if vmin is not None: + data[data < vmin] = replacement + if vmax is not None: + data[data > vmax] = replacement