From f99cbc331b92c3afd251f06259ff37ba45148d5f Mon Sep 17 00:00:00 2001 From: Martin Teichmann <martin.teichmann@xfel.eu> Date: Thu, 17 Mar 2022 21:47:20 +0100 Subject: [PATCH] make centroid threshold configurable --- src/toolbox_scs/detectors/hrixs.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/toolbox_scs/detectors/hrixs.py b/src/toolbox_scs/detectors/hrixs.py index 3de1a47..6282d85 100644 --- a/src/toolbox_scs/detectors/hrixs.py +++ b/src/toolbox_scs/detectors/hrixs.py @@ -197,7 +197,7 @@ def _esrf_centroid(image, threshold=THRESHOLD, curvature=(CURVE_A, CURVE_B)): return res -def _new_centroid(image, threshold=THRESHOLD, curvature=(CURVE_A, CURVE_B)): +def _new_centroid(image, threshold=THRESHOLD, std_threshold=3.5, curvature=(CURVE_A, CURVE_B)): """find the position of photons with sub-pixel precision A photon is supposed to have hit the detector if the intensity within a @@ -208,7 +208,8 @@ def _new_centroid(image, threshold=THRESHOLD, curvature=(CURVE_A, CURVE_B)): """ base = image.mean() corners = image[1:, 1:] + image[:-1, 1:] + image[1:, :-1] + image[:-1, :-1] - threshold = corners.mean() + 3.5 * corners.std() + if threshold is None: + threshold = corners.mean() + std_threshold * corners.std() middle = corners[1:-1, 1:-1] candidates = ( (middle > threshold) @@ -283,7 +284,8 @@ class hRIXS: Y_RANGE = np.s_[:] # centroid - THRESHOLD = THRESHOLD # pixel counts above which a hit candidate is assumed + THRESHOLD = None # pixel counts above which a hit candidate is assumed + STD_THRESHOLD = 3.5 # same as THRESHOLD, in standard deviations CURVE_A = CURVE_A # curvature parameters as determined elsewhere CURVE_B = CURVE_B @@ -347,6 +349,7 @@ class hRIXS: c = centroid( image.to_numpy()[self.X_RANGE, self.Y_RANGE].T, threshold=self.THRESHOLD, + std_threshold=self.STD_THRESHOLD, curvature=(self.CURVE_A, self.CURVE_B)) if not len(c): continue -- GitLab