MNE学习笔记(四):Evoked数据结构
MNE學(xué)習(xí)筆記(四):Evoked數(shù)據(jù)結(jié)構(gòu)
參考文章:
https://mp.weixin.qq.com/s/Udr0qBvspyKVjASdgL-QxQ
https://mne.tools/stable/auto_tutorials/index.html 【官方教程】
https://baike.baidu.com/item/%E8%AF%B1%E5%8F%91%E7%94%B5%E4%BD%8D/8378650?fr=aladdin
概念
Evoked potential(EP)
- 機(jī)體的自發(fā)電活動(dòng)可以為直接的或外界的確定性刺激(電、光、聲等刺激)所影響,產(chǎn)生另一種局部化的電位變化稱為誘發(fā)電位。又稱誘發(fā)反應(yīng)、事件相關(guān)電位。
誘發(fā)電位(Evoked)結(jié)構(gòu)
-
主要用于存儲(chǔ)實(shí)驗(yàn)期間的平均數(shù)據(jù),在MNE中,創(chuàng)建Evoked對(duì)象通常使用mne.Epochs.average()來(lái)平均epochs數(shù)據(jù)來(lái)實(shí)現(xiàn)。
-
Evoked對(duì)象通常存儲(chǔ)一個(gè)已經(jīng)被多個(gè)epochs平均(averaged)后的EEG或者M(jìn)EG信號(hào),它是用來(lái)評(píng)估被刺激誘發(fā)的活動(dòng)(stimulus-evoked activity)的一個(gè)常用技術(shù)。
-
用array存儲(chǔ)(n_channels, n_times)
對(duì)比Epochs對(duì)象,存儲(chǔ)屬性:n_epochs,n_channels,n_times
創(chuàng)建
Evoked數(shù)據(jù)結(jié)構(gòu)的創(chuàng)建主要有兩種方式
- 從Epochs對(duì)象中創(chuàng)建Evoked對(duì)象
- 從頭創(chuàng)建Evoked對(duì)象
從Epochs對(duì)象中創(chuàng)建Evoked對(duì)象
采用read_evokeds方法來(lái)進(jìn)行創(chuàng)建
代碼:
# 從fif文件中讀取誘發(fā)數(shù)據(jù)集 data_path = "D:\Data\MNE-sample-data" fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis-ave.fif') evokeds = mne.read_evokeds(fname, baseline=(None, 0), proj=True) print(evokeds) # 只讀取左聽(tīng)覺(jué)的電位數(shù)據(jù) evoked = mne.read_evokeds(fname, condition='Left Auditory') evoked.apply_baseline((None, 0)).apply_proj() print(evoked)結(jié)果:
從頭創(chuàng)建Evoked對(duì)象
步驟:
代碼:
import mne import numpy as np import matplotlib.pyplot as plt""" 第一步:構(gòu)建數(shù)據(jù) 構(gòu)建一個(gè)大小為10x5x200的三維數(shù)組,數(shù)組中數(shù)據(jù)是隨機(jī)數(shù); 第一維數(shù)據(jù)表示:10 epochs 第二維數(shù)據(jù)表示:5 channels 第三維數(shù)據(jù)表示:2 seconds per epoch """ # 采樣頻率 sfreq = 100 data = np.random.randn(10, 5, sfreq * 2)# 創(chuàng)建一個(gè)info結(jié)構(gòu) info = mne.create_info(ch_names=['MEG1', 'MEG2', 'EEG1', 'EEG2', 'EOG'],ch_types=['grad', 'grad', 'eeg', 'eeg', 'eog'],sfreq=sfreq )""" 第二步:創(chuàng)建evoked對(duì)象 利用mne.EvokedArray創(chuàng)建Evoked對(duì)象 """ # tmin:event開(kāi)始前的時(shí)間,如果未指定,則默認(rèn)為0,這里設(shè)為-0.1s tmin = -0.1# 對(duì)數(shù)據(jù)求平均 data_evoked = data.mean(0)# epochs的數(shù)量 nave = data.shape[0]# 給evoked起一個(gè)名稱 comment = "Smiley faces"# 利用mne.EvokedArray創(chuàng)建Evoked對(duì)象 evoked_array = mne.EvokedArray(data_evoked, info, tmin,comment=comment, nave=nave) print(evoked_array) _ = evoked_array.plot(time_unit='s') plt.show()結(jié)果:
查看
查看的方式和之前的Epochs是類似的
代碼:
# 打印evoked的信息,這個(gè)信息和Raw對(duì)象以及Epochs對(duì)象中的info很相似 print(evoked.info) print(evoked.times)# 查看evoked結(jié)構(gòu)其他屬性 print(evoked.nave) # Number of averaged epochs. print(evoked.first) # First time sample. print(evoked.last) # Last time sample. print(evoked.comment) # Comment on dataset. Usually the condition. print(evoked.kind) # Type of data, either average or standard_error.結(jié)果:
由于數(shù)據(jù)很長(zhǎng),這里只截取部分
可視化
看注釋。PS:之后有時(shí)間可能會(huì)整理可視化的方法。
代碼:
""" 可視化1 快速提取并繪制全局能量譜(Global Field Power, GFP)作為跨通道的標(biāo)準(zhǔn)偏差 這里僅顯示EEG """ gfp = evoked.copy().pick_types(eeg=True, meg=False).data.std(axis=0) fig, ax = plt.subplots(1) ax.plot(evoked.times, gfp / 1e6) # scale to uV ax.set(xlabel='Time (sec)', ylabel='GFP (uV)') fig.tight_layout() plt.show()""" 可視化2 將結(jié)果顯示為蝶形圖 exclude=[]:不排除不良信道(用紅色顯示) """ evoked.plot(exclude=[], time_unit='s') plt.show()""" 可視化3 將結(jié)果以二維圖片的形式顯示 (x: time, y: channels, color: amplitude) """ evoked.plot_image(exclude=[], time_unit='s') plt.show()結(jié)果:
可視化1:
可視化2:
可視化3:
附錄:完整代碼
這里是從Epochs對(duì)象中創(chuàng)建Evoked對(duì)象的方式的完整代碼:
import os.path as op import matplotlib.pyplot as plt import mne# 從fif文件中讀取誘發(fā)數(shù)據(jù)集 data_path = "D:\Data\MNE-sample-data" fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis-ave.fif') evokeds = mne.read_evokeds(fname, baseline=(None, 0), proj=True) print(evokeds) # 只讀取左聽(tīng)覺(jué)的電位數(shù)據(jù) evoked = mne.read_evokeds(fname, condition='Left Auditory') evoked.apply_baseline((None, 0)).apply_proj() print(evoked)# 打印evoked的信息,這個(gè)信息和Raw對(duì)象以及Epochs對(duì)象中的info很相似 print(evoked.info) print(evoked.times)# 查看evoked結(jié)構(gòu)其他屬性 print(evoked.nave) # Number of averaged epochs. print(evoked.first) # First time sample. print(evoked.last) # Last time sample. print(evoked.comment) # Comment on dataset. Usually the condition. print(evoked.kind) # Type of data, either average or standard_error.""" 可視化1 快速提取并繪制全局能量譜(Global Field Power, GFP)作為跨通道的標(biāo)準(zhǔn)偏差 這里僅顯示EEF """ gfp = evoked.copy().pick_types(eeg=True, meg=False).data.std(axis=0) fig, ax = plt.subplots(1) ax.plot(evoked.times, gfp / 1e6) # scale to uV ax.set(xlabel='Time (sec)', ylabel='GFP (uV)') fig.tight_layout() plt.show()""" 可視化2 將結(jié)果顯示為蝶形圖 exclude=[]:不排除不良信道(用紅色顯示) """ evoked.plot(exclude=[], time_unit='s') plt.show()""" 可視化3 將結(jié)果以二維圖片的形式顯示 (x: time, y: channels, color: amplitude) """ evoked.plot_image(exclude=[], time_unit='s') plt.show()總結(jié)
以上是生活随笔為你收集整理的MNE学习笔记(四):Evoked数据结构的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python与erp_Python-EE
- 下一篇: 乘法逆元学习笔记