From acfdc30cfa9377606f25a158c5ed811ac1a2b5e6 Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Mon, 9 Dec 2024 16:08:23 +0100 Subject: [PATCH] Override n_keep if n_best exceeds it --- pyxem/signals/polar_diffraction2d.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pyxem/signals/polar_diffraction2d.py b/pyxem/signals/polar_diffraction2d.py index e7b74b936..adffd30be 100644 --- a/pyxem/signals/polar_diffraction2d.py +++ b/pyxem/signals/polar_diffraction2d.py @@ -28,6 +28,7 @@ _mixed_matching_lib_to_polar, _get_integrated_polar_templates, _norm_rows, + _get_max_n, ) from pyxem.utils._background_subtraction import ( @@ -346,6 +347,10 @@ def get_orientation( Notes ----- + If :code:`n_best` exceeds :code:`n_keep` or :code:`frac_keep * N` for :code:`N` simulations, + then full correlation is performed on :code:`n_best` simulations instead. This ensures the + output contains :code:`n_best` simulations. + A gamma correction is often applied to the diffraction patterns. A good value to start with is the square root (gamma=0.5) of the diffraction patterns to increase the intensity of the low intensity reflections and decrease the @@ -377,6 +382,11 @@ def get_orientation( ) if normalize_templates: intensities_templates = _norm_rows(intensities_templates) + + max_n = _get_max_n(N=r_templates.shape[0], n_keep=n_keep, frac_keep=frac_keep) + if max_n < n_best: + # n_keep takes precedence over frac_keep, so this ensures we get n_best simulations in the result + n_keep = n_best orientation = self.map( _mixed_matching_lib_to_polar, integrated_templates=integrated_templates,