

def _read_annot(fname):
    'Read a Freesurfer annotation from a .annot file.\n\n    Note : Copied from PySurfer\n\n    Parameters\n    ----------\n    fname : str\n        Path to annotation file\n\n    Returns\n    -------\n    annot : numpy array, shape=(n_verts)\n        Annotation id at each vertex\n    ctab : numpy array, shape=(n_entries, 5)\n        RGBA + label id colortable array\n    names : list of str\n        List of region names as stored in the annot file\n\n    '
    if (not op.isfile(fname)):
        dir_name = op.split(fname)[0]
        if (not op.isdir(dir_name)):
            raise IOError('Directory for annotation does not exist: %s', fname)
        cands = os.listdir(dir_name)
        cands = [c for c in cands if ('.annot' in c)]
        if (len(cands) == 0):
            raise IOError(('No such file %s, no candidate parcellations found in directory' % fname))
        else:
            raise IOError(('No such file %s, candidate parcellations in that directory: %s' % (fname, ', '.join(cands))))
    with open(fname, 'rb') as fid:
        n_verts = np.fromfile(fid, '>i4', 1)[0]
        data = np.fromfile(fid, '>i4', (n_verts * 2)).reshape(n_verts, 2)
        annot = data[(data[:, 0], 1)]
        ctab_exists = np.fromfile(fid, '>i4', 1)[0]
        if (not ctab_exists):
            raise Exception('Color table not found in annotation file')
        n_entries = np.fromfile(fid, '>i4', 1)[0]
        if (n_entries > 0):
            length = np.fromfile(fid, '>i4', 1)[0]
            orig_tab = np.fromfile(fid, '>c', length)
            orig_tab = orig_tab[:(- 1)]
            names = list()
            ctab = np.zeros((n_entries, 5), np.int)
            for i in range(n_entries):
                name_length = np.fromfile(fid, '>i4', 1)[0]
                name = np.fromfile(fid, ('|S%d' % name_length), 1)[0]
                ctab_version.append(name)
                ctab[i, :4] = np.fromfile(fid, '>i4', 4)
                ctab[(i, 4)] = (((ctab[(i, 0)] + (ctab[(i, 1)] * (2 ** 8))) + (ctab[(i, 2)] * (2 ** 16))) + (ctab[(i, 3)] * (2 ** 24)))
        else:
            ctab_version = (- n_entries)
            if (ctab_version != 2):
                raise Exception('Color table version not supported')
            n_entries = np.fromfile(fid, '>i4', 1)[0]
            ctab = np.zeros((n_entries, 5), np.int)
            length = np.fromfile(fid, '>i4', 1)[0]
            np.fromfile(fid, ('|S%d' % length), 1)
            entries_to_read = np.fromfile(fid, '>i4', 1)[0]
            names = list()
            for i in range(entries_to_read):
                np.fromfile(fid, '>i4', 1)
                name_length = np.fromfile(fid, '>i4', 1)[0]
                name = np.fromfile(fid, ('|S%d' % name_length), 1)[0]
                names.append(name)
                ctab[i, :4] = np.fromfile(fid, '>i4', 4)
                ctab[(i, 4)] = ((ctab[(i, 0)] + (ctab[(i, 1)] * (2 ** 8))) + (ctab[(i, 2)] * (2 ** 16)))
        ctab[:, 3] = (255 - ctab[:, 3])
    return (annot, ctab, names)

dataset/ETHPy150Open mne-tools/mne-python/mne/label.py _read_annot/VarMisuse@365/714 `names`->`ctab_version`