[Mne_analysis] stc to 3d numpy array

Sheraz Khan, PhD sheraz at nmr.mgh.harvard.edu
Sun Oct 29 14:20:08 EDT 2017
Search archives:

Hi Tsung-Min,

stc.data is 1d vector of the vertex  on the surface right?

It is but the surface on which it will be plotted lives in 3D euclidean
space.

Can I  map surface vertex back to volume position in 3d numpy array?

Yes you can, you need some sort of projection scheme, please find a sample
example script below, it will generate .nii.gz from stc file which you can
read in python using nibabel

import nibabel as nib
img = nib.load('Your_nii_gz_file.nii.gz')

This assumes you have freesurfer installed on the system


However if you already have 3D source space then whole problem become as
simple as
img = stc.as_volume(src)  # where src is the 3d source space

HTH

Sheraz

import mne
import numpy as np
from scipy.io import loadmat
from pyimpress import utils
import os
labels_mat_path =
'/autofs/cluster/transcend/Javeria/dropbox/Dropbox/labels.mat'
labels_path = '/autofs/cluster/fusion/Sheraz/rs/452/'
subjects_dir = '/cluster/transcend/MRI/WMA/recons/'
labels = loadmat(labels_mat_path)['labels']
labels = [labels_path + str(label[0][0][1:-1]) for label in labels]
bn = loadmat('/cluster/transcend/Javeria/dropbox/Dropbox/beta_bet_neg.mat')
bp = loadmat('/cluster/transcend/Javeria/dropbox/Dropbox/beta_bet_pos.mat')
gn = loadmat('/cluster/transcend/Javeria/dropbox/Dropbox/gamma_bet_neg.mat')
gp = loadmat('/cluster/transcend/Javeria/dropbox/Dropbox/gamma_bet_pos.mat')

bp = np.array(bp['vertl']) + np.array(bp['vertr']) +
np.array(bn['vertl'])*-1 + np.array(bn['vertr'])*-1
stc = utils.get_stc(labels,bp)
stc = stc.morph('fsaverage',smooth=2,grade=7)
stc.save('/cluster/transcend/Javeria/dropbox/Dropbox/b_pos','w')


gp = np.array(gp['vertl']) + np.array(gp['vertr']) +
np.array(gn['vertl'])*-1 + np.array(gn['vertr'])*-1
stc = utils.get_stc(labels,gp)
stc = stc.morph('fsaverage',smooth=2,grade=7)
stc.save('/cluster/transcend/Javeria/dropbox/Dropbox/g_pos','w')


c1 = 'mri_surf2surf --srcsurfval
/cluster/transcend/Javeria/dropbox/Dropbox/b_pos-lh.w ' \
     '--trgsurfval /cluster/transcend/Javeria/dropbox/Dropbox/b_pos-lh.mgz
' \
     '--srcsubject fsaverage --src_type w --trgsubject fsaverage --hemi lh'

c2 = 'mri_surf2surf --srcsurfval
/cluster/transcend/Javeria/dropbox/Dropbox/b_pos-rh.w ' \
     '--trgsurfval /cluster/transcend/Javeria/dropbox/Dropbox/b_pos-rh.mgz
' \
     '--srcsubject fsaverage --src_type w --trgsubject fsaverage --hemi rh'

c3 = 'mri_surf2vol --hemi lh --surf white --o
/cluster/transcend/Javeria/dropbox/Dropbox/b_pos-lh.nii.gz ' \
     '--identity fsaverage ' \
     '--template /cluster/transcend/MRI/WMA/recons/fsaverage/mri/T1.mgz ' \
     '--surfval /cluster/transcend/Javeria/dropbox/Dropbox/b_pos-lh.mgz
--fillribbon  --fill-projfrac -1 1 0.05'
##
c4 = 'mri_surf2vol --hemi rh --surf white --o
/homes/6/sheraz/public_html/bs_pos.nii.gz ' \
     '--identity fsaverage ' \
     '--template /cluster/transcend/MRI/WMA/recons/fsaverage/mri/T1.mgz ' \
     '--surfval /cluster/transcend/Javeria/dropbox/Dropbox/b_pos-rh.mgz
--fillribbon  ' \
     '--fill-projfrac -1 1 0.05 --merge
/cluster/transcend/Javeria/dropbox/Dropbox/b_pos-lh.nii.gz'


c5 = 'mri_surf2surf --srcsurfval
/cluster/transcend/Javeria/dropbox/Dropbox/g_pos-lh.w ' \
     '--trgsurfval /cluster/transcend/Javeria/dropbox/Dropbox/g_pos-lh.mgz
' \
     '--srcsubject fsaverage --src_type w --trgsubject fsaverage --hemi lh'

c6 = 'mri_surf2surf --srcsurfval
/cluster/transcend/Javeria/dropbox/Dropbox/g_pos-rh.w ' \
     '--trgsurfval /cluster/transcend/Javeria/dropbox/Dropbox/g_pos-rh.mgz
' \
     '--srcsubject fsaverage --src_type w --trgsubject fsaverage --hemi rh'

c7 = 'mri_surf2vol --hemi lh --surf white --o
/cluster/transcend/Javeria/dropbox/Dropbox/g_pos-lh.nii.gz ' \
     '--identity fsaverage ' \
     '--template /cluster/transcend/MRI/WMA/recons/fsaverage/mri/T1.mgz ' \
     '--surfval /cluster/transcend/Javeria/dropbox/Dropbox/g_pos-lh.mgz
--fillribbon --fill-projfrac -1 1 0.05 '
##
c8 = 'mri_surf2vol --hemi rh --surf white --o
/homes/6/sheraz/public_html/gs_pos.nii.gz ' \
     '--identity fsaverage ' \
     '--template /cluster/transcend/MRI/WMA/recons/fsaverage/mri/T1.mgz ' \
     '--surfval /cluster/transcend/Javeria/dropbox/Dropbox/g_pos-rh.mgz
--fillribbon ' \
     '--fill-projfrac -1 1 0.05 --merge
/cluster/transcend/Javeria/dropbox/Dropbox/g_pos-lh.nii.gz'


> Hi Rezvan:
>
>        stc.data is 1d vector of the vertex  on the surface right?
> Can I  map surface vertex back to volume position in 3d numpy array?
>
> Tsung-Min
>
>
> On Sun, Oct 29, 2017 at 7:46 AM, Rezvan Farahi <rezvan.farahi at gmail.com>
> wrote:
>
>> Hi Tsung-Min,
>> Is it only the data that you need?
>> if so, it is stored in stc.data.
>>
>> Rezvan
>>
>> On Fri, Oct 27, 2017 at 7:36 PM, Tsung Min Huang
>> <tsungmin.huang at sjsu.edu>
>> wrote:
>>
>>> Hi:
>>>
>>>     I have some fMRI data already morph to fsaverage and save as stc
>>> file.
>>> But now I want to use these stc files on python DeepLearning library.
>>> How can I covert these stc file to an 3d numpy array.
>>>
>>>
>>> Tsung-Min
>>>
>>> _______________________________________________
>>> Mne_analysis mailing list
>>> Mne_analysis at nmr.mgh.harvard.edu
>>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>>>
>>>
>>> The information in this e-mail is intended only for the person to whom
>>> it
>>> is
>>> addressed. If you believe this e-mail was sent to you in error and the
>>> e-mail
>>> contains patient information, please contact the Partners Compliance
>>> HelpLine at
>>> http://www.partners.org/complianceline . If the e-mail was sent to you
>>> in error
>>> but does not contain patient information, please contact the sender and
>>> properly
>>> dispose of the e-mail.
>>>
>>>
>>
>> _______________________________________________
>> Mne_analysis mailing list
>> Mne_analysis at nmr.mgh.harvard.edu
>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>>
>>
>> The information in this e-mail is intended only for the person to whom
>> it
>> is
>> addressed. If you believe this e-mail was sent to you in error and the
>> e-mail
>> contains patient information, please contact the Partners Compliance
>> HelpLine at
>> http://www.partners.org/complianceline . If the e-mail was sent to you
>> in
>> error
>> but does not contain patient information, please contact the sender and
>> properly
>> dispose of the e-mail.
>>
>>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis


-------------------------
Sheraz Khan, M.Eng, Ph.D.
Instructor in Neurology

Athinoula A. Martinos Center for Biomedical Imaging
Massachusetts General Hospital
Harvard Medical School

McGovern Institute for Brain Research
Massachusetts Institute of Technology

Tel:   +1 617-643-5634
Fax:   +1 617-948-5966
Email: sheraz at nmr.mgh.harvard.edu
       sheraz at mit.edu
Web:   http://sheraz.mit.edu


More information about the Mne_analysis mailing list