question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

find_events() returns times with offset

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

0reactions
skjernscommented, Apr 15, 2021

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 the fif contains all samples, and first_samp tells mne at which position the actual data starts, right? So how can my events be out of bounds for raw.get_data()? Or is it possible that my fif files are already cropped (by e.g. MaxFilter or ELECTRA), and that’s why first_samp has been noted in the file, and raw.get_data() returns an already cropped array? So first_samp is only used to annotate how many samples there were before the current file (which would be a bit odd to me)?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found