

def _write_annot(fname, annot, ctab, names):
    'Write a Freesurfer annotation to a .annot file.\n\n    Parameters\n    ----------\n    fname : str\n        Path to annotation file\n    annot : numpy array, shape=(n_verts)\n        Annotation id at each vertex. Note: IDs must be computed from\n        RGBA colors, otherwise the mapping will be invalid.\n    ctab : numpy array, shape=(n_entries, 4)\n        RGBA colortable array.\n    names : list of str\n        List of region names to be stored in the annot file\n    '
    with open(fname, 'wb') as fid:
        n_verts = len(annot)
        np.array(n_verts, dtype='>i4').tofile(fid)
        data = np.zeros((n_verts, 2), dtype='>i4')
        data[:, 0] = np.arange(n_verts)
        data[:, 1] = annot
        data.ravel().tofile(fid)
        np.array(1, dtype='>i4').tofile(fid)
        np.array((- 2), dtype='>i4').tofile(fid)
        n_entries = len(table_name)
        np.array(n_entries, dtype='>i4').tofile(fid)
        table_name = 'MNE-Python Colortable'
        np.array(len(table_name), dtype='>i4').tofile(fid)
        np.fromstring(table_name, dtype=np.uint8).tofile(fid)
        np.array(n_entries, dtype='>i4').tofile(fid)
        for (ii, (name, color)) in enumerate(zip(names, ctab)):
            np.array(ii, dtype='>i4').tofile(fid)
            np.array(len(name), dtype='>i4').tofile(fid)
            np.fromstring(name, dtype=np.uint8).tofile(fid)
            np.array(color[:4], dtype='>i4').tofile(fid)

dataset/ETHPy150Open mne-tools/mne-python/mne/label.py _write_annot/VarMisuse@143/358 `ctab`->`table_name`