MCPcopy
hub / github.com/mne-tools/mne-python / _write_annot

Function _write_annot

mne/label.py:2583–2615  ·  view source on GitHub ↗

Write a Freesurfer annotation to a .annot file.

(fname, annot, ctab, names, table_name=_DEFAULT_TABLE_NAME)

Source from the content-addressed store, hash-verified

2581
2582
2583def _write_annot(fname, annot, ctab, names, table_name=_DEFAULT_TABLE_NAME):
2584 """Write a Freesurfer annotation to a .annot file."""
2585 assert len(names) == len(ctab)
2586 with open(fname, "wb") as fid:
2587 n_verts = len(annot)
2588 np.array(n_verts, dtype=">i4").tofile(fid)
2589
2590 data = np.zeros((n_verts, 2), dtype=">i4")
2591 data[:, 0] = np.arange(n_verts)
2592 data[:, 1] = annot
2593 data.ravel().tofile(fid)
2594
2595 # indicate that color table exists
2596 np.array(1, dtype=">i4").tofile(fid)
2597
2598 # color table version 2
2599 np.array(-2, dtype=">i4").tofile(fid)
2600
2601 # write color table
2602 n_entries = len(ctab)
2603 np.array(n_entries, dtype=">i4").tofile(fid)
2604
2605 # write our color table name
2606 _write_annot_str(fid, table_name)
2607
2608 # number of entries to write
2609 np.array(n_entries, dtype=">i4").tofile(fid)
2610
2611 # write entries
2612 for ii, (name, color) in enumerate(zip(names, ctab)):
2613 np.array(ii, dtype=">i4").tofile(fid)
2614 _write_annot_str(fid, name)
2615 np.array(color[:4], dtype=">i4").tofile(fid)
2616
2617
2618def _write_annot_str(fid, s):

Callers 1

write_labels_to_annotFunction · 0.85

Calls 1

_write_annot_strFunction · 0.85

Tested by

no test coverage detected