1
1
"""Tests the generation of new CIFTI2 files from scratch
2
2
3
- Contains a series of functions to create and check each of the 5 CIFTI index types
4
- (i.e. BRAIN_MODELS, PARCELS, SCALARS, LABELS, and SERIES).
3
+ Contains a series of functions to create and check each of the 5 CIFTI index
4
+ types (i.e. BRAIN_MODELS, PARCELS, SCALARS, LABELS, and SERIES).
5
5
6
- These functions are used in the tests to generate most CIFTI file types from scratch.
6
+ These functions are used in the tests to generate most CIFTI file types from
7
+ scratch.
7
8
"""
8
9
import numpy as np
9
10
29
30
30
31
def create_geometry_map (applies_to_matrix_dimension ):
31
32
voxels = ci .Cifti2VoxelIndicesIJK (brain_models [0 ][1 ])
32
- left_thalamus = ci .Cifti2BrainModel (index_offset = 0 , index_count = 4 , model_type = 'CIFTI_MODEL_TYPE_VOXELS' ,
33
- brain_structure = brain_models [0 ][0 ], voxel_indices_ijk = voxels )
33
+ left_thalamus = ci .Cifti2BrainModel (index_offset = 0 , index_count = 4 ,
34
+ model_type = 'CIFTI_MODEL_TYPE_VOXELS' ,
35
+ brain_structure = brain_models [0 ][0 ],
36
+ voxel_indices_ijk = voxels )
34
37
vertices = ci .Cifti2VertexIndices (np .array (brain_models [1 ][1 ]))
35
- left_cortex = ci .Cifti2BrainModel (index_offset = 4 , index_count = 5 , model_type = 'CIFTI_MODEL_TYPE_SURFACE' ,
36
- brain_structure = brain_models [1 ][0 ], vertex_indices = vertices )
38
+ left_cortex = ci .Cifti2BrainModel (index_offset = 4 , index_count = 5 ,
39
+ model_type = 'CIFTI_MODEL_TYPE_SURFACE' ,
40
+ brain_structure = brain_models [1 ][0 ],
41
+ vertex_indices = vertices )
37
42
left_cortex .surface_number_of_vertices = number_of_vertices
38
- volume = ci .Cifti2Volume (dimensions , ci .Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ (- 3 , affine ))
39
- return ci .Cifti2MatrixIndicesMap (applies_to_matrix_dimension , 'CIFTI_INDEX_TYPE_BRAIN_MODELS' ,
43
+ volume = ci .Cifti2Volume (dimensions ,
44
+ ci .Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ (- 3 ,
45
+ affine ))
46
+ return ci .Cifti2MatrixIndicesMap (applies_to_matrix_dimension ,
47
+ 'CIFTI_INDEX_TYPE_BRAIN_MODELS' ,
40
48
maps = [left_thalamus , left_cortex , volume ])
41
49
42
50
43
51
def check_geometry_map (mapping ):
44
- assert_equal (mapping .indices_map_to_data_type , 'CIFTI_INDEX_TYPE_BRAIN_MODELS' )
52
+ assert_equal (mapping .indices_map_to_data_type ,
53
+ 'CIFTI_INDEX_TYPE_BRAIN_MODELS' )
45
54
assert_equal (len (list (mapping .brain_models )), 2 )
46
55
left_thalamus , left_cortex = mapping .brain_models
47
56
@@ -68,15 +77,18 @@ def check_geometry_map(mapping):
68
77
[61 , 59 , 60 ],
69
78
[61 , 60 , 59 ],
70
79
[80 , 90 , 92 ]], )),
71
- ('surface_parcel' , (('CIFTI_STRUCTURE_CORTEX_LEFT' , [0 , 1000 , 1301 , 19972 , 27312 ]),
72
- ('CIFTI_STRUCTURE_CORTEX_RIGHT' , [0 , 100 , 381 ]))),
80
+ ('surface_parcel' , (('CIFTI_STRUCTURE_CORTEX_LEFT' ,
81
+ [0 , 1000 , 1301 , 19972 , 27312 ]),
82
+ ('CIFTI_STRUCTURE_CORTEX_RIGHT' ,
83
+ [0 , 100 , 381 ]))),
73
84
('mixed_parcel' , ([[71 , 81 , 39 ],
74
85
[53 , 21 , 91 ]],
75
86
('CIFTI_STRUCTURE_CORTEX_LEFT' , [71 , 88 , 999 ])))]
76
87
77
88
78
89
def create_parcel_map (applies_to_matrix_dimension ):
79
- mapping = ci .Cifti2MatrixIndicesMap (applies_to_matrix_dimension , 'CIFTI_INDEX_TYPE_PARCELS' )
90
+ mapping = ci .Cifti2MatrixIndicesMap (applies_to_matrix_dimension ,
91
+ 'CIFTI_INDEX_TYPE_PARCELS' )
80
92
for name , elements in parcels :
81
93
surfaces = []
82
94
volume = None
@@ -89,7 +101,8 @@ def create_parcel_map(applies_to_matrix_dimension):
89
101
90
102
mapping .extend ([ci .Cifti2Surface ('CIFTI_STRUCTURE_CORTEX_%s' % orientation ,
91
103
number_of_vertices ) for orientation in ['LEFT' , 'RIGHT' ]])
92
- mapping .volume = ci .Cifti2Volume (dimensions , ci .Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ (- 3 , affine ))
104
+ mapping .volume = ci .Cifti2Volume (dimensions ,
105
+ ci .Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ (- 3 , affine ))
93
106
return mapping
94
107
95
108
@@ -109,7 +122,8 @@ def check_parcel_map(mapping):
109
122
assert_equal (parcel .voxel_indices_ijk ._indices , element )
110
123
111
124
for surface , orientation in zip (mapping .surfaces , ('LEFT' , 'RIGHT' )):
112
- assert_equal (surface .brain_structure , 'CIFTI_STRUCTURE_CORTEX_%s' % orientation )
125
+ assert_equal (surface .brain_structure ,
126
+ 'CIFTI_STRUCTURE_CORTEX_%s' % orientation )
113
127
assert_equal (surface .surface_number_of_vertices , number_of_vertices )
114
128
115
129
assert_equal (mapping .volume .volume_dimensions , dimensions )
@@ -121,8 +135,10 @@ def check_parcel_map(mapping):
121
135
122
136
123
137
def create_scalar_map (applies_to_matrix_dimension ):
124
- maps = [ci .Cifti2NamedMap (name , ci .Cifti2MetaData (meta )) for name , meta in scalars ]
125
- return ci .Cifti2MatrixIndicesMap (applies_to_matrix_dimension , 'CIFTI_INDEX_TYPE_SCALARS' ,
138
+ maps = [ci .Cifti2NamedMap (name , ci .Cifti2MetaData (meta ))
139
+ for name , meta in scalars ]
140
+ return ci .Cifti2MatrixIndicesMap (applies_to_matrix_dimension ,
141
+ 'CIFTI_INDEX_TYPE_SCALARS' ,
126
142
maps = maps )
127
143
128
144
@@ -138,8 +154,9 @@ def check_scalar_map(mapping):
138
154
assert_equal (named_map .metadata , expected [1 ])
139
155
140
156
141
- labels = [('first_name' , {'meta_key' : 'some_metadata' }, {0 : ('label0' , (0.1 , 0.3 , 0.2 , 0.5 )),
142
- 1 : ('new_label' , (0.5 , 0.3 , 0.1 , 0.4 ))}),
157
+ labels = [('first_name' , {'meta_key' : 'some_metadata' },
158
+ {0 : ('label0' , (0.1 , 0.3 , 0.2 , 0.5 )),
159
+ 1 : ('new_label' , (0.5 , 0.3 , 0.1 , 0.4 ))}),
143
160
('another name' , {}, {0 : ('???' , (0 , 0 , 0 , 0 )),
144
161
1 : ('great region' , (0.4 , 0.1 , 0.23 , 0.15 ))})]
145
162
@@ -150,8 +167,10 @@ def create_label_map(applies_to_matrix_dimension):
150
167
label_table = ci .Cifti2LabelTable ()
151
168
for key , (tag , rgba ) in label .items ():
152
169
label_table [key ] = ci .Cifti2Label (key , tag , * rgba )
153
- maps .append (ci .Cifti2NamedMap (name , ci .Cifti2MetaData (meta ), label_table ))
154
- return ci .Cifti2MatrixIndicesMap (applies_to_matrix_dimension , 'CIFTI_INDEX_TYPE_LABELS' ,
170
+ maps .append (ci .Cifti2NamedMap (name , ci .Cifti2MetaData (meta ),
171
+ label_table ))
172
+ return ci .Cifti2MatrixIndicesMap (applies_to_matrix_dimension ,
173
+ 'CIFTI_INDEX_TYPE_LABELS' ,
155
174
maps = maps )
156
175
157
176
@@ -168,8 +187,10 @@ def check_label_map(mapping):
168
187
169
188
170
189
def create_series_map (applies_to_matrix_dimension ):
171
- return ci .Cifti2MatrixIndicesMap (applies_to_matrix_dimension , 'CIFTI_INDEX_TYPE_SERIES' ,
172
- number_of_series_points = 13 , series_exponent = - 3 , series_start = 18.2 ,
190
+ return ci .Cifti2MatrixIndicesMap (applies_to_matrix_dimension ,
191
+ 'CIFTI_INDEX_TYPE_SERIES' ,
192
+ number_of_series_points = 13 ,
193
+ series_exponent = - 3 , series_start = 18.2 ,
173
194
series_step = 10.5 , series_unit = 'SECOND' )
174
195
175
196
0 commit comments