Skip to content

BUG raw.crop with first_samp != 0 and annotations #10490

@agramfort

Description

@agramfort

if you run:

from pathlib import Path
import mne

mne.viz.set_browser_backend('matplotlib')

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

raw = mne.io.read_raw_fif(sample_fname, preload=True)
raw.crop(tmax=4)
meas_date = None

if meas_date is None:
    raw.set_meas_date(None)

sfreq = raw.info['sfreq']
first_samp = 10_000
raw = mne.io.RawArray(raw.get_data(),
                      raw.info,
                      first_samp=first_samp)

annot = mne.Annotations(
    onset=[0, 1.5],
    duration=[1, 0.5],
    description=["a", "b"],
    orig_time=raw.info['meas_date'])

raw.set_annotations(annot)

raw.plot()

you get this

image

so far so good. But then if you do

raw.crop(0, 1.5)  # should keep the first annotation

assert len(raw.annotations) == 1  # FAILS

the first annotation does not survive although you get the data from the first one.

@larsoner you agree it's a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions