python file read .locs

This tutorial is a brain-computer learner Rose Original (reprint please contact the author's permission) published in the public number: BCI community (Micro Signal: Brain_Computer) .QQ exchange group: 903 290 195

Brief introduction

This case focuses on how to read eeglab sample files .locs file. To demonstrate the electrode position, so it is necessary to read .set file. read details .set file See python read .set file , here be directly used.

.set file record information is collected, the main contents include channel number, event number, start time and end time.
.locs file record position information is an electrode.

Knowledge points:

Use mne.channels.read_custom_montage () reads .locs file.

Case

#导入工具库
import mne
import matplotlib.pyplot as plt

1. Read .set file

"""
通过mne.io.read_raw_eeglab来读取.set文件
得到原始数据对象
"""
raw = mne.io.read_raw_eeglab("Eeglab_data.set",preload=False)

2. Read .locs file
first check the channel name of the original data:

"""
打印通道名
"""
print(raw.info['ch_names'])


Can be seen from the result of the printing, the original data is not designated electrode position channel name, so it needs to be mapped to the name of the electrode position.

mapping = {
    'EEG 000': 'FPz', 'EEG 001': 'EOG1', 'EEG 002': 'F3', 'EEG 003': 'Fz',
    'EEG 004': 'F4', 'EEG 005': 'EOG2', 'EEG 006': 'FC5', 'EEG 007': 'FC1',
    'EEG 008': 'FC2', 'EEG 009': 'FC6', 'EEG 010': 'T7', 'EEG 011': 'C3',
    'EEG 012': 'C4', 'EEG 013': 'Cz', 'EEG 014': 'T8', 'EEG 015': 'CP5',
    'EEG 016': 'CP1', 'EEG 017': 'CP2', 'EEG 018': 'CP6', 'EEG 019': 'P7',
    'EEG 020': 'P3', 'EEG 021': 'Pz', 'EEG 022': 'P4', 'EEG 023': 'P8',
    'EEG 024': 'PO7', 'EEG 025': 'PO3', 'EEG 026': 'POz', 'EEG 027': 'PO4',
    'EEG 028': 'PO8', 'EEG 029': 'O1', 'EEG 030': 'Oz', 'EEG 031': 'O2'
}
# 根据映射名对原始数据中的通道名进行重命名
raw.rename_channels(mapping)
"""
读取.locs文件,.locs文件记录的是电极头皮位置
"""
montage=mne.channels.read_custom_montage("eeglab_chan32.locs")
"""
设置脑电图中传感器配置(电极位置配置)
"""
raw.set_montage(montage,raise_if_subset=False)
"""
打印设置电极位置后的通道名
"""
print(raw.info['ch_names'])

3. Draw electrode position

# 绘制电极位置
raw.plot_sensors()
plt.show()

"""
绘制通道位置图,并对应位置上显示通道名称
"""
layout_from_raw = mne.channels.make_eeg_layout(raw.info)
layout_from_raw.plot()
plt.show()

"""
上述效果也可通过
mne.channels.find_layout(raw.info, ch_type='eeg')
来读取
"""
layout_from_raw =mne.channels.find_layout(raw.info, ch_type='eeg')
layout_from_raw.plot()
plt.show()

4. Draw the power spectral density of each channel

"""
绘制各通道的功率谱密度
"""
raw.plot_psd()
plt.show()

"""
绘制采样频率在30Hz到70Hz之间,且只考虑40s到50s之间的所有通道的PSD
"""
raw.plot_psd(fmin=30, fmax=70, tmin=40,tmax=50.0,spatial_colors=True)
plt.show()

"""
绘制采样频率在30Hz到70Hz之间,且只考虑40s到50s之间的所有通道的平均PSD
"""
raw.plot_psd(fmin=30, fmax=70, tmin=40,tmax=50.0,average=True)
plt.show()

Brain-computer learner Rose notes share, QQ exchange group: 903 290 195
more to share, please pay attention to the public No.

Guess you like

Origin www.cnblogs.com/RoseVorchid/p/11978739.html