Skip to content

Commit

Permalink
implement frames_pattern, for custom removal of frames
Browse files Browse the repository at this point in the history
  • Loading branch information
carnisj committed Sep 12, 2021
1 parent cd6a515 commit d4c85dd
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
9 changes: 7 additions & 2 deletions bcdi/experiment/diffractometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ def load_check_dataset(
scan_number,
detector,
setup,
frames_pattern=None,
flatfield=None,
hotpixels=None,
background=None,
Expand All @@ -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
Expand Down Expand Up @@ -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 #
Expand Down Expand Up @@ -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(
Expand Down
17 changes: 14 additions & 3 deletions bcdi/preprocessing/bcdi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions bcdi/preprocessing/cdi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions scripts/preprocessing/bcdi_preprocess_BCDI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
##############################
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions scripts/preprocessing/bcdi_preprocess_CDI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
##############################
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d4c85dd

Please sign in to comment.