moved radial_integration algo out of work function
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
from .radprof import prepare_radial_profile, radial_profile
|
from .radprof import calc_radial_integration
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,52 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
def calc_radial_integration(results, data, keep_pixels, pixel_mask_pf, center_radial_integration, r_radial_integration):
|
||||||
|
data_copy_1 = np.copy(data)
|
||||||
|
|
||||||
|
if keep_pixels is None and pixel_mask_pf is not None:
|
||||||
|
keep_pixels = (pixel_mask_pf != 0)
|
||||||
|
if center_radial_integration is None:
|
||||||
|
center_radial_integration = [results["beam_center_x"], results["beam_center_y"]]
|
||||||
|
r_radial_integration = None
|
||||||
|
if r_radial_integration is None:
|
||||||
|
r_radial_integration, nr_radial_integration = prepare_radial_profile(data_copy_1, center_radial_integration, keep_pixels)
|
||||||
|
r_min_max = [int(np.min(r_radial_integration)), int(np.max(r_radial_integration)) + 1]
|
||||||
|
|
||||||
|
|
||||||
|
apply_threshold = results.get("apply_threshold", False)
|
||||||
|
|
||||||
|
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_copy_1[data_copy_1 < threshold_min] = np.nan
|
||||||
|
if threshold_max > threshold_min:
|
||||||
|
data_copy_1[data_copy_1 > threshold_max] = np.nan
|
||||||
|
|
||||||
|
rp = radial_profile(data_copy_1, r_radial_integration, nr_radial_integration, keep_pixels)
|
||||||
|
|
||||||
|
silent_region_min = results.get("radial_integration_silent_min", None)
|
||||||
|
silent_region_max = results.get("radial_integration_silent_max", None)
|
||||||
|
|
||||||
|
if (
|
||||||
|
silent_region_min is not None and
|
||||||
|
silent_region_max is not None and
|
||||||
|
silent_region_max > silent_region_min and
|
||||||
|
silent_region_min > r_min_max[0] and
|
||||||
|
silent_region_max < r_min_max[1]
|
||||||
|
):
|
||||||
|
|
||||||
|
integral_silent_region = np.sum(rp[silent_region_min:silent_region_max])
|
||||||
|
rp = rp / integral_silent_region
|
||||||
|
results["radint_normalised"] = [silent_region_min, silent_region_max]
|
||||||
|
|
||||||
|
results["radint_I"] = list(rp[r_min_max[0]:])
|
||||||
|
results["radint_q"] = r_min_max
|
||||||
|
|
||||||
|
return keep_pixels, center_radial_integration, r_radial_integration
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def radial_profile(data, r, nr, keep_pixels=None):
|
def radial_profile(data, r, nr, keep_pixels=None):
|
||||||
if keep_pixels is not None:
|
if keep_pixels is not None:
|
||||||
tbin = np.bincount(r, data[keep_pixels].ravel())
|
tbin = np.bincount(r, data[keep_pixels].ravel())
|
||||||
|
@ -10,7 +10,7 @@ import numpy as np
|
|||||||
import zmq
|
import zmq
|
||||||
from peakfinder8_extension import peakfinder_8
|
from peakfinder8_extension import peakfinder_8
|
||||||
|
|
||||||
from algos import prepare_radial_profile, radial_profile
|
from algos import calc_radial_integration
|
||||||
|
|
||||||
|
|
||||||
FLAGS = 0
|
FLAGS = 0
|
||||||
@ -250,51 +250,12 @@ def work(backend_address, accumulator_host, accumulator_port, visualisation_host
|
|||||||
results["saturated_pixels_x"] = saturated_pixels_coordinates[1].tolist()
|
results["saturated_pixels_x"] = saturated_pixels_coordinates[1].tolist()
|
||||||
results["saturated_pixels_y"] = saturated_pixels_coordinates[0].tolist()
|
results["saturated_pixels_y"] = saturated_pixels_coordinates[0].tolist()
|
||||||
|
|
||||||
|
|
||||||
# pump probe analysis
|
# pump probe analysis
|
||||||
do_radial_integration = results.get("do_radial_integration", False)
|
do_radial_integration = results.get("do_radial_integration", False)
|
||||||
|
|
||||||
if do_radial_integration:
|
if do_radial_integration:
|
||||||
|
keep_pixels, center_radial_integration, r_radial_integration = calc_radial_integration(results, data, keep_pixels, pixel_mask_pf, center_radial_integration, r_radial_integration)
|
||||||
|
|
||||||
data_copy_1 = np.copy(data)
|
|
||||||
|
|
||||||
if keep_pixels is None and pixel_mask_pf is not None:
|
|
||||||
keep_pixels = pixel_mask_pf!=0
|
|
||||||
if center_radial_integration is None:
|
|
||||||
center_radial_integration = [results["beam_center_x"], results["beam_center_y"]]
|
|
||||||
r_radial_integration = None
|
|
||||||
if r_radial_integration is None:
|
|
||||||
r_radial_integration, nr_radial_integration = prepare_radial_profile(data_copy_1, center_radial_integration, keep_pixels)
|
|
||||||
r_min_max = [int(np.min(r_radial_integration)), int(np.max(r_radial_integration)) + 1]
|
|
||||||
|
|
||||||
|
|
||||||
apply_threshold = results.get("apply_threshold", False)
|
|
||||||
|
|
||||||
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_copy_1[data_copy_1 < threshold_min] = np.nan
|
|
||||||
if threshold_max > threshold_min:
|
|
||||||
data_copy_1[data_copy_1 > threshold_max] = np.nan
|
|
||||||
|
|
||||||
rp = radial_profile(data_copy_1, r_radial_integration, nr_radial_integration, keep_pixels)
|
|
||||||
|
|
||||||
silent_region_min = results.get("radial_integration_silent_min", None)
|
|
||||||
silent_region_max = results.get("radial_integration_silent_max", None)
|
|
||||||
|
|
||||||
if (
|
|
||||||
silent_region_min is not None and
|
|
||||||
silent_region_max is not None and
|
|
||||||
silent_region_max > silent_region_min and
|
|
||||||
silent_region_min > r_min_max[0] and
|
|
||||||
silent_region_max < r_min_max[1]
|
|
||||||
):
|
|
||||||
|
|
||||||
integral_silent_region = np.sum(rp[silent_region_min:silent_region_max])
|
|
||||||
rp = rp / integral_silent_region
|
|
||||||
results["radint_normalised"] = [silent_region_min, silent_region_max]
|
|
||||||
|
|
||||||
results["radint_I"] = list(rp[r_min_max[0]:])
|
|
||||||
results["radint_q"] = r_min_max
|
|
||||||
|
|
||||||
#copy image to work with peakfinder, just in case
|
#copy image to work with peakfinder, just in case
|
||||||
d = np.copy(data)
|
d = np.copy(data)
|
||||||
|
Reference in New Issue
Block a user