table of Contents
This tutorial brain machine in public published learner Rose No: BCI community (Micro Signal: Brain_Computer) .QQ exchange group: 903 290 195
Epochs object is a method of continuous data represented as a collection period,
the array store ( n_events, n_channels, n_times)
You can see how it was created: MNE data structures and how to create Epoch
This example describes the common use object Epoch
a. Create epoch objects
1) read fif file, create raw objects
2) create events target
3) to create objects epoch
import mne
import os.path as op
import numpy as np
from matplotlib import pyplot as plt
Step 1: Create raw objects
data_path = mne.datasets.sample.data_path()
# 加载包含事件events的听觉数据集
raw = mne.io.read_raw_fif(
op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw.fif'))
Step 2: Create events Object
# 构造事件数组
events = mne.find_events(raw, stim_channel='STI 014')
# 显示事件数
print('Number of events:', len(events))
# 显示所有唯一的事件编号(第3列)
print('Unique event codes:', np.unique(events[:, 2]))
"""
使用描述性标签指定感兴趣的事件代码。
给不同的events一个描述性名称。
"""
event_id = {'Auditory/Left': 1, 'Auditory/Right': 2}
Here you can create an event with the above-mentioned extracted mne.Epochs object, but the manner of construction epoch can not be used, because the data has not been read into memory, you can get can also use preload = True by get_data.
Step 3: Create epoch objects
The raw data (RAW) cut into a set of a plurality of Epoch (time segment), and
In each event in advance as a reference standard good, tmax to tmin take this as an epoch period to perform data processing.
The length of time of 1 sec at 1.1 seconds and 0.1 seconds before taken after each event as an epoch, for the same type of event epochs subsequent overlay (Average) Analysis preparation.
epochs = mne.Epochs(raw, events, event_id, tmin=-0.1, tmax=1,
baseline=(None, 0), preload=True)
print(epochs)
b. Check epoch objects
mne.io.Raw epochs objects are similar object, and event attributes having attribute info.
You can view the event information in the epoch of the following two ways
print(epochs.events[:3])
print(epochs.event_id)
[[27977 0 2]
[28771 0 1]
[29652 0 2]]
{'Auditory/Left': 1, 'Auditory/Right': 2}
You can also access events in the epoch objects slicing through the list of ways to use python,
events and descriptive names can also directly access
print(epochs[1:5])
print(epochs['Auditory/Right'])
Description: '/' symbol for dividing tag (Tag), each '/' demarcated as a string of words can be retrieved,
May direct search epochs [ 'Right'] can be obtained result
print(epochs['Right'])
print(epochs['Right', 'Left'])
c.epoch average overlay
Evoked method returns the object by calling mne.Epochs.average (), average () method to specify the desired channel parameter.
ev_left = epochs['Auditory/Left'].average()
ev_right = epochs['Auditory/Right'].average()
f, axs = plt.subplots(3, 2, figsize=(10, 5))
_ = f.suptitle('Left / Right auditory', fontsize=20)
_ = ev_left.plot(axes=axs[:, 0], show=False, time_unit='s')
_ = ev_right.plot(axes=axs[:, 1], show=False, time_unit='s')
plt.tight_layout()
FIG upper left corner of the figure shows the raw data in the left auditory epochs (Mark 'Auditory / Left'), and
simultaneously for all channels of EEG extracted average value superimposing process.
You may be superimposed on the channel specified in the actual process (extraction channel by the pick and average processing method)
This article was shared by brain-computer learner Rose notes, QQ exchange group: 903 290 195
more to share, please pay attention to the public No.