Esempio n. 1
0
def convert_and_rename_subcortical_files(subject, fol, new_fol, lookup, mmvt_subcorticals_fol_name='subcortical'):
    obj_files = glob.glob(op.join(fol, '*.srf'))
    utils.delete_folder_files(new_fol)
    for obj_file in obj_files:
        num = int(op.basename(obj_file)[:-4].split('_')[-1])
        new_name = lookup.get(num, '')
        if new_name != '':
            utils.srf2ply(obj_file, op.join(new_fol, '{}.ply'.format(new_name)))
            verts, faces = utils.read_ply_file(op.join(new_fol, '{}.ply'.format(new_name)))
            np.savez(op.join(new_fol, '{}.npz'.format(new_name)), verts=verts, faces=faces)
    copy_subcorticals_to_mmvt(new_fol, subject, mmvt_subcorticals_fol_name)
Esempio n. 2
0
def convert_and_rename_subcortical_files(subject, fol, new_fol, lookup):
    obj_files = glob.glob(op.join(fol, '*.srf'))
    utils.delete_folder_files(new_fol)
    for obj_file in obj_files:
        num = int(op.basename(obj_file)[:-4].split('_')[-1])
        new_name = lookup.get(num, '')
        if new_name != '':
            utils.srf2ply(obj_file, op.join(new_fol, '{}.ply'.format(new_name)))
            verts, faces = utils.read_ply_file(op.join(new_fol, '{}.ply'.format(new_name)))
            np.savez(op.join(new_fol, '{}.npz'.format(new_name)), verts=verts, faces=faces)
        copy_subcorticals_to_blender(new_fol, subject)
Esempio n. 3
0
def convert_and_rename_subcortical_files(subject, fol, new_fol, lookup):
    obj_files = glob.glob(op.join(fol, '*.srf'))
    utils.delete_folder_files(new_fol)
    for obj_file in obj_files:
        num = int(op.basename(obj_file)[:-4].split('_')[-1])
        new_name = lookup.get(num, '')
        if new_name != '':
            utils.srf2ply(obj_file, op.join(new_fol, '{}.ply'.format(new_name)))
            verts, faces = utils.read_ply_file(op.join(new_fol, '{}.ply'.format(new_name)))
            np.savez(op.join(new_fol, '{}.npz'.format(new_name)), verts=verts, faces=faces)
    blender_fol = op.join(MMVT_DIR, subject, 'subcortical')
    if op.isdir(blender_fol):
        shutil.rmtree(blender_fol)
    shutil.copytree(new_fol, blender_fol)
Esempio n. 4
0
def read_surface(surf_name):
    print('Reading {}'.format(surf_name))
    try:
        verts, faces = nib.freesurfer.read_geometry(surf_name)
    except:
        from src.utils import utils
        import shutil
        utils.print_last_error_line()
        print('Trying to recreate the surface')
        surf_wavefront_name = '{}.asc'.format(surf_name)
        print('mris_convert {} {}'.format(surf_name, surf_wavefront_name))
        utils.run_script('mris_convert {} {}'.format(surf_name,
                                                     surf_wavefront_name))
        ply_fname = '{}.ply'.format(surf_name)
        verts, faces = utils.srf2ply(surf_wavefront_name, ply_fname)
        shutil.copyfile(surf_name, '{}.org'.format(surf_name))
        nib.freesurfer.write_geometry(surf_name, verts, faces)
    return verts, faces
Esempio n. 5
0
def convert_hemis_srf_to_ply(subject, hemi='both', surf_type='pial'):
    for hemi in utils.get_hemis(hemi):
        ply_file = utils.srf2ply(op.join(SUBJECTS_DIR, subject, 'surf', '{}.{}.srf'.format(hemi, surf_type)),
                                 op.join(SUBJECTS_DIR, subject, 'surf', '{}.{}.ply'.format(hemi, surf_type)))
        utils.make_dir(op.join(MMVT_DIR, subject))
Esempio n. 6
0
def convert_hemis_srf_to_ply(subject, hemi='both'):
    for hemi in utils.get_hemis(hemi):
        ply_file = utils.srf2ply(op.join(SUBJECTS_DIR, subject, 'surf', '{}.pial.srf'.format(hemi)),
                                 op.join(SUBJECTS_DIR, subject, 'surf', '{}.pial.ply'.format(hemi)))
        utils.make_dir(op.join(MMVT_DIR, subject))
        shutil.copyfile(ply_file, op.join(MMVT_DIR, subject, '{}.pial.ply'.format(hemi)))
Esempio n. 7
0
def convert_hemis_srf_to_ply(subject, hemi='both', surf_type='pial'):
    for hemi in utils.get_hemis(hemi):
        ply_file = utils.srf2ply(op.join(SUBJECTS_DIR, subject, 'surf', '{}.{}.srf'.format(hemi, surf_type)),
                                 op.join(SUBJECTS_DIR, subject, 'surf', '{}.{}.ply'.format(hemi, surf_type)))
        utils.make_dir(op.join(MMVT_DIR, subject))