MNE官网解读文章《Annotating continuous data》(https://mne.tools/stable/auto_tutorials/raw/30_annotate_raw.html?highlight=annotation,以下简称《文章》)
说明:本博客作为个人学习mne和发现和处理问题的记录
按照《文章》指导,本人编写代码如下——
import os
from datetime import timedelta
import mne
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
'sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False)
raw.crop(tmax=60).load_data()
my_annot = mne.Annotations(onset=[3, 5, 7],
duration=[1, 0.5, 0.25],
description=['AAA', 'BBB', 'CCC'])
print(my_annot)
raw.set_annotations(my_annot)
print(raw.annotations)
meas_date = raw.info['meas_date']
orig_time = raw.annotations.orig_time
print(meas_date)
print(meas_date == orig_time)
time_of_first_sample = raw.first_samp / raw.info['sfreq']
print(time_of_first_sample)
print(my_annot.onset + time_of_first_sample)
print(raw.annotations.onset)
time_format = '%Y-%m-%d %H:%M:%S.%f'
new_orig_time = (meas_date + timedelta(seconds=50)).strftime(time_format)
print(new_orig_time)
later_annot = mne.Annotations(onset=[1, 2, 5],
duration=[1, 0.5, 0.25],
description=['DDD', 'EEE', 'FFF'],