find_events() returns times with offset
See original GitHub issueI have a FIF file with a STI101
trigger channel to which I apply mne.find_events()
to extract the event markers. It seems to be that there is a mismatch of 5100 samples between the extracted events and the positions of the events when looking at the STI-Channel manually. Am I missing something? Why is there a delay to the raw STIM channel positions?
sample file:
import numpy as np
import mne
raw = mne.io.read_raw('events_raw.fif', preload=True)
# automatic extraction
events = mne.find_events(raw,stim_channel='STI101', shortest_event=1, consecutive=False)
# "manual" exctraction of events
manual_events = np.nonzero(raw.get_data('STI101'))[-1]
manual_events = manual_events[np.diff(np.pad(manual_events, [1, 0]))>1]
# consistent lag of 5100 samples
print(events[:,0]-manual_events)
however, I cannot reproduce this when I create the the same structure with an RawArray
, which leads me to conclude that this is something inside of my file that I just can’t figure out, but would badly need to fix.
raw = mne.io.read_raw('events_raw.fif', preload=True)
data = raw.get_data()
ch_types = ['grad', 'stim', 'syst']
ch_names = ['MEG2633', 'STI101', 'SYS201']
info = mne.create_info(ch_names=ch_names, sfreq=1000.0, ch_types=ch_types)
raw = mne.io.RawArray(data, info)
events = mne.find_events(raw,stim_channel='STI101', shortest_event=1, consecutive=False)
# now it works perfectly fine as expected, 0 lag
print(events[:,0]-manual_events)
Do you have any idea why this is happening?
Additional information
Platform: Windows-10-10.0.19041-SP0
Python: 3.8.8 (default, Feb 24 2021, 15:54:32) [MSC v.1928 64 bit (AMD64)]
Executable: C:\Users\skjerns\anaconda3\python.exe
CPU: AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD: 24 cores
Memory: 31.9 GB
mne: 0.22.1
numpy: 1.19.2 {blas=mkl_rt, lapack=mkl_rt}
scipy: 1.6.2
matplotlib: 3.3.4 {backend=Qt5Agg}
sklearn: 0.24.1
numba: 0.53.1
nibabel: Not found
nilearn: Not found
dipy: Not found
cupy: Not found
pandas: 1.2.3
mayavi: Not found
pyvista: Not found
vtk: Not found
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
mne.find_events — MNE 1.2.2 documentation - MNE-Python
If output is 'offset', find_events returns the last sample of each event instead of the first one: >>> print(find_events(raw ...
Read more >Events: list | Google Calendar
Must be an RFC3339 timestamp with mandatory time zone offset, for example, 2011-06-03T10:00:00-07:00, 2011-06-03T10:00:00Z. Milliseconds may be provided but are ...
Read more >Time modifiers - Splunk Documentation
Begin your time offset with a plus (+) or minus (-) to indicate the offset from the current time. ... Specifying latest=now() does...
Read more >Script to read Google Calendar Events and Count total Hours
A time zone offset is required unless a time zone is explicitly specified in ... getUTCDay() returns day of the week, I am...
Read more >Getting local time for future events based off UTC
time() return the local or UTC timestamp? 180 · How to ISO 8601 format a Date with Timezone Offset in JavaScript? 87 ·...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://mne.tools/stable/glossary.html?highlight=first_samp
Is there a place where I can find more documentation on
first_samp
, and how it is used, or what its definition is?I’m a bit puzzled because I have the case in multiple files that
events[-1,0] > len(raw)
. In my understanding thefif
contains all samples, andfirst_samp
tellsmne
at which position the actual data starts, right? So how can my events be out of bounds forraw.get_data()
? Or is it possible that myfif
files are already cropped (by e.g. MaxFilter or ELECTRA), and that’s whyfirst_samp
has been noted in the file, andraw.get_data()
returns an already cropped array? Sofirst_samp
is only used to annotate how many samples there were before the current file (which would be a bit odd to me)?