neuromaps icon indicating copy to clipboard operation
neuromaps copied to clipboard

Exporting surface files

Open butellyn opened this issue 1 year ago • 3 comments

Description of issue

I followed the transformations wiki to get my data from freesurfer's fsaverage5 space into fsLR32k space, but I am having some trouble exporting the resulting gifti. I run the following code to transform the data and export it:

from neuromaps import transforms
import nibabel as nib

subid = 'MWMH212'
sesid = '2'
sub = 'sub-'+subid
ses = 'ses-'+sesid

surfdir = '/Users/flutist4129/Documents/Northwestern/studies/mwmh/data/processed/neuroimaging/surf/'
sssurfdir = surfdir+'sub-'+subid+'/ses-'+sesid+'/'
surf_lh = nib.load(sssurfdir+sub+'_'+ses+'_task-rest_space-fsaverage5_desc-preproc_bold_lh.func.gii')
surf_rh = nib.load(sssurfdir+sub+'_'+ses+'_task-rest_space-fsaverage5_desc-preproc_bold_rh.func.gii')

surf_fslr = transforms.fsaverage_to_fslr([surf_lh, surf_rh], '32k')
surf_fslr_lh = surf_fslr[0]
surf_fslr_rh = surf_fslr[1]

surf_fslr_lh.to_filename(sssurfdir+'/'+sub+'_'+ses+'_task-rest_space-fslr32k_desc-preproc_bold_lh.func.gii')
surf_fslr_rh.to_filename(sssurfdir+'/'+sub+'_'+ses+'_task-rest_space-fslr32k_desc-preproc_bold_rh.func.gii')

But when I open the resulting gifti in workbench using this command:

wb_view ${sssurfdir}/sub-${subid}.L.midthickness.32k_fs_LR.surf.gii \
  ${sssurfdir}/sub-${subid}_ses-${sesid}_space-fslr32k_task-rest_lh.func.gii \
  ${sssurfdir}/sub-${subid}.R.midthickness.32k_fs_LR.surf.gii \
  ${sssurfdir}/sub-${subid}_ses-${sesid}_space-fslr32k_task-rest_rh.func.gii \
  ${ssprepdir}/anat/sub-${subid}_ses-${sesid}_desc-preproc_T1w.nii.gz

I get the following error from wb_view: Screenshot 2024-01-04 at 3 03 40 PM

Considering I have 1110 TRs, it looks like the vertices and the TRs somehow got confused in the process of exporting the giftis. How would you recommend exporting the gifti files?

Code of Conduct

  • [X] I agree to follow the neuromaps Code of Conduct

butellyn avatar Jan 04 '24 21:01 butellyn

So I figured out how to check the shape in python, and is it (1110, ) there as well. Can neuromaps not handle timeseries data?

butellyn avatar Jan 09 '24 18:01 butellyn

Hey @butellyn,

You are unfortunately correct: neuromaps currently does not handle timeseries data :disappointed_relieved:.

The error occurs because the load_data function does not work as expected when loading timeseries data once the transformation is completed (here). We'll try to see whether we can fix this bug in the future.

In the meantime, it is perhaps worth noting that you could also do these transformation using the connectome workbench directly (i.e. by calling the -metric-resample function of the workbench). The aligned spherical mesh required to do the transformation can be downloaded using datasets.fetch_atlas.

VinceBaz avatar Jan 09 '24 21:01 VinceBaz

Hi @VinceBaz! Thank you for letting me know so quickly! I spent awhile trying to get a solution to work in workbench, but ran into an issue I couldn't resolve. I posted about it here on neurostars. Any chance you'd have some insight into this issue? Also trying to adapt code directly from fmriprep.

butellyn avatar Jan 10 '24 15:01 butellyn

Should be fixed by #153

liuzhenqi77 avatar Sep 19 '24 19:09 liuzhenqi77