de-duplicated calc_apply_threshold

This commit is contained in:
2025-10-31 18:38:58 +01:00
parent 603f9215e8
commit 28f7248500
3 changed files with 4 additions and 43 deletions

View File

@@ -1,5 +1,5 @@
from .mask import calc_mask_pixels
from .thresh import threshold
from .thresh import calc_apply_threshold
def calc_apply_aggregation(results, data, pixel_mask, aggregator):
@@ -7,7 +7,7 @@ def calc_apply_aggregation(results, data, pixel_mask, aggregator):
if aggregator.is_ready():
aggregator.reset()
calc_apply_threshold(results, data) # changes data in place
calc_apply_threshold(results, data, value=0) # changes data in place
data = calc_aggregate(results, data, aggregator)
calc_mask_pixels(data, pixel_mask) # changes data in place
@@ -18,23 +18,6 @@ def calc_apply_aggregation(results, data, pixel_mask, aggregator):
#TODO: this is duplicated in calc_apply_threshold and calc_radial_integration
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_min = float(results["threshold_min"])
threshold_max = float(results["threshold_max"])
threshold(data, threshold_min, threshold_max, 0)
def calc_aggregate(results, data, aggregator):
apply_aggregation = results.get("apply_aggregation", False)
if not apply_aggregation:

View File

@@ -1,6 +1,6 @@
import numpy as np
from .thresh import threshold
from .thresh import calc_apply_threshold
from .utils import npmemo
@@ -17,7 +17,7 @@ def calc_radial_integration(results, data, pixel_mask):
r_min = min(rad)
r_max = max(rad) + 1
data = calc_apply_threshold(results, data)
data = calc_apply_threshold(results, data, value=np.nan, copy=True)
rp = radial_profile(data, rad, norm, pixel_mask)
@@ -59,24 +59,3 @@ def radial_profile(data, rad, norm, keep_pixels):
#TODO: this is duplicated in calc_apply_threshold and calc_apply_aggregation
def calc_apply_threshold(results, data):
apply_threshold = results.get("apply_threshold", False)
if not apply_threshold:
return data
for k in ("threshold_min", "threshold_max"):
if k not in results:
return data
threshold_min = float(results["threshold_min"])
threshold_max = float(results["threshold_max"])
data = data.copy() # do the following in-place changes on a copy
threshold(data, threshold_min, threshold_max, np.nan)
return data

View File

@@ -1,7 +1,6 @@
import numpy as np
#TODO: this is duplicated in calc_radial_integration and calc_apply_aggregation
def calc_apply_threshold(results, data, value=None, copy=False):
apply_threshold = results.get("apply_threshold", False)
if not apply_threshold: