Skip to content

Commit 548587e

Browse files
committed
FIX : handle versions of fsaverage
1 parent b916324 commit 548587e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

nibabel/freesurfer/tests/test_io.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from os.path import join as pjoin, isdir
44
import getpass
55
import time
6+
import hashlib
7+
68

79
from ...tmpdirs import InTemporaryDirectory
810

@@ -35,6 +37,14 @@
3537
'cannot find freesurfer {0} directory'.format(DATA_SDIR))
3638

3739

40+
def _hash_file_content(fname):
41+
hasher = hashlib.md5()
42+
with open(fname, 'rb') as afile:
43+
buf = afile.read()
44+
hasher.update(buf)
45+
return hasher.hexdigest()
46+
47+
3848
@freesurfer_test
3949
def test_geometry():
4050
"""Test IO of .surf"""
@@ -90,6 +100,8 @@ def test_annot():
90100
annots = ['aparc', 'aparc.a2005s']
91101
for a in annots:
92102
annot_path = pjoin(data_path, "label", "%s.%s.annot" % ("lh", a))
103+
hash_ = _hash_file_content(annot_path)
104+
93105
labels, ctab, names = read_annot(annot_path)
94106
assert_true(labels.shape == (163842, ))
95107
assert_true(ctab.shape == (len(names), 5))
@@ -98,7 +110,14 @@ def test_annot():
98110
if a == 'aparc':
99111
labels_orig, _, _ = read_annot(annot_path, orig_ids=True)
100112
np.testing.assert_array_equal(labels == -1, labels_orig == 0)
101-
assert_true(np.sum(labels_orig == 0) > 0)
113+
# Handle different version of fsaverage
114+
if hash_ == 'bf0b488994657435cdddac5f107d21e8':
115+
assert_true(np.sum(labels_orig == 0) == 13887)
116+
elif hash_ == 'd4f5b7cbc2ed363ac6fcf89e19353504':
117+
assert_true(np.sum(labels_orig == 1639705) == 13327)
118+
else:
119+
raise RuntimeError("Unknown freesurfer file. Please report "
120+
"the problem to the maintainer of nibabel.")
102121

103122
# Test equivalence of freesurfer- and nibabel-generated annot files
104123
# with respect to read_annot()

0 commit comments

Comments
 (0)