moved thresholding out of work function

This commit is contained in:
2024-08-02 12:14:27 +02:00
parent 53d2d965d9
commit a690654343
3 changed files with 20 additions and 10 deletions

View File

@ -4,5 +4,6 @@ from .peakfind import calc_peakfinder_analysis
from .radprof import calc_radial_integration
from .roi import calc_roi
from .spiana import calc_spi_analysis
from .thresh import calc_apply_threshold

17
dap/algos/thresh.py Normal file
View File

@ -0,0 +1,17 @@
import numpy as np
def calc_apply_threshold(results, pfdata):
apply_threshold = results.get("apply_threshold", False)
threshold_value_choice = results.get("threshold_value", "NaN")
threshold_value = 0 if threshold_value_choice == "0" else np.nan
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"])
pfdata[pfdata < threshold_min] = threshold_value
if threshold_max > threshold_min:
pfdata[pfdata > threshold_max] = threshold_value
return threshold_value_choice

View File

@ -7,7 +7,7 @@ from time import sleep
import jungfrau_utils as ju
import numpy as np
from algos import calc_apply_additional_mask, calc_peakfinder_analysis, calc_radial_integration, calc_roi, calc_spi_analysis
from algos import calc_apply_additional_mask, calc_apply_threshold, calc_peakfinder_analysis, calc_radial_integration, calc_roi, calc_spi_analysis
from utils import json_load, read_bit
from zmqsocks import ZMQSockets
@ -184,15 +184,7 @@ def work(backend_address, accumulator_host, accumulator_port, visualisation_host
if pixel_mask_pf is not None:
pfdata[pixel_mask_pf != 1] = np.nan
apply_threshold = results.get("apply_threshold", False)
threshold_value_choice = results.get("threshold_value", "NaN")
threshold_value = 0 if threshold_value_choice == "0" else np.nan
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"])
pfdata[pfdata < threshold_min] = threshold_value
if threshold_max > threshold_min:
pfdata[pfdata > threshold_max] = threshold_value
threshold_value_choice = calc_apply_threshold(results, pfdata)
calc_roi(results, pfdata, pixel_mask_pf, threshold_value_choice)
calc_spi_analysis(results)