Skip to content

Commit 915cb01

Browse files
committed
ENH: apply changes from @effigies review
1 parent c5a257f commit 915cb01

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

niworkflows/interfaces/cifti.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ 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()
334333
label_img = nb.load(label_file)
335334
if label_img.shape != bold_img.shape[:3]:
336335
warnings.warn("Resampling bold volume to match label dimensions")
@@ -340,23 +339,23 @@ def _create_cifti_image(
340339
bold_img = _reorient_image(bold_img, orientation="LAS")
341340
label_img = _reorient_image(label_img, orientation="LAS")
342341

343-
bold_data = bold_img.get_fdata()
342+
bold_data = bold_img.get_fdata(dtype="float32")
344343
timepoints = bold_img.shape[3]
345344
label_data = np.asanyarray(label_img.dataobj).astype("int16")
346345

347346
# Create brain models
348347
idx_offset = 0
349348
brainmodels = []
350-
bm_ts = np.empty((timepoints, 0))
349+
bm_ts = np.empty((timepoints, 0), dtype="float32")
351350

352351
for structure, labels in CIFTI_STRUCT_WITH_LABELS.items():
353352
if labels is None: # surface model
354353
model_type = "CIFTI_MODEL_TYPE_SURFACE"
355354
# use the corresponding annotation
356355
hemi = structure.split("_")[-1]
357356
# 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)
360359
if annotation_files[0].endswith(".annot"):
361360
annot = nb.freesurfer.read_annot(annotation_files[hemi == "RIGHT"])
362361
# remove medial wall
@@ -365,7 +364,7 @@ def _create_cifti_image(
365364
annot = nb.load(annotation_files[hemi == "RIGHT"])
366365
medial = np.nonzero(annot.darrays[0].data)[0]
367366
# 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])
369368

370369
vert_idx = ci.Cifti2VertexIndices(medial)
371370
bm = ci.Cifti2BrainModel(
@@ -404,7 +403,7 @@ def _create_cifti_image(
404403
voxel_indices_ijk=vox,
405404
)
406405
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))
408407
# add each brain structure to list
409408
brainmodels.append(bm)
410409

@@ -440,7 +439,8 @@ def _create_cifti_image(
440439
matrix.append(geometry_map)
441440
matrix.metadata = ci.Cifti2MetaData(meta)
442441
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())
444444
img.nifti_header.set_intent("NIFTI_INTENT_CONNECTIVITY_DENSE_SERIES")
445445

446446
out_file = "{}.dtseries.nii".format(split_filename(bold_file)[1])

0 commit comments

Comments
 (0)