Beispiel #1
0
# try BLOCK_PLOT = False if you have problems with plotting
BLOCK_PLOT = True

#### Cleaning data ###########################################################
for subs in [
        '202', '203', '204', '205', '206', '207', '208', '209', '211', '212'
]:

    subs_path = op.join(subject_dir, "sub-{}_task-hyper_eeg.fif".format(subs))

    combined_raw = mne.io.read_raw_fif(subs_path, preload=True).crop(
        tmax=300)  # TODO: remove the tmax=300 for the actual stuff

    # split the subjects and delete the raw file
    both_participants = split_raws(combined_raw)
    del combined_raw

    for sub_index, raw in enumerate(both_participants):
        subj_id = "sub-" + subs + "_p-" + str(sub_index)

        # set reference
        raw.set_eeg_reference(["Cz"])

        # filter ?
        raw.filter(l_freq=0.1, h_freq=120)
        raw.notch_filter(freqs=[16.666666667,
                                50])  # bandstop the train and power grid

        # mark the channels and save them
        mark_bads_and_save(raw, subj_id, sensor_map=True, block=BLOCK_PLOT)
connectivity_matrices = []
small_world_coeffs = []

# Perform the data analysis
for subj_pair in [
        '202', '203', '204', '205', '206', '207', '208', '209', '211', '212'
]:

    subs_path = subject_dir + "sub-{0}/eeg/sub-{0}_task-hyper_eeg.fif".format(
        subj_pair)
    behav_path = op.join(behav_dir, "{0}.csv".format(subj_pair))

    combined_raw = mne.io.read_raw_fif(subs_path, preload=True)

    # split the subjects and delete the raw file
    raws = split_raws(combined_raw)
    del combined_raw

    # apply the preprocessing
    for idx, raw in enumerate(raws):
        subj_idx = "sub-{0}_p-{1}".format(subj_pair, idx)
        raws[idx] = preprocess_single_sub(raw, subj_idx)

    # combine the subjects again
    raw_combined = combine_raws(raws[0], raws[1])
    del raws  # to save memory

    # do the behavioral analysis and get the epochs
    behavioral_df = calculate_alpha(pd.read_csv(behav_path))

    event_df = create_event_df(raw_combined)
from data_analysis.functions_connectivity import \
    full_ispc
from data_analysis.functions_preprocessing import \
    (combine_raws, split_raws, preprocess_single_sub, mark_bads_and_save,
     run_ica_and_save, BAD_COMP_PATH)

# Define the subjects and path you want to investigate
# Everything should run after you changed this path according to your computer
subs = "204"
path_to_fif = "/home/dirk/PycharmProjects/NBP_Hyperscanning/data/sub-" + subs + "_task-hyper_eeg.fif"

# read the raw file
raw = mne.io.read_raw_fif(path_to_fif, preload=True).crop(tmax=300)

# split the data into single subjects
sub1_raw, sub2_raw = split_raws(raw)
del raw  # to save memory

# preprocess all the subjects
for sub_index, raw in enumerate([sub1_raw, sub2_raw]):
    # create the subject id:
    subj_id = "test" + str(sub_index + 1)
    print("\n\n Preprocessing Subject {}\n\n".format(subj_id))

    # set the EEG reference. We use Cz as a reference
    raw.set_eeg_reference(["Cz"])

    # Apply high pass/low pass filter
    raw.filter(l_freq=0.1, h_freq=120)  # using firwin
    raw.notch_filter(freqs=[16.666666667,
                            50])  # bandstop the train and power grid