@@ -330,7 +330,6 @@ 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 ()
334
333
label_img = nb .load (label_file )
335
334
if label_img .shape != bold_img .shape [:3 ]:
336
335
warnings .warn ("Resampling bold volume to match label dimensions" )
@@ -340,23 +339,23 @@ def _create_cifti_image(
340
339
bold_img = _reorient_image (bold_img , orientation = "LAS" )
341
340
label_img = _reorient_image (label_img , orientation = "LAS" )
342
341
343
- bold_data = bold_img .get_fdata ()
342
+ bold_data = bold_img .get_fdata (dtype = "float32" )
344
343
timepoints = bold_img .shape [3 ]
345
344
label_data = np .asanyarray (label_img .dataobj ).astype ("int16" )
346
345
347
346
# Create brain models
348
347
idx_offset = 0
349
348
brainmodels = []
350
- bm_ts = np .empty ((timepoints , 0 ))
349
+ bm_ts = np .empty ((timepoints , 0 ), dtype = "float32" )
351
350
352
351
for structure , labels in CIFTI_STRUCT_WITH_LABELS .items ():
353
352
if labels is None : # surface model
354
353
model_type = "CIFTI_MODEL_TYPE_SURFACE"
355
354
# use the corresponding annotation
356
355
hemi = structure .split ("_" )[- 1 ]
357
356
# currently only supports L/R cortex
358
- surf = nb .load (bold_surfs [hemi == "RIGHT" ])
359
- surf_verts = len (surf . agg_data () [0 ])
357
+ surf_ts = nb .load (bold_surfs [hemi == "RIGHT" ])
358
+ surf_verts = len (surf_ts . darrays [0 ]. data )
360
359
if annotation_files [0 ].endswith (".annot" ):
361
360
annot = nb .freesurfer .read_annot (annotation_files [hemi == "RIGHT" ])
362
361
# remove medial wall
@@ -365,7 +364,7 @@ def _create_cifti_image(
365
364
annot = nb .load (annotation_files [hemi == "RIGHT" ])
366
365
medial = np .nonzero (annot .darrays [0 ].data )[0 ]
367
366
# extract values across volumes
368
- ts = np .array ([tsarr .data [medial ] for tsarr in surf .darrays ])
367
+ ts = np .array ([tsarr .data [medial ] for tsarr in surf_ts .darrays ])
369
368
370
369
vert_idx = ci .Cifti2VertexIndices (medial )
371
370
bm = ci .Cifti2BrainModel (
@@ -404,7 +403,7 @@ def _create_cifti_image(
404
403
voxel_indices_ijk = vox ,
405
404
)
406
405
idx_offset += len (vox )
407
- bm_ts = np .column_stack ((bm_ts , ts .T )). astype ( bold_dtype )
406
+ bm_ts = np .column_stack ((bm_ts , ts .T ))
408
407
# add each brain structure to list
409
408
brainmodels .append (bm )
410
409
@@ -440,7 +439,8 @@ def _create_cifti_image(
440
439
matrix .append (geometry_map )
441
440
matrix .metadata = ci .Cifti2MetaData (meta )
442
441
hdr = ci .Cifti2Header (matrix )
443
- img = ci .Cifti2Image (dataobj = bm_ts , header = hdr , nifti_header = bold_img .header )
442
+ img = ci .Cifti2Image (dataobj = bm_ts , header = hdr )
443
+ img .set_data_dtype (bold_img .get_data_dtype ())
444
444
img .nifti_header .set_intent ("NIFTI_INTENT_CONNECTIVITY_DENSE_SERIES" )
445
445
446
446
out_file = "{}.dtseries.nii" .format (split_filename (bold_file )[1 ])
0 commit comments