Skip to content
Merged
Changes from all commits
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
13 changes: 7 additions & 6 deletions niworkflows/interfaces/cifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,16 @@ def _create_cifti_image(
# Create brain models
idx_offset = 0
brainmodels = []
bm_ts = np.empty((timepoints, 0))
bm_ts = np.empty((timepoints, 0), dtype="float32")

for structure, labels in CIFTI_STRUCT_WITH_LABELS.items():
if labels is None: # surface model
model_type = "CIFTI_MODEL_TYPE_SURFACE"
# use the corresponding annotation
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_ts = nb.load(bold_surfs[hemi == "RIGHT"])
surf_verts = len(surf_ts.darrays[0].data)
if annotation_files[0].endswith(".annot"):
annot = nb.freesurfer.read_annot(annotation_files[hemi == "RIGHT"])
# remove medial wall
Expand All @@ -364,7 +364,7 @@ def _create_cifti_image(
annot = nb.load(annotation_files[hemi == "RIGHT"])
medial = np.nonzero(annot.darrays[0].data)[0]
# extract values across volumes
ts = np.array([tsarr.data[medial] for tsarr in surf.darrays])
ts = np.array([tsarr.data[medial] for tsarr in surf_ts.darrays])
Copy link
Member

Choose a reason for hiding this comment

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

Oh, here would be a good place to use agg_data().

Suggested change
ts = np.array([tsarr.data[medial] for tsarr in surf_ts.darrays])
ts = surf_ts.agg_data()[medial, :]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doesn't agg_data() return a tuple?

Copy link
Member

Choose a reason for hiding this comment

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

If the image has multiple types of data array, or you request multiple intents, then no.

If you want to be safe (e.g., if we start putting surfaces inside functional files...):

Suggested change
ts = np.array([tsarr.data[medial] for tsarr in surf_ts.darrays])
ts = surf_ts.agg_data("time series")[medial, :]

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

running fmriprep with this change leads to:

   ts = surf_ts.agg_data("time series")[medial, :]
TypeError: tuple indices must be integers or slices, not tuple

I think keeping it as it was is simplest ATM

Copy link
Member

Choose a reason for hiding this comment

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

Sure. That seems really weird, though. If you can pdb it at some point, I would be interested in the details.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, if there are no darrays, you do get an empty tuple.


vert_idx = ci.Cifti2VertexIndices(medial)
bm = ci.Cifti2BrainModel(
Expand All @@ -391,7 +391,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 Down Expand Up @@ -439,7 +439,8 @@ 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)
img.set_data_dtype(bold_img.get_data_dtype())
img.nifti_header.set_intent("NIFTI_INTENT_CONNECTIVITY_DENSE_SERIES")

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