diff --git a/bcdi/experiment/diffractometer.py b/bcdi/experiment/diffractometer.py index b63ac7d31..778382da9 100644 --- a/bcdi/experiment/diffractometer.py +++ b/bcdi/experiment/diffractometer.py @@ -862,6 +862,7 @@ def load_check_dataset( scan_number, detector, setup, + frames_pattern=None, flatfield=None, hotpixels=None, background=None, @@ -876,6 +877,9 @@ def load_check_dataset( :param scan_number: the scan number to load :param detector: an instance of the class Detector :param setup: an instance of the class Setup + :param frames_pattern: 1D array of int, of length data.shape[0]. If + frames_pattern is 0 at index, the frame at data[index] will be skipped, + if 1 the frame will added to the stack. :param flatfield: the 2D flatfield array :param hotpixels: the 2D hotpixels array. 1 for a hotpixel, 0 for normal pixels. :param background: the 2D background array to subtract to the data @@ -947,7 +951,9 @@ def load_check_dataset( ################# # select frames # ################# - data, frames_logical = self.select_frames(data) + data, frames_logical = self.select_frames( + data=data, frames_pattern=frames_pattern + ) ################################# # crop the monitor if necessary # @@ -1214,7 +1220,6 @@ def select_frames(data, frames_pattern=None): accordingly. """ - # TODO implement this if frames_pattern is None: frames_pattern = np.ones(data.shape[0], dtype=int) valid.valid_1d_array( diff --git a/bcdi/preprocessing/bcdi_utils.py b/bcdi/preprocessing/bcdi_utils.py index 967f1ce85..f4e52793c 100644 --- a/bcdi/preprocessing/bcdi_utils.py +++ b/bcdi/preprocessing/bcdi_utils.py @@ -1265,8 +1265,11 @@ def load_bcdi_data( return a monitor based on the integrated intensity in the region of interest defined by detector.sum_roi, 'skip' to do nothing :param debugging: set to True to see plots - :parama kwargs: - - 'photon_threshold' = float, photon threshold to apply before binning + :param kwargs: + - 'photon_threshold': float, photon threshold to apply before binning + - 'frames_pattern': 1D array of int, of length data.shape[0]. If + frames_pattern is 0 at index, the frame at data[index] will be skipped, + if 1 the frame will added to the stack. :return: - the 3D data and mask arrays @@ -1279,7 +1282,7 @@ def load_bcdi_data( # check and load kwargs valid.valid_kwargs( kwargs=kwargs, - allowed_kwargs={"photon_threshold"}, + allowed_kwargs={"photon_threshold", "frames_pattern"}, name="kwargs", ) photon_threshold = kwargs.get("photon_threshold", 0) @@ -1289,12 +1292,20 @@ def load_bcdi_data( min_included=0, name="photon_threshold", ) + frames_pattern = kwargs.get("frames_pattern") + valid.valid_1d_array( + frames_pattern, + allow_none=True, + allowed_values={0, 1}, + name="frames_pattern" + ) rawdata, rawmask, monitor, frames_logical = setup.diffractometer.load_check_dataset( logfile=logfile, scan_number=scan_number, detector=detector, setup=setup, + frames_pattern=frames_pattern, bin_during_loading=bin_during_loading, flatfield=flatfield, hotpixels=hotpixels, diff --git a/bcdi/preprocessing/cdi_utils.py b/bcdi/preprocessing/cdi_utils.py index 44d64b0cb..731a91e51 100644 --- a/bcdi/preprocessing/cdi_utils.py +++ b/bcdi/preprocessing/cdi_utils.py @@ -615,7 +615,10 @@ def load_cdi_data( defined by detector.sum_roi :param debugging: set to True to see plots :param kwargs: - - 'photon_threshold' = float, photon threshold to apply before binning + - 'photon_threshold': float, photon threshold to apply before binning + - 'frames_pattern': 1D array of int, of length data.shape[0]. If + frames_pattern is 0 at index, the frame at data[index] will be skipped, + if 1 the frame will added to the stack. :return: - the 3D data and mask arrays @@ -629,7 +632,7 @@ def load_cdi_data( # check and load kwargs valid.valid_kwargs( kwargs=kwargs, - allowed_kwargs={"photon_threshold"}, + allowed_kwargs={"photon_threshold", "frames_pattern"}, name="kwargs", ) photon_threshold = kwargs.get("photon_threshold", 0) @@ -639,12 +642,20 @@ def load_cdi_data( min_included=0, name="photon_threshold", ) + frames_pattern = kwargs.get("frames_pattern") + valid.valid_1d_array( + frames_pattern, + allow_none=True, + allowed_values={0, 1}, + name="frames_pattern" + ) rawdata, rawmask, monitor, frames_logical = setup.diffractometer.load_check_dataset( logfile=logfile, scan_number=scan_number, detector=detector, setup=setup, + frames_pattern=frames_pattern, bin_during_loading=bin_during_loading, flatfield=flatfield, hotpixels=hotpixels, diff --git a/scripts/preprocessing/bcdi_preprocess_BCDI.py b/scripts/preprocessing/bcdi_preprocess_BCDI.py index c289f02af..c068d18bf 100644 --- a/scripts/preprocessing/bcdi_preprocess_BCDI.py +++ b/scripts/preprocessing/bcdi_preprocess_BCDI.py @@ -72,6 +72,10 @@ binning = (1, 2, 2) # binning to apply to the data # (stacking dimension, detector vertical axis, detector horizontal axis) bin_during_loading = False # True to bin during loading, require less memory +frames_pattern = None +# 1D array of int, of length data.shape[0]. If frames_pattern is 0 at index, +# the frame at data[index] will be skipped, if 1 the frame will added to the stack. +# Use this if you need to remove some frames and you know it in advance. ############################## # parameters used in masking # ############################## @@ -768,6 +772,7 @@ def press_key(event): scan_number=scan_nb, detector=detector, setup=setup, + frames_pattern=frames_pattern, bin_during_loading=bin_during_loading, flatfield=flatfield, hotpixels=hotpix_array, diff --git a/scripts/preprocessing/bcdi_preprocess_CDI.py b/scripts/preprocessing/bcdi_preprocess_CDI.py index 94e5aaa4e..bc190c23b 100644 --- a/scripts/preprocessing/bcdi_preprocess_CDI.py +++ b/scripts/preprocessing/bcdi_preprocess_CDI.py @@ -54,6 +54,10 @@ binning = [1, 2, 2] # binning that will be used for phasing # (stacking dimension, detector vertical axis, detector horizontal axis) bin_during_loading = False # True to bin during loading, require less memory +frames_pattern = None +# 1D array of int, of length data.shape[0]. If frames_pattern is 0 at index, +# the frame at data[index] will be skipped, if 1 the frame will added to the stack. +# Use this if you need to remove some frames and you know it in advance. ############################## # parameters used in masking # ############################## @@ -580,6 +584,7 @@ def press_key(event): scan_number=scan_nb, detector=detector, setup=setup, + frames_pattern=frames_pattern, bin_during_loading=bin_during_loading, flatfield=flatfield, hotpixels=hotpix_array,