Export NiLearn Surfaces

Summary of what happened:

I would like to export the surface file I created in nilearn using vol_to_surf(). I am currently trying to use nibabel’s write_geometry(), but I am not sure what components of the output from vol_to_surf() correspond to the arguments in write_geometry(). Does anyone have suggestions for how to use write_geometry(), or other functions I might consider using for exporting the surface data?

Command used (and if a helper script was used, a link to the helper script or the command generated):

import numpy as np 
import nibabel as nib
fsaverage = datasets.fetch_surf_fsaverage("fsaverage5")
...
surf_data = surface.vol_to_surf(img, # img is path to a 4D nifti of one person's resting state scan
                                surf_mesh = fsaverage["pial_left"],
                                inner_mesh = fsaverage["white_left"])

Version:

Python 3.8.9
nilearn==0.9.1
nibabel==3.2.2

Environment (Docker, Singularity, custom installation):

Installed the python packages with pip3.

What you are writing is the surface representation of img, right ?
For this I generally use:

from nibabel.gifti import read, write, GiftiDataArray, GiftiImage
gimage = GiftiImage(
                darrays=[GiftiDataArray().from_array(
                    surf_data, intent='t test')]) # or whatever this represents
write(gimage, some_path)
1 Like