使用mne库绘制地形图
mne官方提供繪制地形圖的例子:https://mne.tools/stable/auto_examples/visualization/evoked_topomap.html#sphx-glr-auto-examples-visualization-evoked-topomap-py
跟著教程繪制即可,下面是我繪制地形圖的代碼
def plot_topomap(evoke):''':param evoke: evoked data:return:'''# 設置想要繪制的地形圖的指定時間times = np.arange(0.1, 0.5, 0.02)# ncols是指每一行顯示的個數,contours是指地形圖的等高線數evoke.plot_topomap(times, ncols=4, nrows='auto', contours=9, ch_type='eeg')這邊補充一個python小知識:np.linspace和np.arange有什么區別
https://stackoverflow.com/questions/62106028/what-is-the-difference-between-np-linspace-and-np-arange
在繪制完之后的圖片是這樣的:
感覺與官網上的圖有點差別,一是大腦太小了,二是電極在地形圖中的位置也不匹配。一開始我通過設置參數sphere來調整中間大腦的直徑,有效果但畢竟是自己設置的,這個直徑的值把握不好。
參考:https://mne.tools/stable/auto_tutorials/intro/40_sensor_locations.html
Channel positions in 2D space are obtained by projecting their actual 3D positions onto a sphere, then projecting the sphere onto a plane. By default, a sphere with origin at (0, 0, 0) (x, y, z coordinates) and radius of 0.095 meters (9.5 cm) is used. You can use a different sphere radius by passing a single value as the sphere argument in any function that plots channels in 2D (like plot that we use here, but also for example mne.viz.plot_topomap):對于電極在地形圖中位置不匹配問題,我采用重新定位電極方法
# 采用EEG內置腦電圖電極standard_1020,不過還有其他很多標準,具體看上面的鏈接 montage = mne.channels.make_standard_montage('standard_1020') raw.set_montage(montage, on_missing='ignore')這里有一個問題,就是電極通道名字不匹配問題,我原先的電極通道中PZ、OZ電極等的Z是大寫的,然后"standard_1020"電極的名字中z是小寫的,所以會報錯,找了很久的方法,終于解決了
具體看:https://mne.discourse.group/t/channel-positions-not-present-in-digmontage/4119/2
簡而言之就是自己換一下通道的名字
new_chan_names = ['Fp1', 'Fpz', 'Fp2', 'AF3', 'AF4', 'F7', 'F5', 'F3', 'F1', 'Fz', 'F2', 'F4', 'F6', 'F8', 'FT7', 'FC5','FC3', 'FC1', 'FCz', 'FC2', 'FC4', 'FC6', 'FT8', 'T7', 'C5', 'C3', 'C1', 'Cz', 'C2', 'C4', 'C6', 'T8','M1', 'TP7', 'CP5', 'CP3', 'CP1', 'CPz', 'CP2', 'CP4', 'CP6', 'TP8', 'M2', 'P7', 'P5', 'P3', 'P1', 'Pz','P2', 'P4', 'P6', 'P8', 'PO7', 'PO5', 'PO3', 'POz', 'PO4', 'PO6', 'PO8', 'O9', 'O1', 'Oz', 'O2', 'O10']def read_plot(file, name):raw = mne.io.read_raw_cnt(file, preload=True)# 去掉壞的電極raw.info['bads'].append('M1')raw.info['bads'].append('M2')old_chan_names = raw.ch_nameschan_names_dict = {old_chan_names[i]: new_chan_names[i] for i in range(64)}raw.rename_channels(chan_names_dict)montage = mne.channels.make_standard_montage('standard_1020')raw.set_montage(montage, on_missing='ignore')raw.plot_sensors(show_names=True)print(raw.ch_names)然后就解決了,神奇的是上面第一個大腦太小的問題也自動解決了。
附圖:
總結
以上是生活随笔為你收集整理的使用mne库绘制地形图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unity常用的动画类型
- 下一篇: k8s使用StatefulSet部署Mo