Compare commits

...

4 Commits

Author SHA1 Message Date
28f7248500 de-duplicated calc_apply_threshold 2025-10-31 18:38:58 +01:00
603f9215e8 added replacement value as argument 2025-10-31 18:35:11 +01:00
36c61c7b8e added boolean copy switch 2025-10-31 18:32:07 +01:00
32adb370cd order 2025-10-31 18:20:51 +01:00
3 changed files with 16 additions and 49 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
data = data.copy() # do the following in-place changes on a copy
threshold_min = float(results["threshold_min"])
threshold_max = float(results["threshold_max"])
threshold(data, threshold_min, threshold_max, np.nan)
return data

View File

@@ -1,23 +1,28 @@
import numpy as np
#TODO: this is duplicated in calc_radial_integration and calc_apply_aggregation
def calc_apply_threshold(results, data):
def calc_apply_threshold(results, data, value=None, copy=False):
apply_threshold = results.get("apply_threshold", False)
if not apply_threshold:
return
return data
for k in ("threshold_min", "threshold_max"):
if k not in results:
return
return data
threshold_value_choice = results.get("threshold_value", "NaN")
threshold_value = 0 if threshold_value_choice == "0" else np.nan #TODO
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"])
threshold(data, threshold_min, threshold_max, threshold_value)
if copy:
data = data.copy() # do the following in-place changes on a copy
threshold(data, threshold_min, threshold_max, value)
return data