find_events does not correctly save time indices

Hi,

I tried to use find_events to extract trigger events from my MEG trigger channels.
This appears to works. I can raw.plot(events=events) and in the plot everything looks perfect. Then I wanted to crop the data and noticed that the events array appears to be incorrect. I can see that the entries in the events array go beyond the length of my data. I can see that the first trigger is actually at 4.663 seconds. However find_events places the first event at 37423. After that all times are correct, but time shifted. It looks like all time indices in the events array are shifted as if one had added 32760 to each time stamp.
I can “fix” this doing something like:
events[:, 0] -= 32760
but why is this happening? When I do this, the plot then shows incorrectly placed triggers, but this events array then works. I wonder how I can proceed now. Am I doing something wrong here or is there really an error with find_events?

Any help is greatly appreciated. Thanks!

system info:

mne.sys_info()
Platform: macOS-13.5.1-arm64-i386-64bit
Python: 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:25:29) [Clang 14.0.6 ]
Executable: /Applications/MNE-Python/.mne-python/bin/python
CPU: i386: 10 cores
Memory: 32.0 GB

mne: 1.3.1

Hi, is this recording from a NeuroMag system? Then what you’re seeing might be related to the fact that it starts counting time (and samples) before the actual recording has started. We keep track of this via raw.first_samp and raw.first_time.

See the glossary: Glossary — MNE 1.5.0 documentation

Example:

# %%
import mne

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

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

events = mne.find_events(raw, stim_channel="STI 014")

mne.viz.plot_events(events)
mne.viz.plot_events(events, first_samp=raw.first_samp)

This produces two figures:
image

image

MNE is aware of this time shift and takes it into account during operations when necessary.

Best wishes,
Richard

1 Like

Yes, thank you!
it is indeed a NeuroMag machine and raw.first_samp does exactly what I need. I also noticed that I need to rerun find_events whenever I crop or copy data, because MNE gets horribly confused, but it works fine now.