Annotation and crop - different onset points after reloading the saved croppend data
See original GitHub issueDescribe the bug
I suspect that this issue is similar to the #9383. The issue only occurs when a raw instance created with Annotation. Originally labeled data as brain vision files are work fine. Cropping the instance, saving and reloading it shows the annotations in the original place before the cropping.
Steps to reproduce
import numpy as np
import mne
CH_NUM = 32
FS = 160
data = np.zeros((CH_NUM, FS * 20))
ch_names = [f'EEG{i}' for i in range(CH_NUM)]
ch_types = ['eeg'] * len(ch_names)
onset = [8, 12, 18]
duration = [2] * len(onset)
description = list(range(len(onset)))
info = mne.create_info(ch_names, ch_types=ch_types, sfreq=FS)
raw = mne.io.RawArray(data, info)
annotation = mne.Annotations(onset, duration, description)
raw = raw.set_annotations(annotation)
sess = raw.copy()
sess.crop(5, 18)
file = 'test_file_raw.fif'
sess.save(file, overwrite=True)
sess.plot(block=False)
r = mne.io.read_raw(str(file))
r.plot(block=False)
raw.plot(block=True)
Expected results
I expect that the annotated data should look like the same before and after saving it.
Actual results
The annotations are shifted…
Additional information
Platform: Windows-10-10.0.19041-SP0 Python: 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] Executable: C:\Programs\Miniconda3\envs\bci2\python.exe CPU: Intel64 Family 6 Model 158 Stepping 10, GenuineIntel: 12 cores Memory: Unavailable (requires “psutil” package) mne: 0.23.0 numpy: 1.19.3 {blas=D:\a\1\s\numpy\build\openblas_info, lapack=D:\a\1\s\numpy\build\openblas_lapack_info} scipy: 1.6.0 matplotlib: 3.3.3 {backend=TkAgg} sklearn: 0.24.0 numba: Not found nibabel: Not found nilearn: Not found dipy: Not found cupy: Not found pandas: 1.2.0 mayavi: Not found pyvista: Not found vtk: Not found
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (10 by maintainers)
Top GitHub Comments
@mscheltienne I’m inclined to bump the milestone on this from 0.24 to 1.0 so we don’t have to rush a fix in the next week that will potentially break other stuff.
A few words following discord discussion. The assumption is that:
first_samp
. -> Different from @drammock comment:the origin is the beginning of the raw object instance, regardless of what its first_samp value is.
I’ll have a look when I have time.