allow vmin/vmax = None as "no limit"

This commit is contained in:
2025-11-19 18:48:20 +01:00
parent ee79ee98a0
commit 3bbc317f6f

View File

@@ -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