Neuronal-Oscillations / FLUX

The FLUX pipeline for analysis of MEG data using MNE Python
https://neuosc.com/flux/
BSD 3-Clause "New" or "Revised" License
44 stars 33 forks source link

Error: orig_time should be the same to add/concatenate 2 annotations #23

Closed oscfer88 closed 1 year ago

oscfer88 commented 1 year ago

Bug reported from @SyanahWynn


Here the explanation of the error and a possible fix. (I have added the outputs and the figure of the artifacts after the fix as attachments):

ERROR

Traceback (most recent call last): File "FLUX_tutorial.py", line 89, in data1.set_annotations(annotations_blink+annotations_muscle); File "/rds/homes/w/wynns/mne-haswell/lib/python3.8/site-packages/mne/annotations.py", line 294, in add out += other File "/rds/homes/w/wynns/mne-haswell/lib/python3.8/site-packages/mne/annotations.py", line 305, in iadd raise ValueError("orig_time should be the same to " ValueError: orig_time should be the same to add/concatenate 2 annotations (got None != 2000-01-01 00:00:00+00:00)

FIX (?) Commenting out the onset offset and adding the orig_time manually did seem to get rid of the error and the timing in the plot looks the same as the one in the tutorial.

onset = eog_events[:, 0] / data1.info['sfreq'] - 0.25

onset -= data1._first_time

duration = np.repeat(0.5, n_blinks)
description = ['blink'] * n_blinks
orig_time = data1.info['meas_date'] annotations_blink = mne.Annotations(onset,duration,description,orig_time)

oscfer88 commented 1 year ago

This bug is only present in the newer version of MNE (>0.24). It is due to a change made to the annotate_muscle_zscore function (see below).

From MNE-Python version 1.0.0 changelog: "Fix inconsistent behavior of mne.preprocessing.annotate_* functions by making them all return mne.Annotations objects with the orig_time attribute set to raw.info["meas_time"]"