@@ -346,16 +346,16 @@ def _create_cifti_image(
346346 # Create brain models
347347 idx_offset = 0
348348 brainmodels = []
349- bm_ts = np .empty ((timepoints , 0 ))
349+ bm_ts = np .empty ((timepoints , 0 ), dtype = "float32" )
350350
351351 for structure , labels in CIFTI_STRUCT_WITH_LABELS .items ():
352352 if labels is None : # surface model
353353 model_type = "CIFTI_MODEL_TYPE_SURFACE"
354354 # use the corresponding annotation
355355 hemi = structure .split ("_" )[- 1 ]
356356 # 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 )
359359 if annotation_files [0 ].endswith (".annot" ):
360360 annot = nb .freesurfer .read_annot (annotation_files [hemi == "RIGHT" ])
361361 # remove medial wall
@@ -364,7 +364,7 @@ def _create_cifti_image(
364364 annot = nb .load (annotation_files [hemi == "RIGHT" ])
365365 medial = np .nonzero (annot .darrays [0 ].data )[0 ]
366366 # 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 ])
368368
369369 vert_idx = ci .Cifti2VertexIndices (medial )
370370 bm = ci .Cifti2BrainModel (
@@ -391,7 +391,7 @@ def _create_cifti_image(
391391 else np .concatenate ((ts , bold_data [ijk ]))
392392 )
393393 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 ) )
395395 ]
396396
397397 vox = ci .Cifti2VoxelIndicesIJK (vox )
@@ -439,7 +439,8 @@ def _create_cifti_image(
439439 matrix .append (geometry_map )
440440 matrix .metadata = ci .Cifti2MetaData (meta )
441441 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 ())
443444 img .nifti_header .set_intent ("NIFTI_INTENT_CONNECTIVITY_DENSE_SERIES" )
444445
445446 out_file = "{}.dtseries.nii" .format (split_filename (bold_file )[1 ])
0 commit comments