Skip to content

Commit 7af65ce

Browse files
committed
TEST: Test write_annot fill_ctab parameter
1 parent fccda24 commit 7af65ce

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

nibabel/freesurfer/tests/test_io.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def test_annot():
209209
assert_equal(names, names2)
210210

211211

212-
def test_annot_readback():
212+
def test_read_write_annot():
213213

214214
# This annot file will store a LUT for a mesh made of 10 vertices, with
215215
# 3 colours in the LUT.
@@ -245,9 +245,31 @@ def test_annot_readback():
245245
annot_path = 'c.annot'
246246

247247
with InTemporaryDirectory():
248-
write_annot(annot_path, labels, rgbal, names)
248+
write_annot(annot_path, labels, rgbal, names, fill_ctab=False)
249249
labels2, rgbal2, names2 = read_annot(annot_path)
250250
assert np.all(np.isclose(rgbal2, rgbal))
251+
assert np.all(np.isclose(labels2, labels))
252+
assert names2 == names
253+
254+
255+
def test_write_annot_fill_ctab():
256+
257+
nvertices = 10
258+
nlabels = 3
259+
names = ['label {}'.format(l) for l in range(1, nlabels + 1)]
260+
labels = list(range(nlabels)) + \
261+
list(np.random.randint(0, nlabels, nvertices - nlabels))
262+
labels = np.array(labels, dtype=np.int32)
263+
np.random.shuffle(labels)
264+
rgbal = np.random.randint(0, 255, (nlabels, 4), dtype=np.int32)
265+
annot_path = 'c.annot'
266+
267+
with InTemporaryDirectory():
268+
write_annot(annot_path, labels, rgbal, names, fill_ctab=True)
269+
labels2, rgbal2, names2 = read_annot(annot_path)
270+
assert np.all(np.isclose(rgbal2[:, :4], rgbal))
271+
assert np.all(np.isclose(labels2, labels))
272+
assert names2 == names
251273

252274

253275
@freesurfer_test

0 commit comments

Comments
 (0)