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

Visualizing fMRI data following 2015 paper. #350

Open
iPsych opened this issue Dec 1, 2019 · 8 comments
Open

Visualizing fMRI data following 2015 paper. #350

iPsych opened this issue Dec 1, 2019 · 8 comments

Comments

@iPsych
Copy link

iPsych commented Dec 1, 2019

Following the 2015 Paper, Step 1 and Step 2 successfully segment and made a Sub01 folder and files in db.

cortex.segment.init_subject( "Sub01" , " T1_anatomical.nii.gz" )
cortex.align.automatic( "Sub01" ,  "transform_name" , "functional.nii.gz" )

However, the third step shows error, since the variable data was not set.

cortex.webshow(( data, "Sub01" ,"transform_name " ))

I thought step2 will pass the part of 'functional.nii.gz' to step 3 but it wasn't.
What should be done to visualize (part of) aligned functional.nii.gz. in 3rd step?

@mvdoc
Copy link
Contributor

mvdoc commented Dec 2, 2019

Hi @iPsych, I believe the code you are referring to in the paper was meant to be a proof of concept. I would suggest you look at the example gallery, which is updated to the latest version of pycortex https://gallantlab.github.io/auto_examples/index.html. In particular you might want to test your installation of pycortex running the demo https://gallantlab.github.io/install.html#demo

@iPsych
Copy link
Author

iPsych commented Dec 2, 2019

Hi, @mvdoc, Thank you for the reply.
I read the examples too, and the demo runs properly with random number generation.
However, I cannot find any example visualized actual functional nifti image on the surface.

@mvdoc
Copy link
Contributor

mvdoc commented Dec 2, 2019

You will need to provide a volume dataset as a numpy array (instead of the randomly generated volume). You can load volumes in python using nibabel, with something like this (assuming you're loading a 4D volume)

import nibabel as nib
img = nib.load('/path/to/your/functional.nii.gz')
data = img.get_data()
data = data.T  # pycortex assumes the first dimension to be TRs

subject_id = 'your_subject_id'
transform_name = 'your_transform_name'

data_to_show = data[0]  # assuming you want to show the first TR
vol = cortex.Volume(data_to_show, subject_id, transform_name)
cortex.webgl.show(vol)

where you need to change subject_id and transform_name to what you have previously created. In general before being able to visualize data on a surface you will need 1. to run freesurfer recon-all to reconstruct the surfaces and import the subject in pycortex and 2. to align the surface to your reference image to generate a transform.

@iPsych
Copy link
Author

iPsych commented Dec 2, 2019

@mvdoc
It raises "Value Error : Cannot Find valid mask" in braindata.py
Should the mask also provided?
3D mask loaded using nib.load and get_data doesn't works.

@mvdoc
Copy link
Contributor

mvdoc commented Dec 3, 2019

Can you post the code you're using and that gives you this error?

In general, that error occurs whenever there's a shape mismatch between the data you're trying to visualize and the reference image that was stored in the database. If the shape is different, pycortex will try to use known masks (for example, a cortical mask selecting only voxels near the surface boundaries). If none of them works, it will raise this error.

@iPsych
Copy link
Author

iPsych commented Dec 3, 2019

There are brainmask and brainmask_mask file in anatomicals folder.

The error is below.


ValueError Traceback (most recent call last)
in
8
9 data_to_show = data[0] # assuming you want to show the first TR
---> 10 vol = cortex.Volume(data_to_show, subject_id, transform_name)
11 cortex.webgl.show(vol)

/usr/local/lib/python3.6/dist-packages/cortex/dataset/views.py in init(self, data, subject, xfmname, mask, cmap, vmin, vmax, description, **kwargs)
270 super(Volume, self).init(data, subject, xfmname, mask=mask,
271 cmap=cmap, vmin=vmin, vmax=vmax,
--> 272 description=description, **kwargs)
273 # set vmin and vmax
274 self.vmin = self.vmin if self.vmin is not None else \

/usr/local/lib/python3.6/dist-packages/cortex/dataset/braindata.py in init(self, data, subject, xfmname, mask, **kwargs)
141 self.xfmname = xfmname
142
--> 143 self._check_size(mask)
144 self.masked = _masker(self)
145

/usr/local/lib/python3.6/dist-packages/cortex/dataset/braindata.py in _check_size(self, mask)
221 if mask is None:
222 nvox = self.data.shape[-1]
--> 223 self._mask, self.mask = _find_mask(nvox, self.subject, self.xfmname)
224 elif isinstance(mask, np.ndarray):
225 self.mask = mask > 0

/usr/local/lib/python3.6/dist-packages/cortex/dataset/braindata.py in _find_mask(nvox, subject, xfmname)
554 return name.group(1), mask
555
--> 556 raise ValueError('Cannot find a valid mask')
557
558

ValueError: Cannot find a valid mask

@alexhuth
Copy link
Contributor

alexhuth commented Dec 3, 2019

What is data_to_show.shape? From the error I'm guessing it's a 1-D vector with values for each voxel in your mask. To supply a custom mask you need to also include that in the Volume init, e.g. vol = cortex.Volume(data_to_show, subject_id, transform_name, mask=my_mask).

Inserting your own custom mask into the pycortex filestore so that it is automatically detected is currently a bit weird (I've never done this and don't know exactly what it would take off-hand)--masks belong to transforms, so you would need to place it in the directory for your transform with the right filename and right format. Supplying a mask using the mask kwarg is the preferred method.

@luoying050601
Copy link

what you have previously created

can you tell me how to create the subject and transform into the build file

FileNotFoundError: [Errno 2] No such file or directory: 'build/bdist.macosx-10.9-x86_64/wheel/pycortex-1.1.1.data/data/share/pycortex/db/'sub_id'/transforms/'XXX'/matrices.xfm'

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

4 participants