Skip to content

Commit

Permalink
Merge pull request #192 from ckiefer0/master
Browse files Browse the repository at this point in the history
pipelines: added for each analysis step a sub category in the config file
  • Loading branch information
ckiefer0 authored Mar 27, 2019
2 parents 7398b23 + 99bee9b commit 28c3286
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 68 deletions.
23 changes: 11 additions & 12 deletions pipelines/1_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

###############################################################################
Expand Down Expand Up @@ -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'):
Expand All @@ -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
Expand Down
28 changes: 14 additions & 14 deletions pipelines/2_artifact_rejection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
4 changes: 2 additions & 2 deletions pipelines/3_prepare_epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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']
Expand Down
6 changes: 3 additions & 3 deletions pipelines/4_covariance_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pipelines/5_setup_source_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions pipelines/6_do_source_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
108 changes: 80 additions & 28 deletions pipelines/config_file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -74,17 +94,49 @@ 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'
]
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',
Expand Down
1 change: 0 additions & 1 deletion pipelines/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 28c3286

Please sign in to comment.