gallantlab / pycortex

Pycortex is a python-based toolkit for surface visualization of fMRI data
https://gallantlab.github.io/pycortex
BSD 2-Clause "Simplified" License
586 stars 137 forks source link

Plotting Volume data on MNI standard flatmap #322

Closed amyh101 closed 5 years ago

amyh101 commented 5 years ago

I have some data and ROIs defined in MNI standard volume space and I want to visualize these results on a standard brain flatmap. I have looked into the methods suggested on a previous post (https://github.com/gallantlab/pycortex/issues/170) but the 'MNI' subject does not appear to be part of pycortex standard package.

Is this a correct assumption? To plot on a standard brain flatmap should I go through the process outlined in the documentation for pycortex using the MNI brain as a subject named 'MNI'?

marklescroart commented 5 years ago

Hello, We have plans to share a pycortex subject version of the MNI / fsaverage brain in the (possibly near) future - in the meantime, the method you suggest will work. You don't technically need to do the segmentation in freesurfer - the fsaverage brain is based on the MNI brain. You should be able to import the fsaverage subject from freesurfer into pycortex using cortex.segment.import_freesurfer_subject('fsaverage') (you will have to flatten the brain yourself)

drorcohengithub commented 5 years ago

Visualizing on top of the MNI brain is something I am also interested in. It'd be great if you guys include this in the future 😄

amyh101 commented 5 years ago

Great! Thanks @marklescroart for the help with this! I also have a followup question, I have imported my 'MNI' subject but when I attempt to import the flattened surfaces (used tksurfer in freesurfer) I receive an error:

NoOptionError: No option 'cache' in section: 'basic'

Any help diagnosing the source of this error would be greatly appreciated!

marklescroart commented 5 years ago

Hello again, First, if you are using tksurfer, I strongly recommend trying freeview (the newer Freesurfer viewer); it’s MUCH better in every way. Second - that’s a small bug, we will fix eventually, you can get rid of it by specifying a cache directory in your config file (you can find the file path for that file by calling cortex.options.usercfg). In that file, just add a line under the [basic] heading that says something like: cache = /where/you/want/a/local/cache/ This option exists to allow multiple people to use the same pycortex directory without having permission clashes on the cached files that pycortex creates.

Good luck!

On Apr 1, 2019, at 4:04 PM, amyh101 notifications@github.com wrote:

Great! Thanks @marklescroart https://github.com/marklescroart for the help with this! I also have a followup question, I have imported my 'MNI' subject but when I attempt to import the flattened surfaces (used tksurfer in freesurfer) I receive an error:

NoOptionError: No option 'cache' in section: 'basic'

Any help diagnosing the source of this error would be greatly appreciated!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gallantlab/pycortex/issues/322#issuecomment-478778367, or mute the thread https://github.com/notifications/unsubscribe-auth/AFPlw76aXKX5Jv9h23rgMBagR-wFw_i-ks5vcpCCgaJpZM4cOpQ9.

amyh101 commented 5 years ago

That make sense and seems to have resolved the issue. Thanks!

I have run into another issue though when I try to view data on the 'fsaverage' surface. I have attempted three methods to view volume data within the newly created surfaces (e.g. atlas, ROI masks, functional data, etc.).

  1. Use align.automatic(...) to generate transforms for the data of interest - This function seems to fail regardless of the reference image. I have attached the first error generated below... libc++abi.dylib: terminating with uncaught exception of type NEWMAT::SingularException

  2. Manually generate transforms using flirt command in fsl - this generates appropriate affine transforms and the data can be loaded with pycortex (correct dimensions) but there appears to be an error when plotting these data as quickshow options show only blank screens

  3. Transform input data into fs space (using flirt command in fsl) and using 'identity' transform in pycortex. Although the resulting volumes are the correct shape, it results in a dimension mismatch error when plotting.

I assume the best way to approach this problem is using the built in align functions. It seems like that would be the best solution, but to just plot in standard space, I wondered if there is an easier solution. Any help resolving this would be greatly appreciated!!

Side note...is there functionality to generate the cuts necessary to create a flatmap within freeview? My understanding was that tksurfer was required to cut the mesh before flattening. I am currently not using the built in cut_surface function in pycortex because of an error with blender.

amyh101 commented 5 years ago

I think I worked out the issues with alignment/viewing volume data. The 'identity' transform can be used as long as you ensure the volume data is loaded correctly. When loading the volume data, it seems the issue originates from the underlying datatype of the nii file. It worked for me after I changed all of the data types to double64.

Thanks!

marklescroart commented 5 years ago

Glad you figured it out, thanks for the feedback!

On Apr 4, 2019, at 10:27 AM, amyh101 notifications@github.com wrote:

I think I worked out the issues with alignment/viewing volume data. The 'identity' transform can be used as long as you ensure the volume data is loaded correctly. When loading the volume data, it seems the issue originates from the underlying datatype of the nii file. It worked for me after I changed all of the data types to double64.

Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gallantlab/pycortex/issues/322#issuecomment-479989896, or mute the thread https://github.com/notifications/unsubscribe-auth/AFPlw9Gs7UikMkpLf4ysXAIcXYCshkdWks5vdjXmgaJpZM4cOpQ9.

christian-oreilly commented 4 years ago

I want to upvote the sharing of the pycortex MNI / fsaverage brain. That would be very useful for most users I think.

In the meantime, I tried to import it using the command cortex.segment.import_freesurfer_subject('fsaverage') suggested by @marklescroart but get an exception because the fsaverage do not contain the "mri/wm.mgz" file. Is this normal? Is it due to changes in PyCortex or to a broken fsaverage on my side?

N-HEDGER commented 3 years ago

Hi @christian-oreilly I am encountering the same problem with importing fsaverage/fsaverage5. Did you find a way to resolve this?

christian-oreilly commented 3 years ago

I don't remember all the details from one year ago, but looking at /usr/local/freesurfer/subjects/fsaverage5, it seems like it contains all the files necessary for you to create the flatmap if you need it. For this, you need to make the necessary cuts on the inflated surfaces as described in here : https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferOccipitalFlattenedPatch

Then, the code to import this surface would be something like this:

import cortex
subject = "fsaverage5"
cortex.freesurfer.make_fiducial(subject)
cortex.freesurfer.flatten(subject, hemi="lh", patch="cortex")
cortex.freesurfer.flatten(subject, hemi="rh", patch="cortex")
cortex.freesurfer.import_subj(subject)
cortex.freesurfer.import_flat(subject, patch="cortex", hemis=['lh', 'rh'])