import sys
sys.version_info
del sys # module sysの読み込み中止
import os.path as op
import numpy as np
import mne
mne.set_log_level('INFO')
data_path=op.join(mne.datasets.sample.data_path(),'MEG','sample') # このコードは
print(data_path)
data_path=mne.datasets.sample.data_path()+'\\MEG\\sample' # このコードと同じ意味です
print(data_path)
op.joinを使わなくてもpythonは+' 'で代用できます。
raw=mne.io.read_raw_fif(op.join(data_path,'sample_audvis_raw.fif'))
print(raw)
raw.set_eeg_reference() # EEG averageを関電位とする
events=mne.read_events(op.join(data_path,'sample_audvis_raw-eve.fif'))
events.shape
raw.plot(block=True); # jupyterでは;をつけないと2個絵が出てきます。
raw.plot(order='selection');
raw.plot_sensors(kind='3d',ch_type='mag',ch_groups='position');
SSPの追加です
projs=mne.read_proj(op.join(data_path,'sample_audvis_eog-proj.fif'));
print(projs);
raw.add_proj(projs)
raw.plot_projs_topomap();
raw.plot();
Projボタンを押せば、SSPのON/OFFを選択できますが、jupyterではできません・・・
raw.plot_psd(tmax=np.inf,average=False);
layout=mne.channels.read_layout('Vectorview-mag') # Vectorview-grad,Vectorview-all
layout.plot();
raw.plot_psd_topo(tmax=30.,fmin=5.,fmax=60.,n_fft=1024,layout=layout);
print(layout.ids)
print(layout.kind)
print(layout.names);
print(layout.pos.shape)
% reset
import mne
mne.set_log_level('INFO')
data_path=mne.datasets.sample.data_path()+'\\MEG\\sample\\'
raw=mne.io.read_raw_fif(data_path+'sample_audvis_raw.fif')
raw.set_eeg_reference() # averageをEEGのreferenceにする
event_id={'auditory/left':1,'auditory/right':2,'visual/left':3,'visual/right':4,'smiley':5,'button':32}
events=mne.read_events(data_path+'sample_audvis_raw-eve.fif')
epochs=mne.Epochs(raw,events,event_id=event_id,tmin=-0.2,tmax=1.)
print(epochs.get_data().shape)
epochs.plot(block=True);
events=mne.pick_events(events,include=[5,32]); # 5,32のトリガーsmileyとbutton
print(events.T)
mne.viz.plot_events(events);
epochs['smiley'].plot(events=events);
print(raw.ch_names[278]);
epochs.plot_image(278,cmap='interactive');
epochs.plot_topo_image(vmin=-200,vmax=200,title='ERF images');
% reset
import numpy as np
import matplotlib.pyplot as plt
import mne
mne.set_log_level('INFO')
data_path=mne.datasets.sample.data_path()
fname=data_path+'\\MEG\\sample\\sample_audvis-ave.fif'
evoked=mne.read_evokeds(fname,baseline=(None,0),proj=True);
print(evoked);
evoked_l_aud=evoked[0]
evoked_r_aud=evoked[1]
evoked_l_vis=evoked[2]
evoked_r_vis=evoked[3]
fig=evoked_l_aud.plot(exclude=[]) # exclude=()でもOK
fig.tight_layout() # たぶんMATLABのaxis tight
picks=mne.pick_types(evoked_l_aud.info,meg=True,eeg=False,eog=False)
evoked_l_aud.plot(spatial_colors=True,gfp=True,picks=picks); # gfpはgrand field power
evoked_l_aud.plot_topomap();
times=np.arange(0.05,0.151,0.05)
evoked_r_aud.plot_topomap(times=times,ch_type='mag');
evoked_r_aud.plot_topomap(times=times,ch_type='grad');
evoked_r_aud.plot_topomap(times='peaks',ch_type='mag'); #適当にpeakでtopoを作成
evoked_r_aud.plot_topomap(times='peaks',ch_type='grad');
fig,ax=plt.subplots(1,5); # 返り値0番目がfigure 1番目がaxes MATLABでは別々に指定
evoked_l_aud.plot_topomap(times=0.1,axes=ax[0],show=False);
evoked_r_aud.plot_topomap(times=0.1,axes=ax[1],show=False);
evoked_l_vis.plot_topomap(times=0.1,axes=ax[2],show=False);
evoked_r_vis.plot_topomap(times=0.1,axes=ax[3],show=True); # colorbar もaxesを消費 colorbarは最後でないとダメ
ts_args=dict(gfp=True)
topomap_args=dict(sensors=False)
evoked_r_aud.plot_joint(title='right auditory',times=[0.07,0.105],ts_args=ts_args,topomap_args=topomap_args);
conditions=["Left Auditory","Right Auditory","Left visual","Right visual"] # Visualでなくvisual わざと文字列変換するようにしてある
evoked_dict=dict()
for condition in conditions:
evoked_dict[condition.replace(" ","/")]=mne.read_evokeds(fname,baseline=(None,0),proj=True,condition=condition)
print(evoked_dict);
colors=dict(Left='Crimson',Right='CornFlowerBlue');
linestyles=dict(Auditory='-',visual='--');
pick=evoked_dict['Left/Auditory'].ch_names.index('MEG 1811')
mne.viz.plot_compare_evokeds(evoked_dict,picks=pick,colors=colors,linestyles=linestyles);
evoked_r_aud.plot_image(picks=picks);
title='MNE sample data (condition : %s)'
evoked_l_aud.plot_topo(title=title % evoked_l_aud.comment);
colors='yellow','green','red','blue'
mne.viz.plot_evoked_topo(evoked,color=colors,title=title % 'Left/Right Auditory/Visual');
% matplotlib inline
subjects_dir=data_path+'\\subjects'
trans_fname=data_path+'\\MEG\\sample\\sample_audvis_raw-trans.fif'
maps=mne.make_field_map(evoked_l_aud,trans=trans_fname,subject='sample',subjects_dir=subjects_dir,n_jobs=1) # n_jpbs=2にするとエラー
field_map=evoked_l_aud.plot_field(maps,time=0.1)
三次元画像が出てくるはずなんですが・・・ 何も出てきませんでした。