mne-tools / mne-tools/mne-python

Annotation times cannot be used to get corresponding data

Open
#13,890 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

BUG
Dominant language
Python
Stars
3.5k
Forks
1.6k
Avg merge
1d 6h
Merged PRs (30d)
100

Description

Description of the problem

I have some (manually-created) annotations for a raw file. I want to pull out the data from a particular channel, from the start to the end of that annotation. Either I'm making a really dumb mistake, or this is surprisingly difficult to do. It's clear that the problem has to do with first_samp (and I could subtract raw.first_samp somewhere in my code to get the right result) but it feels like this should be easier / "just work".

Steps to reproduce
import matplotlib.pyplot as plt
import mne
import numpy as np

fname = mne.datasets.sample.data_path() / "MEG" / "sample" / "sample_audvis_raw.fif"
raw = mne.io.read_raw_fif(fname)
annot = mne.Annotations(onset=3, duration=1, description="test")
raw.set_annotations(annot)

ann = raw.annotations[0]
data = raw.get_data(picks=[0], tmin=ann["onset"], tmax=ann["onset"] + ann["duration"])[0]
plt.ion()
fig, ax = plt.subplots(layout="constrained")
ax.plot(np.arange(len(data)), data)

raw.plot(picks=[0], start=ann["onset"], duration=ann["duration"])
Link to data

No response

Expected results
  1. when I call raw.plot(start=raw.annotations[0]["onset"], duration=raw.annotations[0]["duration"]) I would really like to see the data corresponding to that annotation span
  2. when I call raw.get_data(tmin=raw.annotations[0]["onset"], tmax=raw.annotations[0]["onset"] + raw.annotations[0]["duration"]) I would really like to obtain the data corresponding to the annotation span
Actual results
Image

NB: although sys_info() below says I'm on 1.11.0, I get the same results on main --- just happened to be in a project venv when I stumbled on this.

Additional information

Platform Linux-6.8.0-45-generic-x86_64-with-glibc2.39
Python 3.13.12 | packaged by conda-forge | (main, Feb 5 2026, 05:53:46) [GCC 14.3.0]
Executable /home/drmccloy/Documents/academics/research/ilabs/prism/.pixi/envs/analysis/bin/python3.13
CPU Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz (16 cores)
Memory 125.7 GiB

Core
├☒ mne 1.11.0 (outdated, release 1.12.1 is available!)
├☑ numpy 2.4.2 (OpenBLAS 0.3.30 with 8 threads)
├☑ scipy 1.17.1
└☑ matplotlib 3.10.8 (backend=qtagg)

Numerical (optional)
├☑ sklearn 1.8.0
├☑ numba 0.64.0
├☑ nibabel 5.4.0
├☑ nilearn 0.13.1
├☑ dipy 1.11.0
├☑ openmeeg 2.5.16
├☑ pandas 3.0.1
├☑ h5io 0.2.5
├☑ h5py 3.15.1
└☐ unavailable cupy

Visualization (optional)
├☑ pyvista 0.47.1 (OpenGL 4.5.0 NVIDIA 595.58.03 via NVIDIA GeForce RTX 2060/PCIe/SSE2)
├☑ pyvistaqt 0.11.3
├☑ vtk 9.5.0
├☑ qtpy 2.4.3 (PySide6=6.9.2)
├☑ pyqtgraph 0.14.0
├☑ mne-qt-browser 0.7.4
├☑ ipywidgets 8.1.8
├☑ trame_client 3.11.3
├☑ trame_server 3.10.0
├☑ trame_vtk 2.11.1
├☑ trame_vuetify 3.2.1
└☐ unavailable ipympl

Ecosystem (optional)
├☑ mne-bids 0.18.0
├☑ mne-icalabel 0.8.1
├☑ mne-bids-pipeline 1.10.0.dev167+g18af7ca2d
├☑ eeglabio 0.1.3
├☑ edfio 0.4.13
├☑ curryreader 0.1.2
├☑ mffpy 0.10.0
├☑ pybv 0.7.6
├☑ antio 0.6.1
├☑ defusedxml 0.7.1
└☐ unavailable mne-nirs, mne-features, mne-connectivity, neo

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided script, then inspect the Raw.get_data and Raw.plot entry points for how they interpret annotation onsets alongside first_samp. Trace the resulting sample ranges and verify that both APIs select and display the data covered by the annotation without requiring callers to adjust the onset.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data, data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.