Losing events when concatenating files

Dear everybody,

I have troubles concatenating multiple fif-files, as I seem to lose all events in the process.

What I am doing right now is a concatenation of multiple files (typically 3 or 4, but varies) as follows:

for r in raws:
            all_raws[r] = mne.io.read_raw(r, preload=False)
raw = mne.concatenate_raws([all_raws[r] for r in raws])

I checked, that the raw-files I feed into the dictionary still contain the events (in form of annotations).

After concatenation

mne.events_from_annotations(raw)

returns an empty list.

I am aware of

mne.concatenate_events()

but I don’t understand what the input for the arguments first_samp and last_samp is supposed tobe like in this scenario.

Concatenating events and event_ids from mne.events_from_annotations also seems suboptimal, as I am not sure in what order I would need to do that (i.e. which file comes first in the above list comprehension).

Any help would be much appreciated!

Thank you in advance!

Best,
Rudi K.

Hello @RuKrei,

just a small thing on nomenclature:

events and annotations are two related, but distinct concepts in MNE-Python. It’s a bit confusing, but suffice it to say that events are the things in that NumPy array with 3 columns (and without duration, as they are instantaneous), while annotations are a separate object type and can have a duration.

It’s unclear to me where exactly things go wrong in your above code. Could you please check what raw.annotations looks like after the concatenation? Are there even any annotations left?

Thanks,
Richard

sure,

events, event_ids = mne.events_from_annotations(raw)
print(events)

returns an empty array: array([], shape=(0, 3), dtype=int32)

raw.annotations()

is also empty: <Annotations | 0 segments>

Thanks for having a look.

Best,
Rudi

Hmm I cannot seem to reproduce this with MNE-Python 0.24 and the following code:

# %%
from pathlib import Path
import mne


sample_dir = Path(mne.datasets.sample.data_path())
sample_fname = sample_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'

raw = mne.io.read_raw_fif(sample_fname, preload=True)
raw.crop(tmax=60)

a = mne.Annotations(
    onset=[0, 1, 2],
    duration=[1, 1, 1],
    description=['foo', 'bar', 'baz']
)
raw.set_annotations(a)


mne.concatenate_raws([raw, raw, raw])
print(raw.annotations)

@RuKrei Which version of MNE-Python are you using?

@drammock @agramfort Any idea what might be going on here?

Hmmm, strange things are happening here.

If I run your code, @richard, on mne 0.24 it executes as expected.

The only thing I do before concatenating is filtering and resampling the files.
So my best guess right now is, that I am for some reason losing the events there.

I will check and let you know, once I can tell more.

Thanks again.

Best
Rudi

Hello @RuKrei, if you want to, feel free to share your input data with me via Google Drive or a similar service; my email address is richard.hoechenberger@gmail.com
I can then have a look.

Cheers,
Richard