From 0c1b7ce3ab38d2479aa839dbd7699d9dff29901e Mon Sep 17 00:00:00 2001 From: Dylan Kennedy Date: Tue, 19 May 2026 03:34:07 -0700 Subject: [PATCH 1/2] Add minimum beam size check for fit validation. --- lcls_tools/common/image/fit.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lcls_tools/common/image/fit.py b/lcls_tools/common/image/fit.py index 225eea8f..c6e3b353 100644 --- a/lcls_tools/common/image/fit.py +++ b/lcls_tools/common/image/fit.py @@ -79,6 +79,9 @@ class ImageProjectionFit(ImageFit): Fit amplitude to noise threshold for the fit. If the amplitude of the fit is below this threshold times the noise standard deviation and `validate_fit` is True, the fit parameters will be set to NaN. + min_beam_size: PositiveFloat + Minimum beam size in pixels for the fit. If the beam size of the fit is below this threshold, + and 'validate_fit' is True, the fit parameters will be set to NaN. beam_extent_n_stds : PositiveFloat Number of standard deviations on either side to use for the beam extent. If the beam extent is outside the image and `validate_fit` is True, the fit parameters will be set to NaN. @@ -94,6 +97,9 @@ class ImageProjectionFit(ImageFit): signal_to_noise_threshold: PositiveFloat = Field( 2.0, description="Fit amplitude to noise threshold for the fit" ) + min_beam_size: PositiveFloat = Field( + 1.0, description="Minimum beam size in pixels to accept for validation" + ) beam_extent_n_stds: PositiveFloat = Field( 2.0, description="Number of standard deviations on either side to use for the beam extent", @@ -164,3 +170,13 @@ def _validate_parameters( warnings.warn( f"Projection in {dim} was off the screen, fit cannot be trusted" ) + + # if the beam size is smaller than the specified minimum number of pixels, fits cannot be trusted + if self.min_beam_size is not None: + if parameters["sigma"] < self.min_beam_size: + for name in parameters.keys(): + parameters[name] = np.nan + + warnings.warn( + f"Projection in {dim} had too small a beam size, fit cannot be trusted" + ) From e6663643b34dc43be83171eb64ae7031fba0705c Mon Sep 17 00:00:00 2001 From: Dylan Kennedy Date: Tue, 19 May 2026 03:44:50 -0700 Subject: [PATCH 2/2] Black formatting. --- lcls_tools/common/image/fit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lcls_tools/common/image/fit.py b/lcls_tools/common/image/fit.py index c6e3b353..dc70e5f8 100644 --- a/lcls_tools/common/image/fit.py +++ b/lcls_tools/common/image/fit.py @@ -171,7 +171,7 @@ def _validate_parameters( f"Projection in {dim} was off the screen, fit cannot be trusted" ) - # if the beam size is smaller than the specified minimum number of pixels, fits cannot be trusted + # if the beam size is smaller than the specified minimum number of pixels, fits cannot be trusted if self.min_beam_size is not None: if parameters["sigma"] < self.min_beam_size: for name in parameters.keys():