3
3
from os .path import join as pjoin , isdir
4
4
import getpass
5
5
import time
6
+ import hashlib
7
+
6
8
7
9
from ...tmpdirs import InTemporaryDirectory
8
10
35
37
'cannot find freesurfer {0} directory' .format (DATA_SDIR ))
36
38
37
39
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
+
38
48
@freesurfer_test
39
49
def test_geometry ():
40
50
"""Test IO of .surf"""
@@ -90,6 +100,8 @@ def test_annot():
90
100
annots = ['aparc' , 'aparc.a2005s' ]
91
101
for a in annots :
92
102
annot_path = pjoin (data_path , "label" , "%s.%s.annot" % ("lh" , a ))
103
+ hash_ = _hash_file_content (annot_path )
104
+
93
105
labels , ctab , names = read_annot (annot_path )
94
106
assert_true (labels .shape == (163842 , ))
95
107
assert_true (ctab .shape == (len (names ), 5 ))
@@ -98,7 +110,14 @@ def test_annot():
98
110
if a == 'aparc' :
99
111
labels_orig , _ , _ = read_annot (annot_path , orig_ids = True )
100
112
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." )
102
121
103
122
# Test equivalence of freesurfer- and nibabel-generated annot files
104
123
# with respect to read_annot()
0 commit comments