Ejemplo n.º 1
0
def aseg_to_srf(subject, subjects_dir, output_fol, region_id, mask_fname, norm_fname,
                overwrite_subcortical_objs=False):
    ret = True
    tmp_fol = op.join(subjects_dir, subject, 'tmp', utils.rand_letters(6))
    utils.make_dir(tmp_fol)
    rs = utils.partial_run_script(locals())
    output_fname = op.join(output_fol, '{}.srf'.format(region_id))
    tmp_output_fname = op.join(tmp_fol, '{}.asc'.format(region_id))
    if overwrite_subcortical_objs:
        utils.remove_file(output_fname)
    try:
        rs(mri_pretess)
        rs(mri_tessellate)
        rs(mris_smooth)
        rs(mris_convert)
        if op.isfile(tmp_output_fname):
            shutil.move(tmp_output_fname, output_fname)
            shutil.rmtree(tmp_fol)
        else:
            ret = False
    except:
        print('Error in aseg_to_srf! subject: {}'.format(subject))
        print(traceback.format_exc())
        ret = False

    return ret
Ejemplo n.º 2
0
def aseg_to_srf(subject,
                subjects_dir,
                output_fol,
                region_id,
                lookup,
                mask_fname,
                norm_fname,
                overwrite_subcortical_objs=False,
                **kargs):
    from src.utils import geometry_utils as gu
    ret = True
    tmp_fol = op.join(subjects_dir, subject, 'tmp', utils.rand_letters(6))
    utils.make_dir(tmp_fol)
    rs = utils.partial_run_script(locals())
    # output_fname = op.join(output_fol, '{}.srf'.format(region_id))
    # tmp_output_fname = op.join(tmp_fol, '{}.asc'.format(region_id))
    # if overwrite_subcortical_objs:
    #     utils.remove_file(output_fname)
    try:
        rs(mri_pretess)
        rs(mri_tessellate)
        rs(mris_smooth)
        fs_file = op.join(tmp_fol, '{}_smooth'.format(region_id))
        verts, faces = gu.read_surface(fs_file)
        # verts, faces = nib_fs.read_geometry(fs_file)
        num = int(op.basename(fs_file).split('_')[0])
        if num not in lookup:
            print('Error in the subcorticals lookup table!')
            return False
        new_name = lookup.get(num, '')
        utils.write_ply_file(verts, faces,
                             op.join(output_fol, '{}.ply'.format(new_name)),
                             True)
        # mris_convert = 'mris_convert {tmp_fol}/{region_id}_smooth {tmp_fol}/{region_id}.asc'
        # rs(mris_convert)
        # if op.isfile(tmp_output_fname):
        #     shutil.move(tmp_output_fname, output_fname)
        if op.isdir(tmp_fol):
            shutil.rmtree(tmp_fol)
        else:
            ret = False
    except:
        print('Error in aseg_to_srf! subject: {}'.format(subject))
        print(traceback.format_exc())
        ret = False

    return ret
Ejemplo n.º 3
0
Archivo: ct.py Proyecto: keshava/mmvt
def find_electrodes(subject,
                    n_components,
                    n_groups,
                    ct_name='',
                    brain_mask_fname='',
                    output_fol=None,
                    clustering_method='knn',
                    max_iters=5,
                    cylinder_error_radius=3,
                    min_elcs_for_lead=4,
                    max_dist_between_electrodes=20,
                    min_cylinders_ang=0.1,
                    thresholds=(99, 99.9, 99.95, 99.99, 99.995, 99.999),
                    min_joined_items_num=1,
                    min_distance_beteen_electrodes=2,
                    overwrite=False,
                    debug=False):
    from src.misc.dell import find_electrodes_in_ct
    if n_components <= 0 or n_groups <= 0:
        print('Both n_components and n_groups should be > 0!')
        return False
    if ct_name == '':
        ct_name = 'ct_reg_to_mr.mgz'
    ct_fname = op.join(MMVT_DIR, subject, 'ct', ct_name)
    if brain_mask_fname == '':
        brain_mask_fname = op.join(SUBJECTS_DIR, subject, 'mri', 'brain.mgz')
    if output_fol is None:
        output_fol = utils.make_dir(
            op.join(MMVT_DIR, subject, 'ct', 'finding_electrodes_in_ct',
                    utils.rand_letters(5)))
    electrodes, groups, groups_hemis = find_electrodes_in_ct.find_depth_electrodes_in_ct(
        subject, ct_fname, brain_mask_fname, n_components, n_groups,
        output_fol, clustering_method, max_iters, cylinder_error_radius,
        min_elcs_for_lead, max_dist_between_electrodes, min_cylinders_ang,
        thresholds, min_joined_items_num, min_distance_beteen_electrodes,
        overwrite, debug)
    if output_fol == '':
        return all(x is not None for x in [electrodes, groups, groups_hemis])
    else:
        return op.isfile(op.join(output_fol, 'objects.pkl'))