예제 #1
0
def load_surf_files(nii_fname, run_fmri_preproc=True, user_fol='', debug=True):
    fmri_file_template = ''
    if user_fol == '':
        user_fol = mu.get_user_fol()
    nii_fol = mu.get_fname_folder(nii_fname)
    if debug:
        print('load_surf_files: nii_fol: {}'.format(nii_fol))
    hemi, fmri_hemis = mu.get_hemi_from_full_fname(nii_fname)
    if debug:
        print('load_surf_files: hemi, fmri_hemis: {}, {}'.format(
            hemi, fmri_hemis))
    if hemi == '':
        hemi = mu.find_hemi_using_vertices_num(nii_fname)
        if hemi == '':
            return ''
    # fmri_hemis = mu.get_both_hemis_files(nii_fname)
    local_fname = build_local_fname(nii_fname, user_fol)
    if debug:
        print('load_surf_files: local_fname: {}'.format(local_fname))
    mu.make_dir(op.join(user_fol, 'fmri'))
    if nii_fol != op.join(user_fol, 'fmri'):
        mu.make_link(nii_fname, local_fname, True)
    other_hemi = mu.other_hemi(hemi)
    if debug:
        print('load_surf_files: other_hemi: {}'.format(other_hemi))
    other_hemi_fname = fmri_hemis[other_hemi]
    if other_hemi_fname == '':
        other_hemi_fname = local_fname.replace(hemi, other_hemi)
    if debug:
        print('load_surf_files: other_hemi_fname: {}'.format(other_hemi_fname))
    # todo: if the other hemi file doens't exist, just create an empty one
    output_fname_template = ''
    if op.isfile(other_hemi_fname):
        local_other_hemi_fname = build_local_fname(other_hemi_fname, user_fol)
        if nii_fol != op.join(user_fol, 'fmri'):
            mu.make_link(other_hemi_fname, local_other_hemi_fname, True)
        fmri_file_template = mu.get_template_hemi_label_name(
            mu.namebase_with_ext(local_fname))
        if run_fmri_preproc:
            mu.add_mmvt_code_root_to_path()
            from src.preproc import fMRI
            importlib.reload(fMRI)
            vertices_num = mu.get_vertices_num()
            ret, npy_output_fname_template = fMRI.load_surf_files(
                mu.get_user(), fmri_hemis, vertices_num=vertices_num)
            output_fname_template = op.join(
                mu.get_parent_fol(npy_output_fname_template),
                mu.namebase_with_ext(npy_output_fname_template)[len('fmri_'):])
        else:
            mu.run_mmvt_func(
                'src.preproc.fMRI',
                'load_surf_files',
                flags='--fmri_file_template "{}"'.format(fmri_file_template))
            # todo: find what should be the output_fname_template
    else:
        print(
            "Couldn't find the other hemi file! ({})".format(other_hemi_fname))
    return output_fname_template  #, hemi, other_hemi
예제 #2
0
def load_surf_files(nii_fname):
    fmri_file_template = ''
    user_fol = mu.get_user_fol()
    nii_fol = mu.get_fname_folder(nii_fname)
    fmri_hemis = mu.get_both_hemis_files(nii_fname)
    hemi = mu.get_hemi_from_full_fname(nii_fname)
    local_fname = build_local_fname(nii_fname, user_fol)
    mu.make_dir(op.join(user_fol, 'fmri'))
    if nii_fol != op.join(user_fol, 'fmri'):
        mu.make_link(nii_fname, local_fname, True)
    other_hemi = mu.other_hemi(hemi)
    other_hemi_fname = fmri_hemis[other_hemi]
    if op.isfile(other_hemi_fname):
        local_other_hemi_fname = build_local_fname(other_hemi_fname, user_fol)
        if nii_fol != op.join(user_fol, 'fmri'):
            mu.make_link(other_hemi_fname, local_other_hemi_fname, True)
        fmri_file_template = mu.get_template_hemi_label_name(mu.namesbase_with_ext(local_fname))
        cmd = '{} -m src.preproc.fMRI -s {} -f load_surf_files --fmri_file_template "{}"'.format(
            bpy.context.scene.python_cmd, mu.get_user(), fmri_file_template)
        mu.run_command_in_new_thread(cmd, False)
    return fmri_file_template, hemi
예제 #3
0
def load_surf_files(nii_fname, run_fmri_preproc=True, user_fol=''):
    fmri_file_template = ''
    if user_fol == '':
        user_fol = mu.get_user_fol()
    nii_fol = mu.get_fname_folder(nii_fname)
    # hemi = mu.get_hemi_from_fname(mu.namebase(nii_fname))
    # if hemi == '':
    hemi, fmri_hemis = mu.get_hemi_from_full_fname(nii_fname)
    if hemi == '':
        hemi = mu.find_hemi_using_vertices_num(nii_fname)
        if hemi == '':
            return '', ''
    # fmri_hemis = mu.get_both_hemis_files(nii_fname)
    local_fname = build_local_fname(nii_fname, user_fol)
    mu.make_dir(op.join(user_fol, 'fmri'))
    if nii_fol != op.join(user_fol, 'fmri'):
        mu.make_link(nii_fname, local_fname, True)
    other_hemi = mu.other_hemi(hemi)
    other_hemi_fname = fmri_hemis[other_hemi]
    # todo: if the other hemi file doens't exist, just create an empty one
    if op.isfile(other_hemi_fname):
        local_other_hemi_fname = build_local_fname(other_hemi_fname, user_fol)
        if nii_fol != op.join(user_fol, 'fmri'):
            mu.make_link(other_hemi_fname, local_other_hemi_fname, True)
        fmri_file_template = mu.get_template_hemi_label_name(
            mu.namebase_with_ext(local_fname))
        if run_fmri_preproc:
            mu.run_mmvt_func(
                'src.preproc.fMRI',
                'load_surf_files',
                flags='--fmri_file_template "{}"'.format(fmri_file_template))
            # cmd = '{} -m  -s {} -f  --fmri_file_template "{}" --ignore_missing 1'.format(
            #     bpy.context.scene.python_cmd, mu.get_user(), fmri_file_template)
            # mu.run_command_in_new_thread(cmd, False, cwd=mu.get_mmvt_code_root())
    else:
        print(
            "Couldn't find the other hemi file! ({})".format(other_hemi_fname))
    return fmri_file_template, hemi, other_hemi