@@ -330,6 +330,7 @@ def _create_cifti_image(
330
330
BOLD data saved as CIFTI dtseries
331
331
"""
332
332
bold_img = nb .load (bold_file )
333
+ bold_dtype = bold_img .get_data_dtype ()
333
334
label_img = nb .load (label_file )
334
335
if label_img .shape != bold_img .shape [:3 ]:
335
336
warnings .warn ("Resampling bold volume to match label dimensions" )
@@ -339,7 +340,7 @@ def _create_cifti_image(
339
340
bold_img = _reorient_image (bold_img , orientation = "LAS" )
340
341
label_img = _reorient_image (label_img , orientation = "LAS" )
341
342
342
- bold_data = bold_img .get_fdata (dtype = "float32" )
343
+ bold_data = bold_img .get_fdata ()
343
344
timepoints = bold_img .shape [3 ]
344
345
label_data = np .asanyarray (label_img .dataobj ).astype ("int16" )
345
346
@@ -355,7 +356,7 @@ def _create_cifti_image(
355
356
hemi = structure .split ("_" )[- 1 ]
356
357
# currently only supports L/R cortex
357
358
surf = nb .load (bold_surfs [hemi == "RIGHT" ])
358
- surf_verts = len (surf .darrays [0 ]. data )
359
+ surf_verts = len (surf .agg_data () [0 ])
359
360
if annotation_files [0 ].endswith (".annot" ):
360
361
annot = nb .freesurfer .read_annot (annotation_files [hemi == "RIGHT" ])
361
362
# remove medial wall
@@ -391,7 +392,7 @@ def _create_cifti_image(
391
392
else np .concatenate ((ts , bold_data [ijk ]))
392
393
)
393
394
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 ) )
395
396
]
396
397
397
398
vox = ci .Cifti2VoxelIndicesIJK (vox )
@@ -403,7 +404,7 @@ def _create_cifti_image(
403
404
voxel_indices_ijk = vox ,
404
405
)
405
406
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 )
407
408
# add each brain structure to list
408
409
brainmodels .append (bm )
409
410
@@ -439,7 +440,7 @@ def _create_cifti_image(
439
440
matrix .append (geometry_map )
440
441
matrix .metadata = ci .Cifti2MetaData (meta )
441
442
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 )
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