Skip to content

Annotation displayed on ICA sources when meas_date is None and first_samp is not 0 are wrong #11762

Closed

Description

@mscheltienne

Description of the problem

One more time-management related issue with annotations. MWE:

from datetime import datetime, timezone

import numpy as np
from mne import Annotations, create_info
from mne.io import RawArray
from mne.preprocessing import ICA


#%%
# date = datetime(1995, 3, 28, 0, 0, 0, 0, tzinfo=timezone.utc)

info = create_info(5, 1000, "eeg")
data = np.random.randn(5, 10000)
raw = RawArray(data, info)
assert raw.first_samp == 0
# raw.set_meas_date(date)
annotation = Annotations(onset=4, duration=1, description="bad_test")
raw.set_annotations(annotation)
# raw.plot(theme="light", scalings="auto")

#%%
raw.crop(2, 8)
# raw.plot(theme="light", scalings="auto")

#%%
ica = ICA(
    method="picard", fit_params=dict(ortho=False, extended=True), random_state=888
)
ica.fit(raw, picks="eeg", reject_by_annotation=True)
ica.plot_sources(raw, theme="light")

If there is no measurement date and if raw.first_samp is different from 0 (e.g. by cropping), the annotations displayed in ica.plot_sources are not correctly set. Issue is here:

mne-python/mne/viz/ica.py

Lines 1304 to 1305 in 7def836

inst_array = RawArray(data, info, inst.first_samp)
inst_array.set_annotations(inst.annotations)

Still thinking about what is a good fix.. time-management is a real headache 🤯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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