diff --git a/dap/algos/forcesend.py b/dap/algos/forcesend.py index 63ea339..f1f205d 100644 --- a/dap/algos/forcesend.py +++ b/dap/algos/forcesend.py @@ -1,6 +1,7 @@ import numpy as np from .mask import calc_mask_pixels +from .thresh import threshold def calc_force_send(results, data, pixel_mask_pf, image, data_summed, n_aggregated_images): @@ -42,10 +43,9 @@ def calc_apply_threshold(results, data): threshold_min = float(results["threshold_min"]) threshold_max = float(results["threshold_max"]) - data[data < threshold_min] = 0 - #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] = 0 + + threshold(data, threshold_min, threshold_max, 0) + def calc_apply_aggregation(results, data, data_summed, n_aggregated_images): diff --git a/dap/algos/radprof.py b/dap/algos/radprof.py index 8dbc92e..42bc268 100644 --- a/dap/algos/radprof.py +++ b/dap/algos/radprof.py @@ -1,5 +1,6 @@ import numpy as np +from .thresh import threshold from .utils import npmemo @@ -76,10 +77,8 @@ def calc_apply_threshold(results, data): threshold_min = float(results["threshold_min"]) threshold_max = float(results["threshold_max"]) - 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(data, threshold_min, threshold_max, np.nan) return data diff --git a/dap/algos/thresh.py b/dap/algos/thresh.py index 075e8e7..4cd2ac4 100644 --- a/dap/algos/thresh.py +++ b/dap/algos/thresh.py @@ -16,10 +16,19 @@ def calc_apply_threshold(results, data): threshold_min = float(results["threshold_min"]) threshold_max = float(results["threshold_max"]) - data[data < threshold_min] = threshold_value + + threshold(data, threshold_min, threshold_max, threshold_value) + + + +def threshold(data, vmin, vmax, replacement): + """ + threshold data in place by replacing values < vmin and values > vmax with replacement + """ + data[data < vmin] = replacement #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 + if vmax > vmin: + data[data > vmin] = replacement