@@ -330,6 +330,7 @@ def _create_cifti_image(
330330 BOLD data saved as CIFTI dtseries
331331 """
332332 bold_img = nb .load (bold_file )
333+ bold_dtype = bold_img .get_data_dtype ()
333334 label_img = nb .load (label_file )
334335 if label_img .shape != bold_img .shape [:3 ]:
335336 warnings .warn ("Resampling bold volume to match label dimensions" )
@@ -339,7 +340,7 @@ def _create_cifti_image(
339340 bold_img = _reorient_image (bold_img , orientation = "LAS" )
340341 label_img = _reorient_image (label_img , orientation = "LAS" )
341342
342- bold_data = bold_img .get_fdata (dtype = "float32" )
343+ bold_data = bold_img .get_fdata ()
343344 timepoints = bold_img .shape [3 ]
344345 label_data = np .asanyarray (label_img .dataobj ).astype ("int16" )
345346
@@ -355,7 +356,7 @@ def _create_cifti_image(
355356 hemi = structure .split ("_" )[- 1 ]
356357 # currently only supports L/R cortex
357358 surf = nb .load (bold_surfs [hemi == "RIGHT" ])
358- surf_verts = len (surf .darrays [0 ]. data )
359+ surf_verts = len (surf .agg_data () [0 ])
359360 if annotation_files [0 ].endswith (".annot" ):
360361 annot = nb .freesurfer .read_annot (annotation_files [hemi == "RIGHT" ])
361362 # remove medial wall
@@ -391,7 +392,7 @@ def _create_cifti_image(
391392 else np .concatenate ((ts , bold_data [ijk ]))
392393 )
393394 vox += [
394- [ijk [0 ][ix ], ijk [1 ][ix ], ijk [2 ][ix ]] for ix , row in enumerate ( ts )
395+ [ijk [0 ][idx ], ijk [1 ][idx ], ijk [2 ][idx ]] for idx in range ( len ( ts ) )
395396 ]
396397
397398 vox = ci .Cifti2VoxelIndicesIJK (vox )
@@ -403,7 +404,7 @@ def _create_cifti_image(
403404 voxel_indices_ijk = vox ,
404405 )
405406 idx_offset += len (vox )
406- bm_ts = np .column_stack ((bm_ts , ts .T ))
407+ bm_ts = np .column_stack ((bm_ts , ts .T )). astype ( bold_dtype )
407408 # add each brain structure to list
408409 brainmodels .append (bm )
409410
@@ -439,7 +440,7 @@ def _create_cifti_image(
439440 matrix .append (geometry_map )
440441 matrix .metadata = ci .Cifti2MetaData (meta )
441442 hdr = ci .Cifti2Header (matrix )
442- img = ci .Cifti2Image (bm_ts , hdr )
443+ img = ci .Cifti2Image (dataobj = bm_ts , header = hdr , nifti_header = bold_img . header )
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