- MNE-Python version: 0.22.0
- operating system:
When I modify the parameter tmin in crop() to a non-zero integer, and then use save() to save the cut Raw.
Open Raw after cutting, Annotations is empty.
But there is no problem if tmin is set to 0
When I modify the parameter tmin in crop() to a non-zero integer, and then use save() to save the cut Raw.
Open Raw after cutting, Annotations is empty.
But there is no problem if tmin is set to 0
Hello, thanks for your report. However, I cannot reproduce this behavior, neither on 0.22 nor with the current development version. I’m using the following code:
# %%
import os
import mne
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
'sample_audvis_raw.fif')
fname = '/tmp/foo_raw.fif'
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False)
raw.crop(tmax=60).load_data()
my_annot = mne.Annotations(onset=[3, 5, 7],
duration=[1, 0.5, 0.25],
description=['AAA', 'BBB', 'CCC'])
raw.set_annotations(my_annot)
# %%
raw.crop(tmax=30)
raw.save(fname, overwrite=True)
raw_loaded = mne.io.read_raw(fname)
print(raw_loaded.annotations)
# %%
raw.crop(tmin=1)
raw.save(fname, overwrite=True)
raw_loaded = mne.io.read_raw(fname)
print(raw_loaded.annotations)
There is no problem with your code, I think I may have considered too much.
Because I observed that the onset of raw_loaded.Annotations started at 45.9, I thought this was an error, because theoretically 0 represents the beginning of new data.
Therefore, when I created the epoch from Raw, I set the beginning of onset to 0. The program did not report an error, but there was no data in the generated Epoch.
If I don’t care about onset, there is no problem.The problematic code is as follows (paste it behind your code), if you comment out the first line, there will be no problem.When the save(tmin,tmax) function is used directly, onset is also non-zero start
raw_loaded.annotations.onset -= raw_loaded.annotations.onset[0]
events = mne.events_from_annotations(raw_loaded)[0]
epochs = mne.Epochs(raw_loaded, events, tmin=0, tmax=2,
baseline=(0, 0),
verbose=False, preload=True)
Anyway, thank you very much for your answer!
You normally should not (read: never) have to do anything like this. If you believe onsets should be shifted, consider passing the orig_time
parameter to mne.Annotations
.