From d9b2ae4ac2bebf084430122f5e8370444a13affb Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Fri, 2 Aug 2024 12:39:45 +0200 Subject: [PATCH] use the same validation logic as in other cases --- dap/algos/thresh.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/dap/algos/thresh.py b/dap/algos/thresh.py index 1c18427..843be71 100644 --- a/dap/algos/thresh.py +++ b/dap/algos/thresh.py @@ -3,17 +3,23 @@ import numpy as np def calc_apply_threshold(results, data): apply_threshold = results.get("apply_threshold", False) + if not apply_threshold: + return + + for k in ("threshold_min", "threshold_max"): + if k not in results: + return + threshold_value_choice = results.get("threshold_value", "NaN") - threshold_value = 0 if threshold_value_choice == "0" else np.nan + threshold_value = 0 if threshold_value_choice == "0" else np.nan #TODO #TODO: this is duplicated in calc_radial_integration - if apply_threshold and all(k in results for k in ("threshold_min", "threshold_max")): - threshold_min = float(results["threshold_min"]) - threshold_max = float(results["threshold_max"]) - data[data < threshold_min] = threshold_value - #TODO: skipping max is a guess, but not obvious/symmetric -- better to ensure the order min < max by switching them if needed - if threshold_max > threshold_min: - data[data > threshold_max] = threshold_value + threshold_min = float(results["threshold_min"]) + threshold_max = float(results["threshold_max"]) + data[data < threshold_min] = threshold_value + #TODO: skipping max is a guess, but not obvious/symmetric -- better to ensure the order min < max by switching them if needed + if threshold_max > threshold_min: + data[data > threshold_max] = threshold_value