Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions niworkflows/interfaces/cifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good reason to upcast to float64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, can revert that

timepoints = bold_img.shape[3]
label_data = np.asanyarray(label_img.dataobj).astype("int16")

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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])
Expand Down