9
9
from __future__ import division , print_function , absolute_import
10
10
11
11
from os .path import join as pjoin , dirname
12
- import sys
13
12
import io
14
13
from distutils .version import LooseVersion
15
14
16
- import numpy as np
17
-
18
15
import nibabel as nib
19
16
from nibabel import cifti2 as ci
20
17
from nibabel .tmpdirs import InTemporaryDirectory
21
18
from nibabel .tests .nibabel_data import get_nibabel_data , needs_nibabel_data
22
19
23
- from numpy .testing import assert_array_equal , assert_array_almost_equal
24
- from nose .tools import (assert_true , assert_false , assert_equal ,
25
- assert_raises )
20
+ from numpy .testing import assert_array_almost_equal
21
+ from nose .tools import (assert_true , assert_equal , assert_raises )
26
22
27
23
NIBABEL_TEST_DATA = pjoin (dirname (nib .__file__ ), 'tests' , 'data' )
28
24
NIFTI2_DATA = pjoin (NIBABEL_TEST_DATA , 'example_nifti2.nii.gz' )
@@ -48,24 +44,28 @@ def test_read_nifti2():
48
44
filemap [k ].fileobj = io .open (NIFTI2_DATA )
49
45
assert_raises (ValueError , ci .Cifti2Image .from_file_map , filemap )
50
46
47
+
51
48
@needs_nibabel_data ('nitest-cifti2' )
52
49
def test_read_internal ():
53
50
img2 = ci .load (DATA_FILE6 )
54
51
assert_true (isinstance (img2 .header , ci .Cifti2Header ))
55
52
assert_equal (img2 .shape , (1 , 91282 ))
56
53
54
+
57
55
@needs_nibabel_data ('nitest-cifti2' )
58
56
def test_read ():
59
57
img2 = nib .load (DATA_FILE6 )
60
58
assert_true (isinstance (img2 .header , ci .Cifti2Header ))
61
59
assert_equal (img2 .shape , (1 , 91282 ))
62
60
61
+
63
62
@needs_nibabel_data ('nitest-cifti2' )
64
63
def test_version ():
65
64
for i , dat in enumerate (datafiles ):
66
65
img = nib .load (dat )
67
66
assert_equal (LooseVersion (img .header .version ), LooseVersion ('2' ))
68
67
68
+
69
69
@needs_nibabel_data ('nitest-cifti2' )
70
70
def test_readwritedata ():
71
71
with InTemporaryDirectory ():
@@ -78,8 +78,10 @@ def test_readwritedata():
78
78
# Order should be preserved in load/save
79
79
for mim1 , mim2 in zip (img .header .matrix ,
80
80
img2 .header .matrix ):
81
- named_maps1 = [m_ for m_ in mim1 if isinstance (m_ , ci .Cifti2NamedMap )]
82
- named_maps2 = [m_ for m_ in mim2 if isinstance (m_ , ci .Cifti2NamedMap )]
81
+ named_maps1 = [m_ for m_ in mim1
82
+ if isinstance (m_ , ci .Cifti2NamedMap )]
83
+ named_maps2 = [m_ for m_ in mim2
84
+ if isinstance (m_ , ci .Cifti2NamedMap )]
83
85
assert_equal (len (named_maps1 ), len (named_maps2 ))
84
86
for map1 , map2 in zip (named_maps1 , named_maps2 ):
85
87
assert_equal (map1 .map_name , map2 .map_name )
@@ -103,8 +105,10 @@ def test_nibabel_readwritedata():
103
105
# Order should be preserved in load/save
104
106
for mim1 , mim2 in zip (img .header .matrix ,
105
107
img2 .header .matrix ):
106
- named_maps1 = [m_ for m_ in mim1 if isinstance (m_ , ci .Cifti2NamedMap )]
107
- named_maps2 = [m_ for m_ in mim2 if isinstance (m_ , ci .Cifti2NamedMap )]
108
+ named_maps1 = [m_ for m_ in mim1
109
+ if isinstance (m_ , ci .Cifti2NamedMap )]
110
+ named_maps2 = [m_ for m_ in mim2
111
+ if isinstance (m_ , ci .Cifti2NamedMap )]
108
112
assert_equal (len (named_maps1 ), len (named_maps2 ))
109
113
for map1 , map2 in zip (named_maps1 , named_maps2 ):
110
114
assert_equal (map1 .map_name , map2 .map_name )
@@ -148,15 +152,17 @@ def test_cifti2types():
148
152
counter [ci .Cifti2BrainModel ] += 1
149
153
if isinstance (map_ .vertex_indices , ci .Cifti2VertexIndices ):
150
154
counter [ci .Cifti2VertexIndices ] += 1
151
- if isinstance (map_ .voxel_indices_ijk , ci .Cifti2VoxelIndicesIJK ):
155
+ if isinstance (map_ .voxel_indices_ijk ,
156
+ ci .Cifti2VoxelIndicesIJK ):
152
157
counter [ci .Cifti2VoxelIndicesIJK ] += 1
153
158
elif isinstance (map_ , ci .Cifti2NamedMap ):
154
159
counter [ci .Cifti2NamedMap ] += 1
155
160
assert_true (isinstance (map_ .metadata , ci .Cifti2MetaData ))
156
161
if isinstance (map_ .label_table , ci .Cifti2LabelTable ):
157
162
counter [ci .Cifti2LabelTable ] += 1
158
163
for label in map_ .label_table :
159
- assert_true (isinstance (map_ .label_table [label ], ci .Cifti2Label ))
164
+ assert_true (isinstance (map_ .label_table [label ],
165
+ ci .Cifti2Label ))
160
166
counter [ci .Cifti2Label ] += 1
161
167
elif isinstance (map_ , ci .Cifti2Parcel ):
162
168
counter [ci .Cifti2Parcel ] += 1
@@ -175,11 +181,16 @@ def test_cifti2types():
175
181
ci .Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ ):
176
182
counter [ci .Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ ] += 1
177
183
178
- assert_equal (list (mim .named_maps ), [m_ for m_ in mim if isinstance (m_ , ci .Cifti2NamedMap )])
179
- assert_equal (list (mim .surfaces ), [m_ for m_ in mim if isinstance (m_ , ci .Cifti2Surface )])
180
- assert_equal (list (mim .parcels ), [m_ for m_ in mim if isinstance (m_ , ci .Cifti2Parcel )])
181
- assert_equal (list (mim .brain_models ), [m_ for m_ in mim if isinstance (m_ , ci .Cifti2BrainModel )])
182
- assert_equal ([mim .volume ] if mim .volume else [], [m_ for m_ in mim if isinstance (m_ , ci .Cifti2Volume )])
184
+ assert_equal (list (mim .named_maps ),
185
+ [m_ for m_ in mim if isinstance (m_ , ci .Cifti2NamedMap )])
186
+ assert_equal (list (mim .surfaces ),
187
+ [m_ for m_ in mim if isinstance (m_ , ci .Cifti2Surface )])
188
+ assert_equal (list (mim .parcels ),
189
+ [m_ for m_ in mim if isinstance (m_ , ci .Cifti2Parcel )])
190
+ assert_equal (list (mim .brain_models ),
191
+ [m_ for m_ in mim if isinstance (m_ , ci .Cifti2BrainModel )])
192
+ assert_equal ([mim .volume ] if mim .volume else [],
193
+ [m_ for m_ in mim if isinstance (m_ , ci .Cifti2Volume )])
183
194
184
195
for klass , count in counter .items ():
185
196
assert_true (count > 0 , "No exercise of " + klass .__name__ )
0 commit comments