-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07-epoch.py
More file actions
38 lines (27 loc) · 1.76 KB
/
Copy path07-epoch.py
File metadata and controls
38 lines (27 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import mne
import os.path as op
from config_AVTest import MEG_data_path,group_name,Ids,bids_root
from mne.preprocessing import read_ica
import numpy as np
import pandas as pd
from mne_bids import BIDSPath
task='AVTest'
day=200
for subject_id in Ids:
subject = group_name+"%d" % subject_id
print("processing subject: %s" % subject)
fname=op.join(MEG_data_path,subject,task+'_%d'%(day+subject_id)+'_tsss_mc.fif')
bids_path = BIDSPath(subject='%02d'%(subject_id), session='day2', task='AVTest', suffix='meg', datatype='meg', processing='tsss', extension='.fif', root=bids_root)
raw_tsss_mc=mne.io.read_raw_fif(bids_path.fpath,preload=True)
raw_tsss_mc.filter(l_freq=0.1, h_freq=40.0,fir_design='firwin') # low-pass filter data
ica = read_ica(fname.replace("_tsss_mc", "-ica"))
ica.exclude = np.load(fname.replace("tsss_mc.fif",'ICA_excludes_EOG_EKG.npy')).tolist() #EOG_EKG
raw_tsss_mc = ica.apply(raw_tsss_mc, exclude=ica.exclude)
df=pd.read_csv(fname.replace('tsss_mc.fif','events_with_artifacts_marked.csv'))
df=df[df['artifacts']==False]
events = df[["stim_onset", "button_press", "trigger_code"]].astype(int).values
picks = mne.pick_types(raw_tsss_mc.info, meg=True, eeg=False, stim=False, eog=True,exclude='bads')
epochs = mne.Epochs(raw_tsss_mc, events, event_id=None, tmin=-0.2, tmax=1.0, picks=picks, baseline=(None,0), preload=True,reject=None,proj=True,metadata=df)
# picks=mne.pick_channels(epochs.ch_names,[epochs.ch_names[0]]+epochs.ch_names[1::9]+epochs.ch_names[5::9]+epochs.ch_names[6::9])
# epochs.plot(n_channels=103,n_epochs=40,block = True,picks=picks, scalings='auto')
epochs.save(fname.replace("_tsss_mc", "-epo"),overwrite=True)