Example #1
0
def _apply_vek_prob(data_dir=None):
    """
    Applies probabilistic von Economo & Koskinas FreeSurfer classifier

    Uses `fsaverage5` surface; requires FreeSurfer installation.

    Parameters
    ----------
    data_dir : str or os.PathLike, optional
        Path where probabilistic von Economo & Koskinas classifier should be
        downloaded. Also determines where generated annotation files are
        saved.

    Returns
    -------
    surface : (2,) namedtuple
        Where the first entry ('lh') is the left hemisphere annotation file and
        the second entry ('rh') is the right hemisphere annotation file
    """

    vek = nndata.fetch_voneconomo(data_dir=data_dir)

    annots = []
    for hemi in ('lh', 'rh'):
        gcs = Path(getattr(vek['gcs'], hemi))
        ctab = Path(getattr(vek['ctab'], hemi))
        annot = (gcs.parent / 'atl-vonEconomoKoskinas_space-fsaverage5_hemi-{}'
                 '_deterministic.annot'.format(hemi[0].capitalize()))
        annot = nnsurf.apply_prob_atlas('fsaverage5',
                                        str(gcs),
                                        hemi,
                                        ctab=str(ctab),
                                        annot=str(annot))
        annots.append(annot)

    return vek['gcs'].__class__(*annots)

annot = 'atl-Cammoun2012_space-fsaverage_res-{}_hemi-{}_deterministic.annot'

if __name__ == '__main__':
    #####
    # get the GCS files and apply them onto the fsaverage surface
    gcs = datasets.fetch_cammoun2012('gcs')
    for scale, gcsfiles in gcs.items():
        for fn in gcsfiles:
            hemi = re.search('hemi-([RL])', fn).group(1)
            scale = re.search('res-(.*)_hemi-', fn).group(1)
            out = op.join(op.dirname(fn), annot.format(scale, hemi))
            freesurfer.apply_prob_atlas('fsaverage',
                                        fn,
                                        hemi.lower() + 'h',
                                        ctab=fn.replace('.gcs', '.ctab'),
                                        annot=out)

    #####
    # get scale 500 parcellation files and combine
    dirname = op.dirname(fn)
    lh = sorted(glob.glob(op.join(dirname, '*res-500*_hemi-L*annot')))
    rh = sorted(glob.glob(op.join(dirname, '*res-500*_hemi-R*annot')))
    annot = op.join(dirname, annot.format('500', '{}'))
    parc500 = combine_cammoun_500(lh, rh, 'fsaverage', annot=annot)
    for fn in lh + rh:
        os.remove(fn)

    #####
    # map all the WRONG .annot files to the correct ordering