From 5f055c8718b3adb116ab9c5c67094255d16b5ae0 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Fri, 9 Aug 2024 15:54:54 +0200 Subject: [PATCH] flatten the code; early exit --- dap/algos/radprof.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/dap/algos/radprof.py b/dap/algos/radprof.py index a083cd4..e1d877d 100644 --- a/dap/algos/radprof.py +++ b/dap/algos/radprof.py @@ -64,16 +64,21 @@ def radial_profile(data, rad, norm, keep_pixels): 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 #TODO: this is duplicated in calc_apply_threshold and calc_force_send - 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.copy() # do the following in-place changes on a copy - data[data < threshold_min] = np.nan - #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] = np.nan + threshold_min = float(results["threshold_min"]) + threshold_max = float(results["threshold_max"]) + data = data.copy() # do the following in-place changes on a copy + data[data < threshold_min] = np.nan + #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] = np.nan return data