Recommendations with converting a surface source estimate object to nifti

If you have a question or issue with MNE-Python, please include the following info:

  • MNE-Python version: 0.21.1
  • operating system: Windows 10

Good afternoon I am trying to visualize with nifti our roc estimates on brains. Not so important to go into details. In the end now I have a source estimate object where i can visualize using the plot method.
This is however a surface source estimate and I need to convert it into nifti to visualize it. I know that the VolSourceEstimate object has a save as nifti format but not the surface source estimate. How can I proceed? Any advice or opinions?

I took the approach of trying to get a morph object with the mne.compute_source_morph() and then modifying somehow the function _interpolate_data(stc, morph, mri_resolution, mri_space, output) to work on surface source estimates. I however am stuck because I end up getting a morph object with a list of 2 arrays under morphed_data_object[‘from vertices’] and not the mentioned arrays in the interpolate_data function:
if mri_resolution:
affine = morph.src_data[‘src_affine_vox’]
else:
affine = morph.src_data[‘src_affine_src’]

if mri_space:
    affine = np.dot(morph.src_data['src_affine_ras'], affine)

I am however a student and relatively new to mne so it may be far fetched my approach to solving the situation.
I know I cant simply just feed the raw stc to the nibabels Nifti1.image function because there should be a transformation prior which I had thought to be the source morph.

Any opinions or advice?

I can think of two ways:

  1. Use a combination of upsampling to the high resolution mesh using morph = compute_source_morph(src, subject, smooth='nearest', spacing=None), then using nibabel.freesurfer.io.write_morph_data, and then FreeSurfer’s mri_surf2vol.

  2. Read FreeSurfer’s ribbon.mgz for your subject, and for each voxel, take the value of the nearest point in your source space. This will involve a bit of gymnastics involving vox_mri_t for the source space, which is really the same thing as nibabel’s img.header.get_vox2ras_tkr().

Feel free to give either or both of these a shot and if this isn’t enough information to go on, I can try to write a little example for MNE showing one or both of these.

In principle we could consider adding a as_volume / save_as_volume for surface source spaces that does the second method.