diff --git a/pipelines/1_preprocessing.py b/pipelines/1_preprocessing.py index fe8c367c..ac3dada5 100644 --- a/pipelines/1_preprocessing.py +++ b/pipelines/1_preprocessing.py @@ -23,17 +23,20 @@ subjects = config['subjects'] # noise reducer -refnotch = config['refnotch'] +refnotch = config['noise_reducer']['refnotch'] # filtering -flow = config['l_freq'] -fhigh = config['h_freq'] -unfiltered = config['unfiltered'] +flow = config['filtering']['l_freq'] +fhigh = config['filtering']['h_freq'] +unfiltered = config['filtering']['unfiltered'] +fi_method = config['filtering']['method'] +fir_design = config['filtering']['fir_design'] +phase = config['filtering']['phase'] # resampling -rsfreq = config['rsfreq'] +rsfreq = config['resampling']['rsfreq'] -# WIP: the state space file saves the parameters for the creation of each file +# TODO WIP: the state space file saves the parameters for the creation of each file state_space_fname = '_state_space_dict.pkl' ############################################################################### @@ -80,13 +83,9 @@ if raw_fname.endswith('bcc-raw.fif') or raw_fname.endswith('bcc-empty.fif'): - method = 'fir' - fir_design = 'firwin' - phase = 'zero' - raw = mne.io.Raw(op.join(dirname, raw_fname), preload=True) - raw_filt = raw.filter(flow, fhigh, method=method, n_jobs=1, + raw_filt = raw.filter(flow, fhigh, method=fi_method, n_jobs=1, fir_design=fir_design, phase=phase) if raw_fname.endswith('-raw.fif'): @@ -97,7 +96,7 @@ fi_dict = dict() fi_dict['flow'] = flow fi_dict['fhigh'] = fhigh - fi_dict['method'] = method + fi_dict['method'] = fi_method fi_dict['fir_design'] = fir_design fi_dict['phase'] = phase fi_dict['output_file'] = raw_filt_fname diff --git a/pipelines/2_artifact_rejection.py b/pipelines/2_artifact_rejection.py index adf4640d..0fee1ca2 100644 --- a/pipelines/2_artifact_rejection.py +++ b/pipelines/2_artifact_rejection.py @@ -20,20 +20,20 @@ subjects = config['subjects'] -ecg_ch = config['ecg_ch'] -eog_hor_ch = config['eog_hor_ch'] -eog_ver_ch = config['eog_ver_ch'] - -flow_ecg = config['flow_ecg'] -fhigh_ecg = config['fhigh_ecg'] -flow_eog = config['flow_eog'] -fhigh_eog = config['fhigh_eog'] - -ecg_thresh = config['ecg_thresh'] -eog_thresh = config['eog_thresh'] -use_jumeg = config['use_jumeg'] -random_state = config['random_state'] -unfiltered = config['unfiltered'] +ecg_ch = config['ica']['ecg_ch'] +eog_hor_ch = config['ica']['eog_hor_ch'] +eog_ver_ch = config['ica']['eog_ver_ch'] + +flow_ecg = config['ica']['flow_ecg'] +fhigh_ecg = config['ica']['fhigh_ecg'] +flow_eog = config['ica']['flow_eog'] +fhigh_eog = config['ica']['fhigh_eog'] + +ecg_thresh = config['ica']['ecg_thresh'] +eog_thresh = config['ica']['eog_thresh'] +use_jumeg = config['ica']['use_jumeg'] +random_state = config['ica']['random_state'] +unfiltered = config['ica']['unfiltered'] pre_proc_ext = config['pre_proc_ext'] diff --git a/pipelines/3_prepare_epochs.py b/pipelines/3_prepare_epochs.py index 91e1d6f2..d8676bb9 100644 --- a/pipelines/3_prepare_epochs.py +++ b/pipelines/3_prepare_epochs.py @@ -31,7 +31,7 @@ for cond in config['conditions']: print(cond) - # you may want to use glob etc. to avoid having to write down all file names in the config + # TODO: may want to use glob etc. to avoid having to write down all file names in the config for fname in config[cond]['raw_fnames']: subject = fname.split('_')[0] raw_fname = op.join(recordings_dir, subject, fname) @@ -44,7 +44,7 @@ # get channel with events stim_channel = config[cond]['ch_name'] - event_id = config['event_id'] + event_id = config[cond]['event_id'] # get tmin, tmax for epoch creation tmin, tmax = config[cond]['tmin'], config[cond]['tmax'] diff --git a/pipelines/4_covariance_matrices.py b/pipelines/4_covariance_matrices.py index d155da10..bf98b5c6 100644 --- a/pipelines/4_covariance_matrices.py +++ b/pipelines/4_covariance_matrices.py @@ -27,10 +27,10 @@ subjects = config['subjects'] l_freq, h_freq = config['l_freq'], config['h_freq'] pre_proc_ext = config['pre_proc_ext'] -unfiltered = config['unfiltered'] -compute_empty_cov = True -compute_epo_cov = True +compute_empty_cov = config['cov_matrices']['compute_empty_cov'] +compute_epo_cov = config['cov_matrices']['compute_epo_cov'] +unfiltered = config['cov_matrices']['unfiltered'] ############################################################################### # Compute noise covariance matrix based on empty room measurements diff --git a/pipelines/5_setup_source_localization.py b/pipelines/5_setup_source_localization.py index ed75ee9a..d8fff355 100644 --- a/pipelines/5_setup_source_localization.py +++ b/pipelines/5_setup_source_localization.py @@ -50,8 +50,8 @@ mri_dir = '/mri/orig/001.mgz' nii_fname = '_1x1x1mm.nii' -mne_bin_path = '/Users/kiefer/mne/MNE-2.7.3-3268-MacOSX-i386/bin/' # Path to MNE-C binary files -freesurfer_home = '/Users/kiefer/mne/freesurfer/' +mne_bin_path = config['mne_bin_path'] +freesurfer_home = config['freesurfer_home'] freesurfer_bin = freesurfer_home + 'bin/' # determiny granularity of source space diff --git a/pipelines/6_do_source_localization.py b/pipelines/6_do_source_localization.py index fab764e9..3f16dcad 100644 --- a/pipelines/6_do_source_localization.py +++ b/pipelines/6_do_source_localization.py @@ -33,18 +33,19 @@ # subject list subjects = config['subjects'] -n_jobs = config['n_jobs'] pre_proc_ext = config['pre_proc_ext'] # inverse solution -method = config['inv_method'] -snr = config['snr'] +method = config['source_loc']['inv_method'] +n_jobs = config['source_loc']['n_jobs'] +snr = config['source_loc']['snr'] lambda2 = 1.0 / snr ** 2 -do_inv_epo = False + +do_inv_epo = config['source_loc']['do_inv_epo'] # plotting stc -plot_stc = True -time_viewer = True +plot_stc = config['source_loc']['plot_stc'] +time_viewer = config['source_loc']['time_viewer'] ############################################################################### # Calculate forward and inverse solution diff --git a/pipelines/config_file.yaml b/pipelines/config_file.yaml index c02199eb..6a01a6d8 100644 --- a/pipelines/config_file.yaml +++ b/pipelines/config_file.yaml @@ -3,28 +3,55 @@ version: 'v0.1' +############################################################################### +# subject list +############################################################################### + +subjects: ['101611'] + +############################################################################### # directories +############################################################################### + basedir: '/path/to/jusample' -subjects: ['101611'] recordings_dir: 'recordings' subjects_dir: 'subjects' plot_dir: 'plots' +# Path to MNE-C binary files +mne_bin_path: '/Users/kiefer/mne/MNE-2.7.3-3268-MacOSX-i386/bin/' +freesurfer_home: '/Users/kiefer/mne/freesurfer/' + ############################################################################### # pre-processing settings ############################################################################### # noise reducer -refnotch: [50., 100., 150., 200., 250., 300., 350., 400., - 60., 120., 180., 240., 360.] +noise_reducer: + # low pass filter for reference channels, default 5.0 Hz + reflp: 5. + # high pass filter for reference channels, default 0.1 Hz + refhp: 0.1 + # TODO: check if comment is correct -> Eberhard + # Names of the reference channels for high pass filter + noiseref_hp: ['RFG ...'] + # frequencies for notch filter (for power line noise, projector, etc.) + refnotch: [50., 100., 150., 200., 250., 300., 350., 400., + 60., 120., 180., 240., 360.] # filtering -l_freq: 1.0 -h_freq: 45. -unfiltered: True +filtering: + l_freq: 1.0 + h_freq: 45. + method: 'fir' + fir_design: 'firwin' + phase: 'zero' + # create files for unfiltered data as well + unfiltered: True # resampling -rsfreq: 250 +resampling: + rsfreq: 250 # file name extension with the pre-processing steps pre_proc_ext: ',nr,bcc,fibp,rs' @@ -33,39 +60,32 @@ pre_proc_ext: ',nr,bcc,fibp,rs' # ica settings ############################################################################### -ecg_ch: 'ECG 001' -eog_hor_ch: 'EOG 001' -eog_ver_ch: 'EOG 002' +ica: + ecg_ch: 'ECG 001' + eog_hor_ch: 'EOG 001' + eog_ver_ch: 'EOG 002' -flow_ecg: 8 -fhigh_ecg: 20 -flow_eog: 1 -fhigh_eog: 20 + flow_ecg: 8 + fhigh_ecg: 20 + flow_eog: 1 + fhigh_eog: 20 -ecg_thresh: 0.3 -eog_thresh: 0.3 -use_jumeg: True -random_state: 42 + ecg_thresh: 0.3 + eog_thresh: 0.3 + use_jumeg: True + random_state: 42 ############################################################################### -# +# conditions ############################################################################### conditions: ['stim'] -n_jobs: 1 -event_id: 1 - -snr: 1 -inv_method: 'MNE' - -snr_list: 3 -inv_methods: ['MNE', 'dSPM'] - stim: ch_name: 'STI 014' tmin: -0.4 tmax: 0.6 + event_id: 1 raw_fnames: [ '101611_CAU01A_100706_1430_1_c,rfDC,t1,n,meeg,nr,bcc,fibp,rs,ar-raw.fif', '101611_CAU01A_100706_1430_1_c,rfDC,t1,n,meeg,nr,bcc,rs,ar-raw.fif' @@ -74,6 +94,7 @@ paced: ch_name: 'STI 013' tmin: -0.4 tmax: 0.6 + event_id: 1 raw_fnames: [ '101611_CAU01A_100706_1429_1_c,rfDC,t1,n_bcc,nr,ar-raw.fif' ] @@ -81,10 +102,41 @@ both: ch_name: 'STI 014' tmin: -0.4 tmax: 0.6 + event_id: 1 raw_fnames: [ '101611_CAU01A_100706_1430_2_c,rfDC,t1,n_bcc,nr,ar-raw.fif' ] +############################################################################### +# covariance matrices +############################################################################### + +cov_matrices: + # compute covariance matrix based on empty room measurement + compute_empty_cov: True + # compute covariance matrix based on epochs + compute_epo_cov: True + # compute covariance matrix for filtered (False) or unfiltered (True) data + unfiltered: False + +############################################################################### +# source localization +############################################################################### + +source_loc: + n_jobs: 1 + snr: 1 + inv_method: 'MNE' + + do_inv_epo: False + + plot_stc: True + time_viewer: True + +############################################################################### +# other (unused atm) +############################################################################### + label_names: ['bankssts-lh', 'bankssts-rh', 'caudalanteriorcingulate-lh', 'caudalanteriorcingulate-rh', 'caudalmiddlefrontal-lh', diff --git a/pipelines/utils.py b/pipelines/utils.py index 38508875..a971dd76 100644 --- a/pipelines/utils.py +++ b/pipelines/utils.py @@ -115,7 +115,6 @@ def noise_reduction(dirname, raw_fname, denoised_fname, refnotch, state_space_fn # plot final plotting plot_name = denoised_fname.rsplit('-raw.fif')[0] + '-plot' - # TODO: fix plot_denoising plot_denoising([op.join(dirname, raw_fname), op.join(dirname, denoised_fname)], n_jobs=1, fnout=op.join(dirname, plot_name), show=False)