@@ -82,8 +82,8 @@ class _GenerateCiftiInputSpec(BaseInterfaceInputSpec):
82
82
usedefault = True ,
83
83
desc = "CIFTI surface target space" ,
84
84
)
85
- surface_density = traits .Enum (
86
- "32k " , "59k " , desc = "Surface vertices density. "
85
+ grayordinates = traits .Enum (
86
+ "91k " , "170k " , usedefault = True , desc = "Final CIFTI grayordinates "
87
87
)
88
88
TR = traits .Float (mandatory = True , desc = "Repetition time" )
89
89
surface_bolds = traits .List (
@@ -94,10 +94,8 @@ class _GenerateCiftiInputSpec(BaseInterfaceInputSpec):
94
94
95
95
96
96
class _GenerateCiftiOutputSpec (TraitedSpec ):
97
- out_file = File (exists = True , desc = "generated CIFTI file" )
98
- out_metadata = File (exists = True , desc = "variant metadata JSON" )
99
- variant = traits .Str (desc = "Name of variant space" )
100
- density = traits .Str (desc = "Total number of grayordinates" )
97
+ out_file = File (desc = "generated CIFTI file" )
98
+ out_metadata = File (desc = "CIFTI metadata JSON" )
101
99
102
100
103
101
class GenerateCifti (SimpleInterface ):
@@ -108,7 +106,8 @@ class GenerateCifti(SimpleInterface):
108
106
output_spec = _GenerateCiftiOutputSpec
109
107
110
108
def _run_interface (self , runtime ):
111
- surface_labels , volume_labels , metadata = _prepare_cifti (self .inputs .surface_density )
109
+
110
+ surface_labels , volume_labels , metadata = _prepare_cifti (self .inputs .grayordinates )
112
111
self ._results ["out_file" ] = _create_cifti_image (
113
112
self .inputs .bold_file ,
114
113
volume_labels ,
@@ -167,14 +166,14 @@ def _run_interface(self, runtime):
167
166
return runtime
168
167
169
168
170
- def _prepare_cifti (surface_density : str ) -> typing .Tuple [list , str , dict ]:
169
+ def _prepare_cifti (grayordinates : str ) -> typing .Tuple [list , str , dict ]:
171
170
"""
172
171
Fetch the required templates needed for CIFTI-2 generation, based on input surface density.
173
172
174
173
Parameters
175
174
----------
176
- surface_density :
177
- Surface density (required for `fsLR` surfaces )
175
+ grayordinates :
176
+ Total CIFTI grayordinates (91k, 170k )
178
177
179
178
Returns
180
179
-------
@@ -187,7 +186,7 @@ def _prepare_cifti(surface_density: str) -> typing.Tuple[list, str, dict]:
187
186
188
187
Examples
189
188
--------
190
- >>> surface_labels, volume_labels, metadata = _prepare_cifti('32k ')
189
+ >>> surface_labels, volume_labels, metadata = _prepare_cifti('91k ')
191
190
>>> surface_labels # doctest: +ELLIPSIS
192
191
['.../tpl-fsLR_hemi-L_den-32k_desc-nomedialwall_dparc.label.gii', \
193
192
'.../tpl-fsLR_hemi-R_den-32k_desc-nomedialwall_dparc.label.gii']
@@ -199,24 +198,27 @@ def _prepare_cifti(surface_density: str) -> typing.Tuple[list, str, dict]:
199
198
200
199
"""
201
200
202
- vertices_key = {
203
- "32k" : {
201
+ grayord_key = {
202
+ "91k" : {
203
+ "surface-den" : "32k" ,
204
204
"tf-res" : "02" ,
205
205
"grayords" : "91,282" ,
206
206
"res-mm" : "2mm"
207
207
},
208
- "59k" : {
208
+ "170k" : {
209
+ "surface-den" : "59k" ,
209
210
"tf-res" : "06" ,
210
211
"grayords" : "170,494" ,
211
212
"res-mm" : "1.6mm"
212
213
}
213
214
}
214
- if surface_density not in vertices_key :
215
- raise NotImplementedError ("Density {surface_density } is not supported." )
215
+ if grayordinates not in grayord_key :
216
+ raise NotImplementedError ("Grayordinates {grayordinates } is not supported." )
216
217
217
- tf_vol_res = vertices_key [surface_density ]['tf-res' ]
218
- grayords = vertices_key [surface_density ]['grayords' ]
219
- res_mm = vertices_key [surface_density ]['res-mm' ]
218
+ tf_vol_res = grayord_key [grayordinates ]['tf-res' ]
219
+ total_grayords = grayord_key [grayordinates ]['grayords' ]
220
+ res_mm = grayord_key [grayordinates ]['res-mm' ]
221
+ surface_density = grayord_key [grayordinates ]['surface-den' ]
220
222
# Fetch templates
221
223
surface_labels = [
222
224
str (
@@ -248,7 +250,7 @@ def _prepare_cifti(surface_density: str) -> typing.Tuple[list, str, dict]:
248
250
)
249
251
metadata = {
250
252
"Density" : (
251
- f"{ grayords } grayordinates corresponding to all of the grey matter sampled at a "
253
+ f"{ total_grayords } grayordinates corresponding to all of the grey matter sampled at a "
252
254
f"{ res_mm } average vertex spacing on the surface and as { res_mm } voxels subcortically"
253
255
),
254
256
"SpatialReference" : {
@@ -257,7 +259,6 @@ def _prepare_cifti(surface_density: str) -> typing.Tuple[list, str, dict]:
257
259
"CIFTI_STRUCTURE_RIGHT_CORTEX" : surfaces_url % "R" ,
258
260
}
259
261
}
260
-
261
262
return surface_labels , volume_label , metadata
262
263
263
264
@@ -319,13 +320,8 @@ def _create_cifti_image(
319
320
# currently only supports L/R cortex
320
321
surf_ts = nb .load (bold_surfs [hemi == "RIGHT" ])
321
322
surf_verts = len (surf_ts .darrays [0 ].data )
322
- if surface_labels [0 ].endswith (".annot" ):
323
- annot = nb .freesurfer .read_annot (surface_labels [hemi == "RIGHT" ])
324
- # remove medial wall
325
- medial = np .nonzero (annot [0 ] != annot [2 ].index (b"unknown" ))[0 ]
326
- else :
327
- annot = nb .load (surface_labels [hemi == "RIGHT" ])
328
- medial = np .nonzero (annot .darrays [0 ].data )[0 ]
323
+ labels = nb .load (surface_labels [hemi == "RIGHT" ])
324
+ medial = np .nonzero (labels .darrays [0 ].data )[0 ]
329
325
# extract values across volumes
330
326
ts = np .array ([tsarr .data [medial ] for tsarr in surf_ts .darrays ])
331
327
0 commit comments