Cifti dscalar to dtseries using nibabel

Hi All,

Top level - I’d like to apply dual regression on rest fMRI based on parcellation where my rs-fMRI data in in CIFTI format.

For a dual-regression SW I’ve chosen FSL, also because it works on Cifti (according to manual).
For parcellation I’ve chosen the Schaefer parcellation, as it is Cifti-available and also partially based on rest-fMRI.

Now, the Cifti parcellation file is a dscalar file (that is - a single volume/surface), with each greyordinate belongs to one of N parcels. FSL (AFAIU) requires a 4D file as a reference
Working with nibabel, reformatting the matrix is easy - reading it with nibabel and do something like: for k in range(N):
newdata[k,:] = (orgdata==k+1).astype(float)

Updating the Nifti header is also easy -
newobj = nb.Cifti2Image(newdata, dscobj.header, dscobj.nifti_header)
newobj.update_headers()

The problem with this way is the the Cifti header is not being updated - newobj.header.matrix.get_data_shape()
yeilds (1, 64984)

What’s a good way of doing this? - either by sticking to the nibabel->FSL line right or by any alternative

Thanks all so much,
Uri

Have you had a look at the CIFTI-2 Axis API?

There’s some additional documentation and examples in this jupytext doc.