@@ -346,16 +346,16 @@ def _create_cifti_image(
346
346
# Create brain models
347
347
idx_offset = 0
348
348
brainmodels = []
349
- bm_ts = np .empty ((timepoints , 0 ))
349
+ bm_ts = np .empty ((timepoints , 0 ), dtype = "float32" )
350
350
351
351
for structure , labels in CIFTI_STRUCT_WITH_LABELS .items ():
352
352
if labels is None : # surface model
353
353
model_type = "CIFTI_MODEL_TYPE_SURFACE"
354
354
# use the corresponding annotation
355
355
hemi = structure .split ("_" )[- 1 ]
356
356
# currently only supports L/R cortex
357
- surf = nb .load (bold_surfs [hemi == "RIGHT" ])
358
- surf_verts = len (surf .darrays [0 ].data )
357
+ surf_ts = nb .load (bold_surfs [hemi == "RIGHT" ])
358
+ surf_verts = len (surf_ts .darrays [0 ].data )
359
359
if annotation_files [0 ].endswith (".annot" ):
360
360
annot = nb .freesurfer .read_annot (annotation_files [hemi == "RIGHT" ])
361
361
# remove medial wall
@@ -364,7 +364,7 @@ def _create_cifti_image(
364
364
annot = nb .load (annotation_files [hemi == "RIGHT" ])
365
365
medial = np .nonzero (annot .darrays [0 ].data )[0 ]
366
366
# extract values across volumes
367
- ts = np .array ([tsarr .data [medial ] for tsarr in surf .darrays ])
367
+ ts = np .array ([tsarr .data [medial ] for tsarr in surf_ts .darrays ])
368
368
369
369
vert_idx = ci .Cifti2VertexIndices (medial )
370
370
bm = ci .Cifti2BrainModel (
@@ -391,7 +391,7 @@ def _create_cifti_image(
391
391
else np .concatenate ((ts , bold_data [ijk ]))
392
392
)
393
393
vox += [
394
- [ijk [0 ][ix ], ijk [1 ][ix ], ijk [2 ][ix ]] for ix , row in enumerate ( ts )
394
+ [ijk [0 ][idx ], ijk [1 ][idx ], ijk [2 ][idx ]] for idx in range ( len ( ts ) )
395
395
]
396
396
397
397
vox = ci .Cifti2VoxelIndicesIJK (vox )
@@ -439,7 +439,8 @@ def _create_cifti_image(
439
439
matrix .append (geometry_map )
440
440
matrix .metadata = ci .Cifti2MetaData (meta )
441
441
hdr = ci .Cifti2Header (matrix )
442
- img = ci .Cifti2Image (bm_ts , hdr )
442
+ img = ci .Cifti2Image (dataobj = bm_ts , header = hdr )
443
+ img .set_data_dtype (bold_img .get_data_dtype ())
443
444
img .nifti_header .set_intent ("NIFTI_INTENT_CONNECTIVITY_DENSE_SERIES" )
444
445
445
446
out_file = "{}.dtseries.nii" .format (split_filename (bold_file )[1 ])
0 commit comments