示例#1
0
def load_edf_data_seizure_2(args):
    args = elecs.read_cmd_args(
        utils.Bag(
            subject=args.subject,
            atlas='laus125',
            function='create_raw_data_for_blender',
            task='seizure',
            bipolar=args.bipolar,
            raw_fname=op.join(
                ELECTRODES_DIR, args.subject[0], 'DMphaseIISz_TG.edf'
            ),  # '/cluster/neuromind/npeled/taha/dm04002705/edf/DMphaseIISz_TG.edf',
            start_time='00:00:00',
            seizure_onset='00:01:20',
            seizure_end='00:02:00',
            baseline_onset='00:00:00',
            baseline_end='00:01:00',
            lower_freq_filter=2,
            upper_freq_filter=70,
            power_line_notch_widths=5,
            ref_elec='PST1',
            normalize_data=False,
            calc_zscore=False,
            factor=1000,
            channels_names_mismatches='LFO=LIF'))
    pu.run_on_subjects(args, elecs.main)
示例#2
0
def create_ictal_clips(subject,
                       ictal_events_dict,
                       ictal_template,
                       overwrite=False,
                       n_jobs=4):
    mmvt_root = op.join(MMVT_DIR, subject, 'electrodes')
    data_files, baseline_files = [], []
    meta = utils.Bag(np.load(op.join(mmvt_root, 'electrodes_meta_data.npz')))
    for ictal_id, times in ictal_events_dict.items():
        output_fname = op.join(mmvt_root,
                               'electrodes_data_{}.npy'.format(ictal_id))
        baseline_fname = op.join(mmvt_root,
                                 'electrodes_baseline_{}.npy'.format(ictal_id))
        if op.isfile(output_fname) and op.isfile(
                baseline_fname) and not overwrite:
            data_files.append(output_fname)
            baseline_files.append(baseline_fname)
            continue
        event_fname = ictal_template.format(ictal_id=ictal_id)
        if not op.isfile(event_fname):
            print('Cannot find {}!'.format(event_fname))
            continue
        args = electrodes.read_cmd_args(
            utils.Bag(
                subject=subject,
                function='create_raw_data_from_edf',
                task='seizure',
                bipolar=False,
                raw_fname=event_fname,
                start_time=0,
                seizure_onset=times[0] - 5,
                seizure_end=times[0] + 5,  # times[1],
                baseline_onset=0,
                baseline_end=100,
                time_format='seconds',
                lower_freq_filter=1,
                upper_freq_filter=150,
                power_line_notch_widths=5,
                remove_baseline=False,
                normalize_data=False,
                factor=1000,
                overwrite_raw_data=True,
                n_jobs=n_jobs))
        electrodes.call_main(args)
        temp_output_fname = op.join(mmvt_root, 'electrodes_data_diff.npy')
        if op.isfile(temp_output_fname):
            os.rename(temp_output_fname, output_fname)
            data_files.append(output_fname)
        else:
            print('{}: no data!'.format(ictal_id))
        temp_baseline_fname = op.join(mmvt_root, 'electrodes_baseline.npy')
        if op.isfile(temp_baseline_fname):
            os.rename(temp_baseline_fname, baseline_fname)
            baseline_files.append(baseline_fname)
        else:
            print('{}: No baseline!'.format(ictal_id))
    meta_fname = op.join(mmvt_root, 'electrodes_meta_data_diff.npz')
    if op.isfile(meta_fname):
        os.rename(meta_fname, op.join(mmvt_root, 'electrodes_meta_data.npz'))
    return data_files, baseline_files
示例#3
0
def load_edf_data_seizure(args):
    args = elecs.read_cmd_args(
        utils.Bag(
            subject=args.subject,
            atlas='laus125',
            function='create_raw_data_from_edf',
            task='seizure',
            bipolar=args.bipolar,
            raw_fname=op.join(ELECTRODES_DIR, args.subject[0],
                              '{}.edf'.format(args.edf)),
            start_time='00:00:00',
            seizure_onset='00:01:20',
            seizure_end='00:02:00',
            baseline_onset='00:00:00',
            baseline_end='00:01:00',
            lower_freq_filter=1,
            upper_freq_filter=150,
            power_line_notch_widths=5,
            ref_elec='PST1',
            normalize_data=False,
            calc_zscore=False,
            factor=1000,
            # channels_names_mismatches='LFO=LIF'
        ))
    pu.run_on_subjects(args, elecs.main)
示例#4
0
def save_msit_single_trials_data(subject, bipolar):
    args = elecs.read_cmd_args(['-s', subject, '-b', str(bipolar)])
    args.task = 'MSIT'
    args.function = 'create_electrode_data_file'
    args.input_matlab_fname = 'electrodes_data_trials.mat'
    args.electrodes_names_field = 'electrodes'
    args.field_cond_template = '{}'
    elecs.main(subject, args)
示例#5
0
def save_msit_single_trials_data(subject, bipolar):
    args = elecs_preproc.read_cmd_args(['-s', subject, '-b', str(bipolar)])
    args.task = 'MSIT'
    args.function = 'create_electrode_data_file'
    args.input_matlab_fname = 'electrodes_data_trials.mat'
    args.electrodes_names_field = 'electrodes'
    args.field_cond_template = '{}'
    elecs_preproc.main(subject, args)
示例#6
0
def get_ras_from_mad(args):
    args = elecs.read_cmd_args(
        utils.Bag(
            subject=args.subject,
            function='get_ras_file',
            remote_ras_fol=
            '/mnt/cashlab/Original Data/MG/{subject}/{subject}_Notes_and_Images/{subject}_SurferOutput'
        ))
    pu.run_on_subjects(args, elecs.main)
示例#7
0
def load_edf_data_rest(args):
    args = elecs.read_cmd_args(
        utils.Bag(
            subject=args.subject,
            function='create_raw_data_for_blender',
            task='rest',
            bipolar=False,
            remove_power_line_noise=True,
            raw_fname='MG102_d3_Fri.edf',
            # rest_onset_time='6:50:00',
            # end_time='7:05:00',
            normalize_data=False,
            preload=False))
    pu.run_on_subjects(args, elecs.main)
示例#8
0
def calc_electrodes_power_spectrum(subject, edf_name, overwrite=False):
    elecs_args = electrodes.read_cmd_args(utils.Bag(
        subject=subject,
        function='create_raw_data_from_edf,calc_epochs_power_spectrum',
        task='rest',
        bipolar=False,
        remove_power_line_noise=True,
        raw_fname='{}.edf'.format(edf_name),
        normalize_data=False,
        preload=True,
        windows_length=10, # s
        windows_shift=5,
        # epochs_num=20,
        overwrite_power_spectrum=overwrite
    ))
    electrodes.call_main(elecs_args)
示例#9
0
def get_electrodes_file_from_server(args):
    args = elecs.read_cmd_args(
        utils.Bag(subject=args.subject,
                  function='prepare_subject_folder',
                  sftp=True,
                  sftp_username='******',
                  sftp_domain='door.nmr.mgh.harvard.edu',
                  remote_subject_dir=
                  '/space/thibault/1/users/npeled/subjects/{subject}'))
    # This line causes sometimes the sftp to hang, not sure why...
    args.sftp_password = utils.ask_for_sftp_password(args.sftp_username)
    for subject in args.subject:
        upper_subject = subject[:2].upper() + subject[2:]
        args.necessary_files['electrodes'] = \
            ['{}_RAS.{}'.format(upper_subject, file_type) for file_type in ['csv', 'xls', 'xlsx']] + \
            ['{}_RAS.{}'.format(subject, file_type) for file_type in ['csv', 'xls', 'xlsx']]
        pu.run_on_subjects(args, elecs.main)
示例#10
0
def load_electrodes_matlab_stim_file(args):
    from src.preproc import stim
    args = elecs.read_cmd_args(utils.Bag(subject=args.subject, bipolar=True))
    args = pu.add_default_args(args, {
        'error_radius': 3,
        'elec_length': 4,
        'file_frefix': ''
    })

    subject = args.subject[0]
    mat_fname = op.join(elecs.ELECTRODES_DIR, subject,
                        'MG106_LVF56_continuous.mat')
    d = mu.load_mat_to_bag(mat_fname)
    labels = mu.matlab_cell_str_to_list(d.Label)
    fs = d.fs[0][0]
    T = d.data.shape[1]
    # t1, t2 = 62000, 66000
    t1, t2 = T - 5 * fs, T  # Take last 5 seconds
    data = d.data[:, t1:t2]

    bad_electrodes = ['ROF04-05', 'ROF05-06', 'LPF14-NT']
    labels, data = elecs.remove_bad_channels(labels, data, bad_electrodes)
    data = data.reshape((*data.shape, 1))

    args.stim_channel = 'LVF05-LVF06'
    args.bipolar = '-' in args.stim_channel
    elecs.convert_electrodes_coordinates_file_to_npy(subject, bipolar=False)
    output_file = stim.create_stim_electrodes_positions(subject, args, labels)
    # First you need to run find_rois in electrodes_rois project:
    # python -m src.find_rois -s mg106 -b 1 --pos_fname '$MMVT/mg106/electrodes/electrodes_bipolar_stim_LVF04-LVF05_positions.npz' --output_postfix _stim_LVF04-LVF05
    # stim.set_labels_colors(subject, args, stim_dict=dict(labels=labels, data=data, conditions=['rest']))
    data_fname = op.join(
        elecs.MMVT_DIR, subject, 'electrodes',
        'electrodes{}_data.npy'.format('_bipolar' if args.bipolar else ''))
    meta_fname = op.join(
        elecs.MMVT_DIR, subject, 'electrodes',
        'electrodes{}_meta_data.npz'.format(
            '_bipolar' if args.bipolar else ''))
    np.save(data_fname, data)
    np.savez(meta_fname, names=labels, conditions=['rest'])
示例#11
0
def load_edf_data_seizure(args):
    args = elecs.read_cmd_args(
        utils.Bag(
            subject=args.subject,
            atlas='laus250',
            function='create_raw_data_for_blender',
            task='seizure',
            bipolar=False,
            raw_fname='Bakhamis_Amal_1.edf',
            start_time='00:01:34',
            # seizure_onset='00:03:33',
            seizure_onset='00:03:28',
            seizure_end='00:03:50',
            baseline_onset='00:01:34',
            baseline_end='00:03:11',
            lower_freq_filter=0.5,
            upper_freq_filter=70,
            power_line_notch_widths=5,
            ref_elec='CII',
            normalize_data=False,
            calc_zscore=False,
            factor=1000))
    pu.run_on_subjects(args, elecs.main)
示例#12
0
def load_electrodes_matlab_stim_file2(args):
    from src.preproc import stim
    args = elecs.read_cmd_args(utils.Bag(subject=args.subject, bipolar=True))
    args = pu.add_default_args(args, {
        'error_radius': 3,
        'elec_length': 4,
        'file_frefix': ''
    })

    subject = args.subject[0]
    mat_fname = op.join(elecs.ELECTRODES_DIR, subject, 'MG106_HGP_sess2_3.mat')
    d = mu.load_mat_to_bag(mat_fname)
    labels = mu.matlab_cell_str_to_list(d.Label)
    labels = [l.replace(' ', '-') for l in labels]
    labels = [
        '{0}{1}-{0}{2}'.format(*utils.elec_group_number(l, bipolar=True))
        for l in labels
    ]
    time = d.time2.squeeze()
    data = d.Data2
    data = data.reshape((*data.shape, 1))

    args.stim_channel = 'sess2'
    args.bipolar = '-' in labels[0]
    elecs.convert_electrodes_coordinates_file_to_npy(subject, bipolar=False)
    output_file = stim.create_stim_electrodes_positions(subject, args, labels)
    data_fname = op.join(
        elecs.MMVT_DIR, subject, 'electrodes',
        'electrodes{}_data.npy'.format('_bipolar' if args.bipolar else ''))
    meta_fname = op.join(
        elecs.MMVT_DIR, subject, 'electrodes',
        'electrodes{}_meta_data.npz'.format(
            '_bipolar' if args.bipolar else ''))
    np.save(data_fname, data)
    np.savez(meta_fname, names=labels, conditions=['rest'], time=time)
    print('Saving data in {} and {}'.format(data_fname, meta_fname))
示例#13
0
def read_electrodes_coordiantes_from_specific_xlsx_sheet(subject, bipolar):
    args = elecs.read_cmd_args(['-s', subject, '-b', str(bipolar)])
    args.ras_xls_sheet_name = 'RAS_Snapped'
    elecs.main(subject, args)
示例#14
0
def read_electrodes_coordiantes_from_specific_xlsx_sheet(subject, bipolar):
    args = elecs_preproc.read_cmd_args(['-s', subject, '-b', str(bipolar)])
    args.ras_xls_sheet_name = 'RAS_Snapped'
    elecs_preproc.main(subject, args)