Exemplo n.º 1
0
def baseline_GA(subject, subjects1, KIND):
    #set baseline == 'fixation_cross_norisks' and GA_correction = True to build a well-behaved baseline for additional substraction in GA (remove trend this way)
    run_counter = 0
    fpath_events = '/home/asmyasnikova83/DATA/mio_out_{0}/{1}_run{2}_mio_corrected_{3}{4}{5}.txt'
    fpath_raw = '/net/server/data/Archive/prob_learn/vtretyakova/ICA_cleaned/{}/run{}_{}_raw_ica.fif'

    for run in runs:
        rf = fpath_events.format(KIND, subject, run, stimulus, KIND, train)
        file = pathlib.Path(rf)
        if file.exists() and os.stat(rf).st_size != 0:
            run_counter = run_counter + 1
            print('run_counter', run_counter)

    SUBJ_BASE = np.zeros(204)
    BASE = np.zeros((run_counter, 204))
    ind = 0
    for run in runs:
        rf = fpath_events.format(KIND, subject, run, stimulus, KIND, train)
        file = pathlib.Path(rf)
        if file.exists() and os.stat(rf).st_size != 0:
            raw_file = fpath_raw.format(subject, run, subject)
            raw_data = mne.io.Raw(raw_file, preload=True)
            #filter 1-50 Hz
            raw_data = raw_data.filter(
                None, 50, fir_design='firwin'
            )  # for low frequencies, below the peaks of power-line noise low pass filter the data
            raw_data = raw_data.filter(
                1., None, fir_design='firwin')  #remove slow drifts
            picks = mne.pick_types(raw_data.info, meg='grad')
            events_with_cross, events_of_interest = retrieve_events_for_baseline(
                raw_data, rf, KIND, subject, run, picks)
            print('\n\nEvents with cross extracted!')
            BASELINE, b_line = compute_baseline_substraction_and_power(
                raw_data, events_with_cross, events_of_interest, picks)
            print('\n\nDone with the BASELINE I!')
            if BASELINE.all == 0:
                print('Yes, BASELINE is dummy')
                continue
            ind = ind + 1
            print('Baseline shape', BASELINE.shape)
            #average over epochs
            BASELINE = np.mean(BASELINE, axis=1)
            print('Baseline new shape', BASELINE.shape)
            print('ind', ind)
            #put here baseline for each run
            BASE[ind - 1, 0:204] = BASELINE
    print('BASE', BASE)
    #average baseline over runs/blocks
    SUBJ_BASE = np.mean(BASE, axis=0)
    print('SUBJ BASE', SUBJ_BASE)
    #prepare for further baseline correction
    SUBJ_BASE = np.matlib.repmat(SUBJ_BASE, int(time.shape[0]), 1)
    SUBJ_BASE = np.transpose(SUBJ_BASE)
    print('SUBJ BASE shape', SUBJ_BASE.shape)

    return SUBJ_BASE
Exemplo n.º 2
0
for run in runs:
    for subject in subjects:
        rf = fpath_events.format(subject, run)
        file = pathlib.Path(rf)
        if file.exists():
            print('This file is being processed: ', rf)
            if mode == 'server':
                raw_file = fpath_raw.format(subject, run, subject)
            else:
                raw_file = fpath_raw.format(subject, run)
            raw_data = mne.io.Raw(raw_file, preload=True)
            raw_data = raw_data.filter(None, 50, fir_design='firwin') # for low frequencies, below the peaks of power-line noise low pass filter the data
            raw_data = raw_data.filter(1., None, fir_design='firwin') #remove slow drifts           
            picks = mne.pick_types(raw_data.info, meg = True)
            events_with_cross, events_of_interest = retrieve_events_for_baseline(raw_data, rf, picks)
            print('Done with the events!')
            BASELINE, b_line = compute_baseline_substraction_and_power(raw_data, events_with_cross, picks)
            print('\n\nDone with the BASELINE I!')
            CORRECTED_DATA = correct_baseline_substraction(BASELINE, events_of_interest, raw_data, picks)
            print('\n\nDone with the CORRECTED!')
            plot_created_epochs_evoked = False
            epochs_of_interest, evoked = create_mne_epochs_evoked(kind, subject, run, CORRECTED_DATA, events_of_interest, plot_created_epochs_evoked, raw_data, picks)
            evoked_ave.append(evoked)
        else:
            print('This file: ', rf, 'does not exit')
            continue

grand_averages = mne.grand_average(evoked_ave)
if batterfly:
    GA = grand_averages.plot(spatial_colors=True, gfp=True, picks=picks, show=False)