Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError with fmriprep dataset #428

Open
ChristianNSchmitz opened this issue Feb 4, 2022 · 4 comments
Open

ValueError with fmriprep dataset #428

ChristianNSchmitz opened this issue Feb 4, 2022 · 4 comments

Comments

@ChristianNSchmitz
Copy link

ChristianNSchmitz commented Feb 4, 2022

Dear pycortex-team,
we are trying to use the pycortex software on an fmriprep dataset.
However, the adapted example of the tutorial results in the following error.
Thus, we would like to ask you for your support
Thank you very much!

import cortex
from cortex import fmriprep
from os import path as op

# Location of the downloaded openfmri dataset
source_directory = '/mnt/d/Data/OurStudy/derivatives/preprocessing-fmriprep'
# fmriprep subject name (without "sub-")
subject_id = '011'

# import subject into pycortex database
fmriprep.import_subj(subject_id, source_directory)

# We can use visualize the imported subject's T1-weighted image
anat_nifti = 'fmriprep/sub-011/anat/sub-011_run-01_desc-preproc_T1w.nii.gz'
t1_image_path = op.join(source_directory, anat_nifti)

# Now we can make a volume using the built-in identity transform
t1w_volume = cortex.Volume(t1_image_path, subject_id, 'identity')

# And show the result.
ds = cortex.Dataset(t1w=t1w_volume)
cortex.webgl.show(ds)
Traceback (most recent call last):

  File "/tmp/ipykernel_5473/3900280654.py", line 22, in <module>
    cortex.webgl.show(ds)

  File "/root/anaconda3/lib/python3.8/site-packages/cortex/utils.py", line 33, in __call__
    return self._load()(*args, **kwargs)

  File "/root/anaconda3/lib/python3.8/site-packages/cortex/webgl/view.py", line 329, in show
    ctms = dict((subj, utils.get_ctmpack(subj, types, **ctmargs))

  File "/root/anaconda3/lib/python3.8/site-packages/cortex/webgl/view.py", line 329, in <genexpr>
    ctms = dict((subj, utils.get_ctmpack(subj, types, **ctmargs))

  File "/root/anaconda3/lib/python3.8/site-packages/cortex/utils.py", line 98, in get_ctmpack
    ptmap = brainctm.make_pack(ctmfile,

  File "/root/anaconda3/lib/python3.8/site-packages/cortex/brainctm.py", line 285, in make_pack
    ctm.addCurvature()

  File "/root/anaconda3/lib/python3.8/site-packages/cortex/brainctm.py", line 108, in addCurvature
    npz = db.get_surfinfo(self.subject, type='curvature', **kwargs)

  File "/root/anaconda3/lib/python3.8/site-packages/cortex/database.py", line 276, in get_surfinfo
    return Vertex(verts, subject)

  File "/root/anaconda3/lib/python3.8/site-packages/cortex/dataset/views.py", line 324, in __init__
    super(Vertex, self).__init__(data, subject, cmap=cmap, vmin=vmin, vmax=vmax,

  File "/root/anaconda3/lib/python3.8/site-packages/cortex/dataset/braindata.py", line 367, in __init__
    self._set_data(data)

  File "/root/anaconda3/lib/python3.8/site-packages/cortex/dataset/braindata.py", line 451, in _set_data
    raise ValueError('Invalid number of vertices for subject (given %d, should be %d for left hem, %d for right hem, or %d for both)' % (self.nverts, self.llen, self.rlen, self.llen+self.rlen))

ValueError: Invalid number of vertices for subject (given 1691148, should be 733462 for left hem, 750891 for right hem, or 1484353 for both)
@mvdoc
Copy link
Contributor

mvdoc commented Feb 5, 2022

I cannot replicate this issue with a newly imported subject from fmriprep. Have you perhaps tried to import this subject multiple times?

Can you try to replace the last call to cortex.webgl.show(ds) with cortex.webgl.show(ds, recache=True). This will regenerate the pycortex surfaces cache and maybe fix the issue.

If this still doesn't work, I would start from a clean slate and remove the subject from the pycortex store, then re-import it. You can find where your pycortex store is with the following code (see https://gallantlab.github.io/pycortex/auto_examples/quickstart/show_config.html#sphx-glr-auto-examples-quickstart-show-config-py):

from cortex.options import config
print(config.get('basic', 'filestore'))

this will print the path to the filestore, then from the command line you can cd into that folder and remove the directory associated with your subject.

Then try reimporting the subject again.

@ChristianNSchmitz
Copy link
Author

Dear Matteo,
thanks a lot for the quick response.
Unfortunately, both approaches didn't solve the issue and I've got the same error message.
As we are using own data for the fmriprep-preprocessing, could the individual dataset/imaging settings be a reason for the issue?

root@wslComp:/mnt/d/Data/OurStudy/derivatives/preprocessing-fmriprep/fmriprep/sub-011/anat# fslinfo sub-011_run-01_desc-preproc_T1w.nii.gz
data_type       FLOAT32
dim1            192
dim2            544
dim3            512
dim4            1
datatype        16
pixdim1         0.900000
pixdim2         0.449219
pixdim3         0.449219
pixdim4         2.000000
cal_max         0.000000
cal_min         0.000000
file_type       NIFTI-1+

@ChristianNSchmitz
Copy link
Author

Add on: There has been an issue with FMRIPREP if the FOV was >256mm. It has been resolved beginning of 2020. Might that be the sourve of the error?

https://code.stanford.edu/rblair2/fmriprep-test/-/blob/b529274bc37c2d29ab5a859f69379fa6ab4a4eeb/CHANGES.rst

1.5.7 (January 23, 2020)
Bug-fix release in the 1.5.x series.
This release fixes a bug specifically for T1w images with dimensions ≤256 voxels
but a field-of-view >256mm.


FIX: Calculate FoV with shape and zooms (poldracklab/smriprep#161)

@mvdoc
Copy link
Contributor

mvdoc commented Feb 7, 2022

Hmmm interesting. The error you are having is caused by a shape mismatch between the curvature data (generated by freesurfer and stored as {hemi}.curvature under freesurfer/<subject>/surf/) and the surface data (stored as gifti files *.gii under fmriprep/<subject>/anat/). The surface seems to have 1484353 vertices, while for some reason the curvature data seems to have 1691148 vertices.

Now, I can think of two reasons for this

  1. Since recaching or reimporting the subject doesn't help, then there is something different between the surface stored in the fmriprep directory and the surface data stored in the freesurfer directory. Something odd might have happened during recon-all (maybe it was killed and restarted?), and this caused the files to have a different number of vertices.
  2. This is actually how recon-all is supposed to work with sub-mm T1s. I don't think we have ever used freesurfer + pycortex with higher resolution anatomicals, so we can't really help with that. I would suggest (a) checking the dimensions of the surfaces stored under the freesurfer directory vs. the fmriprep directory; (b) reading this freesurfer page: https://surfer.nmr.mgh.harvard.edu/fswiki/SubmillimeterRecon; (c) perhaps try running fmriprep again with the --no-submm-recon flag (no idea if this would help though...again, I never tried fmriprep with highres anatomicals).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants