FIX: Avoid diverting dtype from original
@@ -330,6 +330,7 @@ def _create_cifti_image(
BOLD data saved as CIFTI dtseries
"""
bold_img = nb.load(bold_file)
+ bold_dtype = bold_img.get_data_dtype()
label_img = nb.load(label_file)
if label_img.shape != bold_img.shape[:3]:
warnings.warn("Resampling bold volume to match label dimensions")
@@ -339,7 +340,7 @@ def _create_cifti_image(
bold_img = _reorient_image(bold_img, orientation="LAS")
label_img = _reorient_image(label_img, orientation="LAS")
- bold_data = bold_img.get_fdata(dtype="float32")
+ bold_data = bold_img.get_fdata()
timepoints = bold_img.shape[3]
label_data = np.asanyarray(label_img.dataobj).astype("int16")
@@ -355,7 +356,7 @@ def _create_cifti_image(
hemi = structure.split("_")[-1]
# currently only supports L/R cortex
surf = nb.load(bold_surfs[hemi == "RIGHT"])
- surf_verts = len(surf.darrays[0].data)
+ surf_verts = len(surf.agg_data()[0])
if annotation_files[0].endswith(".annot"):
annot = nb.freesurfer.read_annot(annotation_files[hemi == "RIGHT"])
# remove medial wall
@@ -391,7 +392,7 @@ def _create_cifti_image(
else np.concatenate((ts, bold_data[ijk]))
)
vox += [
- [ijk[0][ix], ijk[1][ix], ijk[2][ix]] for ix, row in enumerate(ts)
+ [ijk[0][idx], ijk[1][idx], ijk[2][idx]] for idx in range(len(ts))
]
vox = ci.Cifti2VoxelIndicesIJK(vox)
@@ -403,7 +404,7 @@ def _create_cifti_image(
voxel_indices_ijk=vox,
)
idx_offset += len(vox)
- bm_ts = np.column_stack((bm_ts, ts.T))
+ bm_ts = np.column_stack((bm_ts, ts.T)).astype(bold_dtype)
# add each brain structure to list
brainmodels.append(bm)
@@ -439,7 +440,7 @@ def _create_cifti_image(
matrix.append(geometry_map)
matrix.metadata = ci.Cifti2MetaData(meta)
hdr = ci.Cifti2Header(matrix)
- img = ci.Cifti2Image(bm_ts, hdr)
+ img = ci.Cifti2Image(dataobj=bm_ts, header=hdr, nifti_header=bold_img.header)
img.nifti_header.set_intent("NIFTI_INTENT_CONNECTIVITY_DENSE_SERIES")
out_file = "{}.dtseries.nii".format(split_filename(bold_file)[1])
