def task_epoch_data():
        """Step 03: Epoch continuuous data 
        Takes in the data filtered at step 02, adds in the events and epoch the data.
        
        
        """
        
        for subj in subject_ids:
            for task in tasks:
                for sess in n_sessions:
                    if sess in exclude_sessions:
                        continue
                    else:
                        
                              
            
                        filt_fname=fname.filt(subject='sub-'+ str(subj).zfill(2), 
                                                  session='ses-'+ str(sess).zfill(2), 
                                                  task='task-'+ task, 
                                                  fmin= bandpass_fmin, 
                                                  fmax= bandpass_fmax)
                        
                        epochs_fname=fname.epochs(subject='sub-'+ str(subj).zfill(2), 
                                                  session='ses-'+ str(sess).zfill(2), 
                                                  task='task-'+ task, 
                                                  )
                    
                        yield dict(
                                name = "%s-%s" % (subj, sess), 
                                file_dep =[filt_fname, '03_filter-continuuous-data.py'], 
                                targets=[epochs_fname], 
                                actions=['python3 04_epoch-data.py %s %s %s' % (subj, sess, task)],
                                                                                 
                                
                                )
def task_filter_continuuous():
        """Step 02: Filter continuuous data 
        Takes in the raw data and apply a filter
        
        """
        
        for subj in subject_ids:
            for task in tasks:
                for sess in n_sessions:
                    if sess in exclude_sessions:
                        continue
                    else:
                        
                        raw_fname = fname.raw(subject='sub-'+ str(subj).zfill(2), 
                                   session='ses-'+ str(sess).zfill(2), 
                                   task='task-'+ task)
            
            
                        filt_fname=fname.filt(subject='sub-'+ str(subj).zfill(2), 
                                                  session='ses-'+ str(sess).zfill(2), 
                                                  task='task-'+ task, 
                                                  fmin= bandpass_fmin, 
                                                  fmax= bandpass_fmax)
                        
                    
                        yield dict(
                                name = "%s-%s" % (subj, sess), 
                                file_dep =[raw_fname, '03_filter-continuuous-data.py'], 
                                targets=[filt_fname], 
                                actions=['python3 03_filter-continuuous-data.py %s %s %s' % (subj, sess, task)],
                                                                                 
                                
                                )
Beispiel #3
0
def task_ica():
    """Step 03: Use ICA to clean up ECG and EOG artifacts"""
    for subject in subjects:
        filt_fnames = [fname.filt(subject=subject, run=run,
                                  fmin=bandpass_fmin, fmax=bandpass_fmax)
                       for run in range(1, 7)]
        ica_fname = fname.ica(subject=subject)

        yield dict(
            name=subject,
            task_dep=['filter'],
            file_dep=filt_fnames + ['03_ica.py'],
            targets=[ica_fname],
            actions=['python 03_ica.py %s' % subject],
        )
Beispiel #4
0
def task_filter():
    """Step 02: Bandpass-filter the data"""
    for subject in subjects:
        sss_fnames = [fname.sss(subject=subject, run=run) for run in range(1, 7)]
        filt_fnames = [fname.filt(subject=subject, run=run,
                                  fmin=bandpass_fmin, fmax=bandpass_fmax)
                       for run in range(1, 7)]

        yield dict(
            name=subject,
            task_dep=['anatomy'],
            file_dep=sss_fnames + ['02_filter.py'],
            targets=filt_fnames,
            actions=['python 02_filter.py %s' % subject],
        )
Beispiel #5
0
def task_epochs():
    """Step 04: Cut the data into epochs"""
    for subject in subjects:
        filt_fnames = [fname.filt(subject=subject, run=run,
                                  fmin=bandpass_fmin, fmax=bandpass_fmax)
                       for run in range(1, 7)]
        ica_fname = fname.ica(subject=subject)
        epo_fname = fname.epo(subject=subject)

        yield dict(
            name=subject,
            task_dep=['ica'],
            file_dep=filt_fnames + [ica_fname, '04_epochs.py'],
            targets=[epo_fname],
            actions=['python 04_epochs.py %s' % subject],
        )
Beispiel #6
0
    # Bandpass the data.
    raw_filt = raw.copy().filter(
        bandpass_fmin, bandpass_fmax, l_trans_bandwidth='auto',
        h_trans_bandwidth='auto', filter_length='auto', phase='zero',
        fir_window='hamming', fir_design='firwin', n_jobs=n_jobs)

    # Highpass the EOG channels to > 1Hz, regardless of the bandpass-filter
    # applied to the other channels
    picks_eog = mne.pick_types(raw_filt.info, meg=False, eog=True)
    raw_filt.filter(
        1., None, picks=picks_eog, l_trans_bandwidth='auto',
        filter_length='auto', phase='zero', fir_window='hann',
        fir_design='firwin', n_jobs=n_jobs)

    f = fname.filt(subject=subject, run=run,
                   fmin=bandpass_fmin, fmax=bandpass_fmax)
    raw_filt.save(f, overwrite=True)

    # Make a plot of the PSD before and after filtering
    figs_before.append(raw.plot_psd(show=False))
    figs_after.append(raw_filt.plot_psd(show=False))

# Append PDF plots to report
report = get_report(subject)
report.add_slider_to_section(
    figs_before,
    ['PSD before filtering: run %d' % i for i in range(1, 7)],
    title='PSD before filtering',
    section='Sensor-level'
)
report.add_slider_to_section(
Beispiel #7
0
args = parser.parse_args()
subj = args.subject
sess = args.session
task = args.task

print('Process data for subject:', subj, 'session:', sess)

subject = 'sub-' + str(subj).zfill(2)
session = 'ses-' + str(sess).zfill(2)
task = 'task-' + task

# load the data
raw = mne.io.read_raw_fif(fname.filt(subject=subject,
                                     session=session,
                                     task=task,
                                     fmin=bandpass_fmin,
                                     fmax=bandpass_fmax),
                          preload=True)

#------------------------------------------
# Insert events from spreadsheet in raw
#------------------------------------------
# specify the trial type
df_spreadsheet['trial'] = np.where(df_spreadsheet['Grade'] != 'NF Blink', 'F',
                                   'NF')
df_spreadsheet['Door'] = df_spreadsheet['Door'].replace(np.nan, 'NF')

df_spreadsheet['trial_type'] = df_spreadsheet['trial'] + '/' + df_spreadsheet[
    'Grade'] + '/' + df_spreadsheet['Door']
#df_spreadsheet['trial_type']=df_spreadsheet['trial_type'].replace(np.nan, 'NF')
Beispiel #8
0
from config import (fname, events_id, epoch_tmin, epoch_tmax, baseline,
                    bandpass_fmin, bandpass_fmax, reject)

# Be verbose
mne.set_log_level('INFO')

# Handle command line arguments
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('subject', metavar='sub###', help='The subject to process')
args = parser.parse_args()
subject = args.subject
print('Processing subject:', subject)

# Construct a raw object that will load the bandpass-filtered data.
raw = mne.io.read_raw_fif(fname.filt(subject=subject,
                                     run=1,
                                     fmin=bandpass_fmin,
                                     fmax=bandpass_fmax),
                          preload=False)
for run in range(2, 7):
    raw.append(
        mne.io.read_raw_fif(fname.filt(subject=subject,
                                       run=run,
                                       fmin=bandpass_fmin,
                                       fmax=bandpass_fmax),
                            preload=False))

# Read events from the stim channel
mask = 4096 + 256  # mask for excluding high order bits
events = mne.find_events(raw,
                         stim_channel='STI101',
                         consecutive='increasing',


print('Filter data for subject:', subj, 'session:', sess)

subject='sub-'+ str(subj).zfill(2)
session='ses-'+ str(sess).zfill(2)
task='task-'+ task


# load raw data 
raw = mne.io.read_raw_brainvision(fname.raw(
                                   subject=subject, 
                                   session=session,
                                   task= task),  preload=True)  

filt_raw = raw.copy()


# specify the filter
filt_raw.load_data().filter(l_freq=bandpass_fmin, h_freq=bandpass_fmax, l_trans_bandwidth='auto',
        h_trans_bandwidth='auto', filter_length='auto', phase='zero',
        fir_window='hamming', fir_design='firwin')


# save the filtered data
f=fname.filt(subject = subject, session= session, task= task, fmin=bandpass_fmin, fmax=bandpass_fmax)

filt_raw.save(f, overwrite = True)