示例#1
0
def calc_msit(args):
    # python -m src.preproc.meg -s ep001 -m mg78 -a laus250 -t MSIT
    #   --contrast interference --t_max 2 --t_min -0.5 --data_per_task 1 --read_events_from_file 1
    #   --events_file_name {subject}_msit_nTSSS_interference-eve.txt --cleaning_method nTSSS
    args = meg.read_cmd_args(
        dict(
            subject=args.subject,
            mri_subject=args.mri_subject,
            task='MSIT',
            function=args.real_function,
            data_per_task=True,
            atlas='laus250',
            contrast='interference',
            cleaning_method='nTSSS',
            t_min=-0.5,
            t_max=2,
            # calc_epochs_from_raw=True,
            read_events_from_file=True,
            # remote_subject_meg_dir='/autofs/space/sophia_002/users/DARPA-MEG/project_orig_msit',
            events_file_name='{subject}_msit_nTSSS_interference-eve.txt',
            reject=False,
            # save_smoothed_activity=True,
            # stc_t=1189,
            morph_to_subject='fsaverage5',
            extract_mode=['mean_flip', 'mean', 'pca_flip']))
    meg.call_main(args)
示例#2
0
def calc_rest(args):
    # '-s hc029 -a laus125 -t rest -f calc_evoked,make_forward_solution,calc_inverse_operator --reject 0 --remove_power_line_noise 0 --windows_length 1000 --windows_shift 500 --remote_subject_dir "/autofs/space/lilli_001/users/DARPA-Recons/hc029"''
    # '-s hc029 -a laus125 -t rest -f calc_stc,calc_labels_avg_per_condition --single_trial_stc 1 --remote_subject_dir "/autofs/space/lilli_001/users/DARPA-Recons/hc029"'
    # '-s subject-name -a atlas-name -t rest -f rest_functions' --l_freq 8 --h_freq 13 --windows_length 500 --windows_shift 100
    args = meg.read_cmd_args(dict(
        subject=args.subject,
        mri_subject=args.mri_subject,
        atlas='laus125',
        function='rest_functions',
        task='rest',
        cleaning_method='tsss',
        reject=False, # Should be True here, unless you are dealling with bad data...
        remove_power_line_noise=True,
        l_freq=3, h_freq=80,
        windows_length=500,
        windows_shift=100,
        inverse_method='MNE',
        remote_subject_dir='/autofs/space/lilli_001/users/DARPA-Recons/{subject}',
        # This properties are set automatically if task=='rest'
        # calc_epochs_from_raw=True,
        # single_trial_stc=True,
        # use_empty_room_for_noise_cov=True,
        # windows_num=10,
        # baseline_min=0,
        # baseline_max=0,
    ))
    meg.call_main(args)
示例#3
0
def calc_meg_epochs(args):
    empty_fnames, cors, days = get_empty_fnames(args.subject[0], args.tasks,
                                                args)
    times = (-2, 4)
    for task in args.tasks:
        args = meg.read_cmd_args(
            dict(subject=args.subject,
                 mri_subject=args.subject,
                 task=task,
                 remote_subject_dir=
                 '/autofs/space/lilli_001/users/DARPA-Recons/{subject}',
                 get_task_defaults=False,
                 fname_format='{}_{}_nTSSS-ica-raw'.format(
                     '{subject}', task.lower()),
                 empty_fname=empty_fnames[task],
                 function='calc_epochs,calc_evokes',
                 conditions=task.lower(),
                 data_per_task=True,
                 normalize_data=False,
                 t_min=times[0],
                 t_max=times[1],
                 read_events_from_file=False,
                 stim_channels='STI001',
                 use_empty_room_for_noise_cov=True,
                 n_jobs=args.n_jobs))
        meg.call_main(args)
示例#4
0
def calc_mne_python_sample_data(args):
    import mne
    mne_sample_data_fol = mne.datasets.sample.data_path()
    trans_fname = op.join(mne_sample_data_fol, 'MEG', 'sample',
                          'sample_audvis_raw-trans.fif')

    args = meg.read_cmd_args(
        dict(
            subject=args.subject,
            mri_subject=args.mri_subject,
            function='read_sensors_layout,calc_evokes',
            # atlas='laus250',
            contrast='audvis',
            task='audvis',
            trans_fname=trans_fname,
            fname_format='{subject}_audvis-{ana_type}.{file_type}',
            fname_format_cond='{subject}_audvis_{cond}-{ana_type}.{file_type}',
            conditions=['LA', 'RA'],
            read_events_from_file=True,
            t_min=-0.2,
            t_max=0.5,
            extract_mode=['mean_flip'],  #, 'mean', 'pca_flip'],
            overwrite_epochs=args.overwrite,
            overwrite_evoked=True,
            overwrite_sensors=True))
    meg.call_main(args)
示例#5
0
def _calc_pvals_fMRI_clusters(p, extract_time_series_for_clusters=False):
    subject, overwrite = p
    stc_name = 'dSPM_mean_flip_vertices_power_spectrum_stat'
    if not utils.both_hemi_files_exist(
            op.join(MMVT_DIR, subject, 'meg', '{}-{}.stc'.format(
                stc_name, '{hemi}'))):
        print('{}: Can\'t find {}!'.format(subject, stc_name))
        return False
    args.subject = subject
    clusters_root_fol = utils.make_dir(
        op.join(MMVT_DIR, subject, 'meg', 'clusters'))
    res_fname = op.join(
        clusters_root_fol,
        'clusters_labels_dSPM_mean_flip_vertices_power_spectrum_stat.pkl')
    if not op.isfile(res_fname) or args.overwrite:
        utils.delete_folder_files(clusters_root_fol)
        _args = meg.read_cmd_args(
            dict(subject=subject,
                 mri_subject=subject,
                 atlas='MSIT_I-C',
                 function='find_functional_rois_in_stc',
                 stc_name=stc_name,
                 threshold=-np.log10(0.01),
                 threshold_is_precentile=False,
                 extract_time_series_for_clusters=False,
                 save_func_labels=True,
                 calc_cluster_contours=True,
                 n_jobs=args.n_jobs))
        try:
            meg.call_main(_args)
        except:
            print(traceback.format_exc())
        if not op.isfile(res_fname):
            print('Cluster output can\'t be found!')
            return False
示例#6
0
def calc_msit(args):
    # python -m src.preproc.meg -s ep001 -m mg78 -a laus250 -t MSIT
    #   --contrast interference --t_max 2 --t_min -0.5 --data_per_task 1 --read_events_from_file 1
    #   --events_fname {subject}_msit_nTSSS_interference-eve.txt --cleaning_method nTSSS
    args = meg.read_cmd_args(dict(
        subject=args.subject,
        mri_subject=args.mri_subject,
        task='MSIT',
        # function=args.real_function,
        function='read_sensors_layout,calc_epochs,calc_evokes,calc_stc,calc_labels_avg_per_condition,calc_labels_min_max',
        data_per_task=True,
        atlas=args.atlas,
        contrast='interference',
        cleaning_method='nTSSS',
        t_min=-0.5,
        t_max=2,
        # calc_epochs_from_raw=True,
        read_events_from_file=True,
        # remote_subject_meg_dir='/autofs/space/sophia_002/users/DARPA-MEG/project_orig_msit',
        events_fname='{subject}_msit_nTSSS_interference-eve.txt',
        reject=False,
        # save_smoothed_activity=True,
        # stc_t=1189,
        morph_to_subject = 'fsaverage5',
        extract_mode=['mean_flip'], #, 'mean', 'pca_flip'],
        pick_ori='normal',
        overwrite_epochs=False,
        overwrite_evoked=True,
        overwrite_stc=False,
        overwrite_labels_data=False,
        overwrite_sensors=False
    ))
    meg.call_main(args)
示例#7
0
def calc_sample_meg_data():
    args = meg.read_cmd_args(
        dict(subject='sample',
             function='calc_epochs,calc_evokes,calc_stc',
             contrast='audvis',
             task='audvis',
             pick_meg=True,
             pick_eeg=False,
             fwd_usingMEG=True,
             fwd_usingEEG=False,
             fname_format='{subject}_audvis_meg-{ana_type}.{file_type}',
             fname_format_cond=
             '{subject}_audvis_meg_{cond}-{ana_type}.{file_type}',
             trans_fname=op.join(MNE_ROOT, 'sample_audvis_raw-trans.fif'),
             events_fname=op.join(MNE_ROOT, 'sample_audvis_raw-eve.fif'),
             raw_fname=op.join(MNE_ROOT, 'sample_audvis_raw.fif'),
             inv_fname=op.join(MNE_ROOT,
                               'sample_audvis-meg-oct-6-meg-inv.fif'),
             fwd_fname=op.join(MNE_ROOT, 'sample_audvis-meg-oct-6-fwd.fif'),
             conditions=['LA', 'RA'],
             read_events_from_file=True,
             t_min=-0.2,
             t_max=0.5,
             overwrite_epochs=False,
             overwrite_evoked=False,
             overwrite_stc=True))
    meg.call_main(args)
示例#8
0
def calc_fwd_inv(subject, raw_fname, empty_fname, bad_channels_fname, overwrite_inv=False,
                 overwrite_fwd=False):
    # python -m src.preproc.eeg -s nmr00857 -f calc_inverse_operator,make_forward_solution
    #     --overwrite_inv 0 --overwrite_fwd 0 -t epilepsy
    #     --raw_fname  /autofs/space/frieda_001/users/valia/epilepsy/5241495_00857/subj_5241495/190123/5241495_01_raw.fif
    #     --empty_fname /autofs/space/frieda_001/users/valia/epilepsy/5241495_00857/subj_5241495/190123/5241495_roomnoise_raw.fif
    #     --use_empty_room_for_noise_cov 1
    #     --bad_channels EEG061,EEG02,EEG042,MEG0112,MEG0113
    bad_channels = ','.join(matlab_utils.matlab_cell_arrays_to_dict(bad_channels_fname)['label'])
    trans_fname = op.join(MEG_DIR, subject, '{}-trans.fif'.format(subject))
    args = meg.read_cmd_args(dict(
        subject=subject,
        mri_subject=subject,
        function='calc_inverse_operator,make_forward_solution',
        task='kaggle',
        inv_fname=op.join(MEG_DIR, subject, '{}-meeg-kaggle-inv.fif'.format(subject)),
        fwd_fname=op.join(MEG_DIR, subject, '{}-meeg-kaggle-fwd.fif'.format(subject)),
        fwd_usingEEG=True,
        overwrite_inv=overwrite_inv,
        overwrite_fwd=overwrite_fwd,
        use_empty_room_for_noise_cov=True,
        bad_channels=bad_channels,
        raw_fname=raw_fname,
        empty_fname=empty_fname,
        cor_fname=trans_fname
    ))
    meg.call_main(args)
示例#9
0
def calc_msit_functional_rois(args):
    clusters_root_fol = utils.make_dir(
        op.join(MMVT_DIR, args.subject[0], 'meg', 'clusters'))
    utils.delete_folder_files(clusters_root_fol)
    # conditions = ['neutral', 'interference']
    # for cond in conditions:
    _args = meg.read_cmd_args(
        dict(
            subject=args.subject,
            mri_subject=args.mri_subject,
            task='MSIT',
            data_per_task=True,
            # atlas='laus125',
            function='find_functional_rois_in_stc',
            inverse_method='dSPM',
            stc_name=
            '{subject}_msit_nTSSS_interference_interference-neutral_1-15-dSPM',
            inv_fname='{subject}_msit_nTSSS_interference_1-15-inv',
            label_name_template='*',
            peak_mode='pos',
            threshold=99.5,
            min_cluster_max=5,
            min_cluster_size=100,
            # recreate_src_spacing='ico5'
            # clusters_label='precentral'
        ))
    meg.call_main(_args)
示例#10
0
def calc_power_spectrum(args):
    args = meg.read_cmd_args(dict(
        subject=args.subject,
        mri_subject=args.mri_subject,
        atlas='laus125',
        function='calc_power_spectrum',
        overwrite_labels_power_spectrum=True,
        task='rest',
    ))
    meg.call_main(args)
示例#11
0
def morph_stc(args):
    args = meg.read_cmd_args(dict(
        subject=args.subject,
        mri_subject=args.mri_subject,
        function='morph_stc',
        task='MSIT',
        data_per_task=True,
        contrast='interference',
        cleaning_method='nTSSS',
        morph_to_subject='colin27'))
    meg.call_main(args)
示例#12
0
def calc_functional_rois(args):
    # -s DC -a laus250 -f find_functional_rois_in_stc --stc_name right-MNE-1-15 --label_name_template "precentral*" --inv_fname right-inv --threshold 99.5
    args = meg.read_cmd_args(
        dict(subject=args.subject,
             mri_subject=args.mri_subject,
             atlas='laus125',
             function='find_functional_rois_in_stc',
             inverse_method='MNE',
             stc_name='right-MNE-1-15',
             label_name_template='precentral*',
             inv_fname='right-inv',
             threshold=99.5))
    meg.call_main(args)
示例#13
0
def calc_labels_connectivity(args):
    args = meg.read_cmd_args(dict(
        subject=args.subject,
        mri_subject=args.mri_subject,
        task='MSIT',
        function='calc_labels_connectivity',
        data_per_task=True,
        # atlas='laus125',
        contrast='interference',
        cleaning_method='nTSSS',
        pick_ori='normal',
        con_method='wpli2_debiased'
    ))
    meg.call_main(args)
示例#14
0
def calc_mne_python_sample_data(args):
    args = meg.read_cmd_args(
        dict(
            subject=args.subject,
            mri_subject=args.mri_subject,
            # atlas='laus250',
            contrast='audvis',
            fname_format='{subject}_audvis-{ana_type}.{file_type}',
            fname_format_cond='{subject}_audvis_{cond}-{ana_type}.{file_type}',
            conditions=['LA', 'RA'],
            read_events_from_file=True,
            t_min=-0.2,
            t_max=0.5,
            extract_mode=['mean_flip', 'mean', 'pca_flip']))
    meg.call_main(args)
示例#15
0
def meg_calc_labels_ts(subject, inv_method='MNE', em='mean_flip', atlas='electrodes_labels', remote_subject_dir='',
                meg_remote_dir='', empty_fname='', cor_fname='', use_demi_events=True, n_jobs=-1):
    functions = 'calc_epochs,calc_evokes,make_forward_solution,calc_inverse_operator,calc_stc,calc_labels_avg_per_condition'
    meg_args = meg.read_cmd_args(dict(
        subject=subject, mri_subject=subject,
        task='rest', inverse_method=inv_method, extract_mode=em, atlas=atlas,
        single_trial_stc=True,
        recreate_src_spacing='ico5',
        # fwd_recreate_source_space=True,
        # recreate_bem_solution=True,
        remote_subject_meg_dir=meg_remote_dir,
        remote_subject_dir=remote_subject_dir,
        empty_fname=empty_fname,
        cor_fname=cor_fname,
        function=functions,
        use_demi_events=use_demi_events,
        windows_length=10000,
        windows_shift=5000,
        # overwrite_fwd=True,
        # overwrite_inv=True,
        # overwrite_labels_data=True,
        using_auto_reject=False,
        use_empty_room_for_noise_cov=True,
        read_only_from_annot=False,
        n_jobs=n_jobs
    ))
    return meg.call_main(meg_args)
示例#16
0
def meg_preproc(subject, inv_method='MNE', em='mean_flip', atlas='electrodes_labels', remote_subject_dir='',
                meg_remote_dir='', empty_fname='', cor_fname='', use_demi_events=True, calc_labels_avg=False,
                overwrite=False, n_jobs=-1):
    functions = 'calc_epochs,calc_evokes,make_forward_solution,calc_inverse_operator'
    if calc_labels_avg:
        functions += ',calc_stc,calc_labels_avg_per_condition'
    meg_args = meg.read_cmd_args(dict(
        subject=subject, mri_subject=subject,
        task='rest', inverse_method=inv_method, extract_mode=em, atlas=atlas,
        remote_subject_meg_dir=meg_remote_dir,
        remote_subject_dir=remote_subject_dir,
        empty_fname=empty_fname,
        cor_fname=cor_fname,
        function=functions,
        use_demi_events=use_demi_events,
        windows_length=10000,
        windows_shift=5000,
        # power_line_notch_widths=5,
        using_auto_reject=False,
        # reject=False,
        use_empty_room_for_noise_cov=True,
        read_only_from_annot=False,
        overwrite_epochs=overwrite,
        overwrite_evoked=overwrite,
        n_jobs=n_jobs
    ))
    return meg.call_main(meg_args)
示例#17
0
def meg_preproc(args):
    atlas, inv_method, em = 'aparc.DKTatlas40', 'dSPM', 'mean_flip'
    atlas = 'darpa_atlas'
    bands = dict(theta=[4, 8], alpha=[8, 15], beta=[15, 30], gamma=[30, 55], high_gamma=[65, 200])
    tasks = ['MSIT', 'ECR']
    empty_fnames = get_empty_fnames(args.subject[0], tasks, args)
    times = (-2, 4)

    for task in tasks:
        args = meg.read_cmd_args(dict(
            subject=args.subject, mri_subject=args.subject,
            task=task, inverse_method=inv_method, extract_mode=em, atlas=atlas,
            meg_dir=args.meg_dir,
            remote_subject_dir=args.remote_subject_dir, # Needed for finding COR
            get_task_defaults=False,
            fname_format='{}_{}_maxwell-raw'.format('{subject}', task),
            empty_fname=empty_fnames[task],
            # function='calc_epochs,calc_evokes,make_forward_solution,calc_inverse_operator,calc_stc_per_condition,calc_labels_avg_per_condition,calc_labels_min_max',
            function='calc_epochs',
            # function='calc_labels_connectivity',
            conditions=task.lower(),
            # data_per_task=True,
            ica_overwrite_raw=False,
            normalize_data=False,
            t_min=times[0], t_max=times[1],
            read_events_from_file=False, stim_channels='STI001',
            use_empty_room_for_noise_cov=True,
            calc_source_band_induced_power=True,
            calc_inducde_power_per_label=False,
            bands='', #dict(theta=[4, 8], alpha=[8, 15], beta=[15, 30], gamma=[30, 55], high_gamma=[65, 200]),
            con_method='coh',
            con_mode='cwt_morlet',
            overwrite_connectivity=False,
            read_only_from_annot=False,
            # pick_ori='normal',
            # overwrite_epochs=True,
            # overwrite_evoked=True,
            # overwrite_inv=True,
            overwrite_stc=True,
            overwrite_labels_data=True,
            n_jobs=args.n_jobs
        ))
        meg.call_main(args)
    #
    for subject in args.subject:
        for task in tasks:
            task = task.lower()
示例#18
0
def meg_remove_artifcats(subject, raw_fname):
    meg_args = meg.read_cmd_args(dict(
        subject=subject, mri_subject=subject,
        function='remove_artifacts',
        raw_fname=raw_fname,
        overwrite_ica=True
    ))
    return meg.call_main(meg_args)
示例#19
0
def calc_fwd_inv(subject, raw_fname, bad_channels, empty_room_fname,
                 remote_subject_dir, fwd_usingMEG, fwd_usingEEG, overwrite,
                 n_jobs):
    args = meg.read_cmd_args(
        dict(subject=subject,
             task='epilepsy',
             function='make_forward_solution,calc_inverse_operator',
             raw_fname=raw_fname,
             bad_channels=bad_channels,
             use_empty_room_for_noise_cov=True,
             empty_fname=empty_room_fname,
             fwd_usingMEG=fwd_usingMEG,
             fwd_usingEEG=fwd_usingEEG,
             remote_subject_dir=remote_subject_dir,
             overwrite_fwd=overwrite,
             overwrite_inv=overwrite,
             n_jobs=n_jobs))
    meg.call_main(args)
示例#20
0
def calc_msit_labels_avg(args):
    # python -m src.preproc.meg -s ep001 -m mg78 -a laus250 -t MSIT
    #   --contrast interference --t_max 2 --t_min -0.5 --data_per_task 1 --read_events_from_file 1
    #   --events_fname {subject}_msit_nTSSS_interference-eve.txt --cleaning_method nTSSS
    args = meg.read_cmd_args(
        dict(subject=args.subject,
             mri_subject=args.mri_subject,
             task='MSIT',
             function='calc_labels_avg_per_condition,calc_labels_min_max',
             data_per_task=True,
             atlas=args.atlas,
             contrast='interference',
             cleaning_method='nTSSS',
             t_min=-0.5,
             t_max=2,
             pick_ori='normal',
             overwrite_labels_data=True))
    meg.call_main(args)
示例#21
0
def read_meg_layouts(_args, remote_raw_fname=''):
    args = copy.copy(_args)
    bad_subjects = []
    output_fol = utils.make_dir(op.join(MMVT_DIR, 'sensors'))
    subjects = args.subject
    for subject in subjects:
        args.subject = [subject]
        _, _, trans_fname = get_meg_empty_fnames(subject, args.remote_meg_dir,
                                                 args)
        if remote_raw_fname == '':
            remote_raw_fname = op.join(
                args.raw_rest_remote_fol, subject,
                '{}_Resting_meg_ica-raw.fif'.format(subject))
        if not op.isfile(remote_raw_fname):
            print('No Cor fname: {}!!!'.format(remote_raw_fname))
            continue
        meg_args = meg.read_cmd_args(
            utils.Bag(subject=subject,
                      data_per_task=False,
                      remote_subject_dir=args.remote_subject_dir,
                      raw_fname=remote_raw_fname,
                      function='read_sensors_layout',
                      trans_fname=trans_fname,
                      overwrite_sensors=True,
                      read_info_file=False,
                      n_jobs=args.n_jobs))
        meg.call_main(meg_args)
        for sensor_type in ['mag', 'planar1', 'planar2']:
            sensors_fname = op.join(
                MMVT_DIR, subject, 'meg',
                'meg_{}_sensors_positions.npz'.format(sensor_type))
            if not op.isfile(sensors_fname):
                bad_subjects.append(subject)
                break
            utils.make_dir(op.join(output_fol, subject))
            output_fname = op.join(output_fol, subject,
                                   utils.namebase_with_ext(sensors_fname))
            if not op.isfile(output_fname):
                utils.copy_file(sensors_fname, output_fname)

    print('{}/{} subjects with no sensors:'.format(len(bad_subjects),
                                                   len(args.subject)))
    print(bad_subjects)
示例#22
0
def calc_meg_power_spectrum(subject, atlas, inv_method, em, overwrite=False, n_jobs=-1):
    meg_args = meg.read_cmd_args(dict(
        subject=subject, mri_subject=subject,
        task='rest', inverse_method=inv_method, extract_mode=em, atlas=atlas,
        function='calc_labels_power_spectrum',
        pick_ori='normal',  # very important for calculation of the power spectrum
        # max_epochs_num=20,
        overwrite_labels_power_spectrum=overwrite,
        n_jobs=n_jobs
    ))
    return meg.call_main(meg_args)
示例#23
0
def mmvt():
    from src.preproc import meg
    # Call the MMVT MEG preprocessing to create the inverse solution and the source estimate
    args = meg.read_cmd_args(
        dict(subject='sample',
             task='audvis',
             inverse_method='MNE',
             pick_ori=None,
             function='calc_inverse_operator,calc_stc',
             inv_loose=0,
             evo_fname=fname_evoked,
             fwd_fname=fname_fwd,
             noise_cov_fname=fname_cov))
    meg.call_main(args)
    stc_fname = meg.get_stc_fname(args).format(hemi='lh')
    t = meg.time_to_index(0.08)
    stc_fname, _ = mmvt.meg.plot_stc(stc_fname,
                                     t=168,
                                     threshold=1.43,
                                     save_image=True)
def calc_functional_rois(conds, args):
    clusters_root_fol = op.join(MMVT_DIR, subject, 'meg', 'clusters')
    utils.delete_folder_files(clusters_root_fol)
    for cond in conds.keys():
        _args = meg.read_cmd_args(
            dict(
                subject=args.subject,
                mri_subject=args.mri_subject,
                atlas='laus250',
                function='find_functional_rois_in_stc',
                inverse_method='MNE',
                stc_name='{}-MNE-1-15'.format(cond),
                label_name_template='precentral*',
                inv_fname='{}-inv'.format(cond),
                threshold=99.5,
                min_cluster_max=0.2,
                min_cluster_size=100,
                # clusters_label='precentral'
            ))
        meg.call_main(_args)
示例#25
0
def calc_msit_evoked(args):
    # python -m src.preproc.meg -s ep001 -m mg78 -a laus125 -f calc_epochs,calc_evokes -t MSIT
    #   --contrast interference --t_max 2 --t_min -0.5 --data_per_task 1 --read_events_from_file 1
    #   --events_fname {subject}_msit_nTSSS_interference-eve.txt --cleaning_method nTSSS
    args = meg.read_cmd_args(dict(
        subject=args.subject,
        mri_subject=args.mri_subject,
        task='MSIT',
        function='calc_epochs,calc_evokes',
        data_per_task=True,
        atlas='laus125',
        contrast='interference',
        cleaning_method='nTSSS',
        t_min=-0.5,
        t_max=2,
        read_events_from_file=True,
        normalize_data = False,
        overwrite_evoked = True,
        events_fname='{subject}_msit_nTSSS_interference-eve.txt',
    ))
    meg.call_main(args)
示例#26
0
def main(subject,
         atlas,
         connectivity_method,
         graph_func,
         remote_subject_dir,
         files,
         n_jobs=4):
    meg_fol = op.join(MMVT_DIR, subject, 'meg')
    for fname in files:
        file_name = utils.namebase(fname)
        files_fol = utils.make_dir(op.join(meg_fol, file_name))
        files_exist = \
            utils.both_hemi_files_exist(op.join(files_fol, '{}_all-dSPM-{}.stc'.format(subject, '{hemi}'))) and \
            utils.both_hemi_files_exist(op.join(files_fol, 'labels_data_epilepsy_laus125_dSPM_mean_flip_{hemi}.npz'))
        if not files_exist:
            args = meg.read_cmd_args(
                dict(subject=subject,
                     task='epilepsy',
                     function='calc_stc,calc_labels_avg_per_condition',
                     atlas=atlas,
                     evo_fname=fname,
                     remote_subject_dir=remote_subject_dir,
                     overwrite_labels_data=True,
                     n_jobs=n_jobs))
            meg.call_main(args)
        analyse_connectivity(subject, connectivity_method, graph_func,
                             file_name, atlas, n_jobs)
        for hemi in utils.HEMIS:
            utils.move_file(
                op.join(meg_fol, '{}_all-dSPM-{}.stc'.format(subject, hemi)),
                files_fol)
            utils.move_file(
                op.join(
                    meg_fol,
                    'labels_data_epilepsy_laus125_dSPM_mean_flip_{}.npz'.
                    format(hemi)), files_fol)

    plot_all_files_graph_max(subject, files, graph_func)
示例#27
0
def analyze_meg(args):
    subjects = args.subject
    for subject, mri_subject in zip(subjects, args.mri_subject):
        init_meg(subject)
        local_rest_raw_fname, empty_fname, cor_fname = get_meg_empty_fnames(
            subject, args.remote_meg_dir.format(subject=subject.upper()), args)
        if not op.isfile(empty_fname) or not op.isfile(cor_fname):
            print('{}: Can\'t find empty, raw, or cor files!'.format(subject))
            continue
        args = meg.read_cmd_args(
            dict(
                subject=subject,
                mri_subject=mri_subject,
                atlas=args.atlas,
                function='rest_functions',
                task='rest',
                reject=
                True,  # Should be True here, unless you are dealling with bad data...
                remove_power_line_noise=True,
                l_freq=3,
                h_freq=80,
                windows_length=500,
                windows_shift=100,
                inverse_method='MNE',
                raw_fname=local_rest_raw_fname,
                cor_fname=cor_fname,
                empty_fname=empty_fname,
                remote_subject_dir=args.remote_subject_dir,
                # This properties are set automatically if task=='rest'
                # calc_epochs_from_raw=True,
                # single_trial_stc=True,
                # use_empty_room_for_noise_cov=True,
                # windows_num=10,
                # baseline_min=0,
                # baseline_max=0,
            ))
        meg.call_main(args)
示例#28
0
文件: ohad_meg.py 项目: ltirrell/mmvt
def meg_prepoc(args):
    # -s nmr00479 -f make_forward_solution,calc_inverse_operator,calc_stc --use_empty_room_for_noise_cov 1 --apply_on_raw 1 --recreate_src_surface 1 --overwrite_fwd 1
    inv_method = 'MNE'
    for subject in args.subject:
        raw_files = glob.glob(op.join(MEG_DIR, subject, '*_??_raw.fif'))
        args.subject = subject
        for raw_fname in raw_files:
            meg_args = meg.read_cmd_args(dict(
                subject=args.subject, mri_subject=args.subject,
                inverse_method=inv_method,
                raw_fname=raw_fname,
                function='make_forward_solution,calc_inverse_operator,calc_stc',
                use_empty_room_for_noise_cov=True,
                apply_on_raw=True,
                pick_ori='normal'
            ))
            ret = meg.call_main(meg_args)
def analyze_meg(subject, seizure_time, seizure_len):
    raw, evoked = None, None
    meg_raw_fnames = [
        op.join(MEG_ROOT, 'nmr01209_6213848_07',
                'nmr01209_6213848_07_Resting_eeg_meg_ica-raw.fif'),
        op.join(MEG_DIR, subject,
                'nmr01209_6213848_07_Resting_eeg_meg_ica-raw.fif')
    ]
    meg_raw_fname = [f for f in meg_raw_fnames if op.isfile(f)][0]
    # empty_room_fname = '/space/megraid/77/MEG/noise/no_name/'
    meg_raw_fname_seizure = op.join(MEG_DIR, subject,
                                    '{}_meg_seizure-raw.fif'.format(subject))
    meg_evoked_fname = op.join(MEG_DIR, subject,
                               '{}_meg_seizure-ave.fif'.format(subject))
    eeg_evoked_fname = op.join(MEG_DIR, subject,
                               '{}_eeg_seizure-ave.fif'.format(subject))
    meeg_evoked_fname = op.join(MEG_DIR, subject,
                                '{}_meeg_seizure-ave.fif'.format(subject))

    if not op.isfile(meg_raw_fname_seizure):
        raw = mne.io.read_raw_fif(meg_raw_fname)
        raw.set_eeg_reference('average',
                              projection=True)  # set EEG average reference
        raw = raw.crop(seizure_time - 2, seizure_time + seizure_len)
        raw.save(meg_raw_fname_seizure)
        # raw.plot(block=True)
        # raw.plot(butterfly=True, group_by='position')
        meg.read_sensors_layout(subject,
                                info=raw.info,
                                overwrite_sensors=False)
        eeg.read_sensors_layout(subject,
                                info=raw.info,
                                overwrite_sensors=False)

    if not op.isfile(meg_evoked_fname) or not op.isfile(
            eeg_evoked_fname) or not op.isfile(meeg_evoked_fname):
        if raw is None:
            raw = mne.io.read_raw_fif(meg_raw_fname_seizure)
        evoked = mne.EvokedArray(raw.get_data(), raw.info, comment='seizure')

        meeg_evoked = evoked.pick_types(meg=True, eeg=True)
        mne.write_evokeds(meeg_evoked_fname, meeg_evoked)

        eeg_evoked = evoked.pick_types(meg=False, eeg=True)
        mne.write_evokeds(eeg_evoked_fname, eeg_evoked)
        meg.save_evokes_to_mmvt(eeg_evoked, [1], subject, modality='eeg')

        meg_evoked = evoked.pick_types(meg=True, eeg=False)
        mne.write_evokeds(meg_evoked_fname, meg_evoked)
        meg.save_evokes_to_mmvt(evoked, [1], subject, modality='meg')

    meg.create_helmet_mesh(subject, overwrite_faces_verts=True)
    eeg.create_helmet_mesh(subject, overwrite_faces_verts=True)

    overwrite_source_bem = False
    args = meg.read_cmd_args(
        dict(
            subject=subject,
            function=
            'make_forward_solution,calc_inverse_operator,calc_stc,calc_labels_avg_per_condition',
            atlas='electrodes_labels',
            evo_fname=meeg_evoked_fname,
            # recreate_src_spacing='ico5',
            # fwd_recreate_source_space=overwrite_source_bem,
            # recreate_bem_solution=overwrite_source_bem,
            contrast='seizure',
            task='seizure',
            raw_fname=meg_raw_fname_seizure,
            use_empty_room_for_noise_cov=True,
            empty_fname='empty_room_raw.fif',
            # overwrite_fwd=True
            overwrite_stc=False,
            overwrite_labels_data=True,
            # pick_meg=True, pick_eeg=False,
            # fwd_usingMEG=True, fwd_usingEEG=False,
        ))
    meg.call_main(args)
示例#30
0
def calc_meg_source_psd(args):
    from src.misc import meg_buddy
    bad_subjects = ['hc004', 'hc012', 'hc029']
    subjects = args.subject
    for subject in subjects:
        if subject in bad_subjects:
            continue
        fol = op.join(MMVT_DIR, subject, 'meg')
        file_name = '{cond}_dSPM_mean_flip_vertices_power_spectrum.pkl'
        if all([op.isfile(op.join(fol, file_name.format(cond=cond.lower())))
                for cond in MSIT_CONDS]) and not args.overwrite:
            print('{}: already has MSIT power stcs'.format(subject))
            continue
        args.subject = subject
        local_raw_fname = op.join(MEG_DIR, args.task, subject, args.raw_template.format(
            subject=subject, task=args.task))
        remote_raw_fname = op.join(args.remote_root_dir, 'raw_preprocessed', subject, args.raw_template.format(
            subject=subject, task=args.task))
        if not op.isfile(remote_raw_fname) and not args.ignore:
            print('Can\'t find remote raw file! {}'.format(remote_raw_fname))
            continue
        if op.isfile(local_raw_fname):
            os.remove(local_raw_fname)
        utils.make_link(remote_raw_fname, local_raw_fname)
        if not op.islink(local_raw_fname) and not args.ignore:
            print('Can\'t create a link to the remote raw!')
            continue
        inv_fname = op.join(MEG_DIR, args.task, subject, args.inv_template.format(subject=subject, task=args.task))
        if not op.isfile(inv_fname):
            inv_fnames = glob.glob(op.join(MEG_DIR, args.task, subject, '*inv.fif'))
            if len(inv_fnames) > 0:
                inv_fname = utils.select_one_file(inv_fnames)
                print('New inv fname: {}'.format(inv_fname))

        _args = meg.read_cmd_args(dict(
            subject=subject, mri_subject=subject,
            function='make_forward_solution,calc_inverse_operator',
            task='MSIT', data_per_task=True,
            fmin=1, fmax=120,
            raw_fname=local_raw_fname, inv_fname=inv_fname,
            remote_subject_dir=args.remote_subject_dir,
            n_jobs=args.n_jobs
        ))
        ret = meg.call_main(_args)
        if not ret[subject].get('calc_inverse_operator', True):
            continue

        # Load the eopchs and calc source power spectrum for both conditions.
        # The epochs are being splitted first
        data = meg_buddy.get_data(subject, tasks=['MSIT'], modalities=['MEG'])['MSIT']['MEG']
        if subject not in data:
            print('{} not in msit_data!'.format(subject))
            continue
        data = data[subject]
        subject_epochs = data._load_epochs('Onset', ar=True)
        indices = data._get_indices(subject_epochs, 'Condition', MSIT_CONDS)
        for cond in MSIT_CONDS:
            epochs = subject_epochs[indices[cond]]
            meg.calc_source_power_spectrum(
                subject, cond.lower(), epochs=epochs, max_epochs_num=50, inv_fname=inv_fname,
                overwrite=args.overwrite, n_jobs=args.n_jobs)