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.

`mne.events_from_annotations` returns events that barely overlap with annotation

See original GitHub issue

I noticed that mne.events_from_annotations sometimes returns events that barely even overlap with an actual annotation when chunk_duration is used. I think this might have been the actual reason behind the issue https://github.com/mne-tools/mne-python/issues/5684#issuecomment-438211200.

The issue seems to arise when an annotation has a duration that is only slightly over chunk_duration. A first event will cover almost the entire annotation, but a second annotation will be created that might start within the annotation, but will barely overlap with it. Because of that, in some rare cases, the second event is identical to the next annotation - causing mne.Epochs to throw an error due to duplicate events.

Steps and/or code to reproduce

import mne
import numpy as np


# Create fake data with annotations
data = np.random.randn(2, 16000)
info = mne.create_info(
    ch_names=['EEG1', 'EEG2'], ch_types=['eeg', 'eeg'], sfreq=256)
raw = mne.io.RawArray(data, info)

onset = [0, 30]
duration = [30.1, 30]
description = ['0', '0']
annots = mne.Annotations(onset, duration, description)
raw = raw.set_annotations(annots)

# Extract epochs
events, event_ids = mne.events_from_annotations(raw, chunk_duration=30)
epochs = mne.Epochs(
    raw, events, tmin=0, tmax=30, baseline=None, on_missing='warning')

Expected results

I would have expected events to contain two events only: one for the first annotation [0, 30.1] and one for the second [30, 60]. An option would be to have an argument that lets the user decide whether events need to completely overlap with the annotation to be returned.

Actual results

events is:

array([[   0,    0,    1],
       [7680,    0,    1],
       [7680,    0,    1]])

Because of the duplicate row, mne.Epochs returns RuntimeError: Event time samples were not unique.

Additional information

Platform:      Linux-4.17.13-041713-generic-x86_64-with-debian-buster-sid
Python:        3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 17:14:51)  [GCC 7.2.0]
Executable:    /home/hubert/miniconda3/envs/dl-eeg/bin/python
CPU:           x86_64: 4 cores
Memory:        15.6 GB

mne:           0.18.dev0
numpy:         1.16.0 {blas=openblas, lapack=openblas}
scipy:         1.1.0
matplotlib:    2.2.3 {backend=TkAgg}

sklearn:       0.20.2
nibabel:       Not found
mayavi:        4.6.2 {qt_api=pyqt5, PyQt5=5.11.3}
cupy:          Not found
pandas:        0.23.4
dipy:          Not found

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hubertjbcommented, May 4, 2019

@mmagnuski @agramfort Thanks again!

0reactions
hubertjbcommented, May 2, 2019

Thanks for looking at this @mmagnuski!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parsing events from raw data
This tutorial describes how to read experimental events from raw recordings, and how to convert between the two different representations of events within...
Read more >
Annotating and Learning Event Durations in Text
This article presents our work on constructing a corpus of news articles in which events are annotated for estimated bounds on their duration, ......
Read more >
python - How to fix overlapping annotations / text
I'm having trouble converting the "axis" methods over to what I want to do, and I don't understand how the text lines up....
Read more >
Epochs events correctly, plots them wrong - MNE Forum
I have no idea why the segments dont get display correctly in the plot. ... to an Events array events, event_dict = mne.events_from_annotations(raw_load) ......
Read more >
dynamic positioning to avoid overlap of result details
If someone can please assist, it will allow me to determine if a pie chart is a suitable way to display results.. I...
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