braindecode.preprocessing.Crop#
- class braindecode.preprocessing.Crop(tmin=0.0, tmax=None, include_tmax=True, *, reset_first_samp=False, verbose=None)[source]#
Braindecode preprocessor wrapper for
crop().Crop raw data file.
Limit the data from the raw file to go between specific times. Note that the new
tminis assumed to bet=0for all subsequently called functions (e.g.,time_as_index(), orEpochs). New first_samp and last_samp are set accordingly.Thus function operates in-place on the instance. Use
mne.io.Raw.copy()if operation on a copy is desired.- Parameters:
tmin (float) – Start time of the raw data to use in seconds (must be >= 0).
tmax (float | None) – End time of the raw data to use in seconds (cannot exceed data duration). If
None(default), the current end of the data is used.include_tmax (bool) –
If True (default), include tmax. If False, exclude tmax (similar to how Python indexing typically works).
Added in version 0.19.
reset_first_samp (bool) –
If True, reset first_samp to 0 after cropping, treating the cropped segment as an independent recording. Note that this can break things if you extracted events before cropping and try to use them afterward. Default is False.
Added in version 1.12.
verbose (bool | str | int | None) – Control verbosity of the logging output. If
None, use the default verbosity level. See the logging documentation andmne.verbose()for details. Should only be passed as a keyword argument.
- Returns:
raw (instance of Raw) – The cropped raw object, modified in-place.
Notes
After cropping, first_samp is updated to reflect the new start of the data, preserving the original recording timeline. This means
raw.timeswill still start at0.0, butraw.first_sampwill reflect the offset from the original recording. If you want to treat the cropped segment as an independent signal withfirst_samp=0, you can convert it to aRawArray:raw_array = mne.io.RawArray(raw.get_data(), raw.info)
Examples
By default, cropping preserves the original recording timeline, so first_samp remains non-zero after cropping:
>>> raw = mne.io.read_raw_fif(fname) >>> print(raw.first_samp) 25800 >>> raw.crop(tmin=10, tmax=20) >>> print(raw.first_samp) 27810
If you want to treat the cropped segment as an independent recording, use
reset_first_samp=True:>>> raw2 = raw.copy().crop(tmin=10, tmax=20, ... reset_first_samp=True) >>> print(raw2.first_samp) 0
Examples using braindecode.preprocessing.Crop#
Comprehensive Preprocessing with MNE-based Classes