11"""Tests the generation of new CIFTI2 files from scratch
22
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).
55
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.
78"""
89import numpy as np
910
2930
3031def create_geometry_map (applies_to_matrix_dimension ):
3132 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 )
3437 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 )
3742 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' ,
4048 maps = [left_thalamus , left_cortex , volume ])
4149
4250
4351def 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' )
4554 assert_equal (len (list (mapping .brain_models )), 2 )
4655 left_thalamus , left_cortex = mapping .brain_models
4756
@@ -68,15 +77,18 @@ def check_geometry_map(mapping):
6877 [61 , 59 , 60 ],
6978 [61 , 60 , 59 ],
7079 [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 ]))),
7384 ('mixed_parcel' , ([[71 , 81 , 39 ],
7485 [53 , 21 , 91 ]],
7586 ('CIFTI_STRUCTURE_CORTEX_LEFT' , [71 , 88 , 999 ])))]
7687
7788
7889def 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' )
8092 for name , elements in parcels :
8193 surfaces = []
8294 volume = None
@@ -89,7 +101,8 @@ def create_parcel_map(applies_to_matrix_dimension):
89101
90102 mapping .extend ([ci .Cifti2Surface ('CIFTI_STRUCTURE_CORTEX_%s' % orientation ,
91103 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 ))
93106 return mapping
94107
95108
@@ -109,7 +122,8 @@ def check_parcel_map(mapping):
109122 assert_equal (parcel .voxel_indices_ijk ._indices , element )
110123
111124 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 )
113127 assert_equal (surface .surface_number_of_vertices , number_of_vertices )
114128
115129 assert_equal (mapping .volume .volume_dimensions , dimensions )
@@ -121,8 +135,10 @@ def check_parcel_map(mapping):
121135
122136
123137def 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' ,
126142 maps = maps )
127143
128144
@@ -138,8 +154,9 @@ def check_scalar_map(mapping):
138154 assert_equal (named_map .metadata , expected [1 ])
139155
140156
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 ))}),
143160 ('another name' , {}, {0 : ('???' , (0 , 0 , 0 , 0 )),
144161 1 : ('great region' , (0.4 , 0.1 , 0.23 , 0.15 ))})]
145162
@@ -150,8 +167,10 @@ def create_label_map(applies_to_matrix_dimension):
150167 label_table = ci .Cifti2LabelTable ()
151168 for key , (tag , rgba ) in label .items ():
152169 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' ,
155174 maps = maps )
156175
157176
@@ -168,8 +187,10 @@ def check_label_map(mapping):
168187
169188
170189def 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 ,
173194 series_step = 10.5 , series_unit = 'SECOND' )
174195
175196
0 commit comments