Source space interpolation

Hi all,

    Is there a way to interpolate sources using built in MNE functions?

    The context is I did a source space TFR decomposition by label for all the labels in aparc subdivided into four sections, and I am putting them back together but approximately 5% of source vertices are not within any of the labels using the stc.in_label function. I visualized the brain and it appears the sources not covered are in a roughly uniform distribution, suggesting that interpolating them may not be a bad idea. The relevant code is reproduced below as well.

Any help would be appreciated.

if tfr:
    labels = read_labels_from_annot(self.subject,parc='aparc',hemi='both',
                                    surf_name='white',
                                    subjects_dir=self.subjects_dir)
    if splits is not None: #splits = 4
        labels = [split_label(label,parts=splits,subject=self.subject,
                              subjects_dir=self.subjects_dir,freesurfer=True)
                  for label in labels]
        labels = [l2 for l in labels for l2 in l]
    tfrs = np.memmap('sb_tfr_%s_%s_%s_workfile' %(event,ar,keyword_out),
                     dtype='float64', mode='w+',
                     shape=(batch,steps,fwd['nsource'],len(epochs.times)))
else:
    tfrs = None
mins = range(0,Nboot-batch +1,batch)
maxs = range(batch,Nboot+1,batch)
for i_min,i_max in zip(mins,maxs):
    fname2 = self._fname('sources','bootstrap','.npz','%i-%i' %(i_min,i_max),
                         ar and not keyword_out,keyword_out,method,
                         pick_ori,tfr,Nboot,Nave,seed,fmin,fmax,nmin,
                         nmax,steps)
    if os.path.isfile(fname2):
        continue
    for i,k in enumerate(range(i_min,i_max)):
        indices = bootstrap_indices[i]
        bl_indices = [bl_events.index(j) for j in events[indices]]
        inv = self._generate_inverse(epochs,fwd,bl_epochs[bl_indices],lambda2,method,
                                     pick_ori)
        evoked = epochs[indices].average()
        stc = apply_inverse(evoked,inv,lambda2=lambda2,method=method,
                                   pick_ori=pick_ori)
        stcs[k] = stc.data[:]
        if tfr:
            tfr_stcs = []
            for _ in range(steps):
                stc_new = stc.copy()
                stc_new.data.fill(0)
                tfr_stcs.append(stc_new)
            for label in tqdm(labels):
                power,_ = source_induced_power(epochs[indices],inv,freqs,
                                               label=label,lambda2=lambda2,
                                               nave=Nave,n_cycles=n_cycles,
                                               n_jobs=n_jobs,prepared=True)
                ver = stc.in_label(label).vertices
                assigned = [[],[]]
                if 'lh' in label.name:
                    inds = np.array([np.where(v==stc.vertices[0])[0][0]
                                     for v in ver[0]])
                    assigned[0] += list(inds)
                elif 'rh' in label.name:
                    inds = np.array([np.where(v==stc.vertices[1])[0][0]
                                     for v in ver[1]])
                    assigned[1] += list(inds)
                    inds += fwd['nsource']/2
                else:
                    raise ValueError('Unidentified label')
                for j in range(steps):
                    tfr_stcs[j].data[inds] = power[:,j]
            unassigned = [np.setdiff1d(stc.vertices[0],ind[0]),
                          np.setdiff1d(stc.vertices[1],ind[1])]
            for j in range(steps):
                tfrs[k,j] = tfr_stcs[j].data

Thanks,

Alex

Translational NeuroEngineering Laboratory
Division of Neurotherapeutics, Department of Psychiatry
Massachusetts General Hospital, Martinos Center
149 13th St Charlestown #2301, Boston, MA 02129
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180918/8cb97c89/attachment.html

what are you using to visualize ?

pysurfer do an automatic interpolation, which I am using

I was am using MMVT to visualize ultimately.

Is there a way to save out the automatic interpolation to the stc?

Thanks,

Alex

Translational NeuroEngineering Laboratory
Division of Neurotherapeutics, Department of Psychiatry
Massachusetts General Hospital, Martinos Center
149 13th St Charlestown #2301, Boston, MA 02129

What you need is a smoothing matrix which can be used to interpolate data
defined for a subset of vertices onto mesh with an adjancency matrix

from surfer.utils import smoothing_matrix

Sheraz