Skip to content

Repeated Epoch/Evoked cropping is not idempotent when include_tmax=False #9374

@jsosulski

Description

@jsosulski

Describe the bug

Repeated cropping of mne.Epoch when include_tmax=False cuts off the last time sample.

Steps to reproduce

import mne
import numpy as np

n_epochs, n_channels, n_timepoints = 10, 4, 21
ch_names = [f"ch_{i}" for i in range(n_channels)]
fake_data = np.random.random((n_epochs, n_channels, n_timepoints))

info = mne.create_info(ch_names=ch_names, sfreq=40)
epo = mne.EpochsArray(fake_data, info)

for i in range(10):
    epo.crop(tmin=0, tmax=0.4, include_tmax=False)
    print(f"{epo.tmax=}")

Expected results

The epo.tmax should be set to 0.375 on the first and all subsequent iterations.

Actual results

Every loop iteration cuts off the last time sample of the epoch.

Additional information

Platform:      Linux-5.4.0-72-generic-x86_64-with-glibc2.29
Python:        3.8.5 (default, Jan 27 2021, 15:41:15)  [GCC 9.3.0]
Executable:    /home/jan/dev/python/spot/spot_venv/bin/python
CPU:           x86_64: 8 cores
Memory:        Unavailable (requires "psutil" package)
mne:           0.24.dev0
numpy:         1.19.5 {blas=openblas, lapack=openblas}
scipy:         1.5.4
matplotlib:    3.3.4 {backend=module://backend_interagg}

sklearn:       0.23.2
numba:         Not found
nibabel:       3.2.1
nilearn:       Not found
dipy:          Not found
cupy:          Not found
pandas:        1.1.5
mayavi:        Not found
pyvista:       Not found
vtk:           Not found

The cause of the issue is that when the tmax argument for crop is out of range of the Epoch, it is set to epo.tmax. However, this behaviour is (at least for me) unintuitive when include_tmax=False as I do not want to cut off the last time sample, if my desired interval is larger than the epoch.

Possible solution would be to set tmax to tmax + 1/sfreq when include_tmax=True and the desired tmax-crop is outside the epoch interval.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions