question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Order of vertices in morphed source spaces

See original GitHub issue

Hi,

When morphing the source space of fsaverage to ‘sample’, the order of the morphed vertices is not preserved. The first 10 vertices of the morphed source space do not correspond to those of fsaverage:

fsaverage:

fsaverage-sources

Morphed fsaverage -> sample:

sample-sources

import mne
import os

from mne.datasets.sample import data_path
from mayavi import mlab  # noqa
from surfer import Brain  # noqa

data_path = data_path()
subjects_dir = data_path + "/subjects/"
os.environ['SUBJECTS_DIR'] = subjects_dir

fname_fs = subjects_dir + "fsaverage/bem/fsaverage-ico-5-src.fif"
src_fs = mne.read_source_spaces(fname_fs)
src_sample = mne.morph_source_spaces(src_fs, subject_to="sample",
                                     subjects_dir=subjects_dir)
sources = np.arange(10)

for subject, src in zip(["fsaverage", "sample"], [src_fs, src_sample]):
    brain = Brain(subject, 'lh', 'inflated', subjects_dir=subjects_dir)
    surf = brain.geo['lh']
    vertices = src[0]["vertno"][sources]
    mlab.points3d(surf.x[vertices], surf.y[vertices],
                  surf.z[vertices], color=(1, 0, 0), scale_factor=6.)
    mlab.savefig("%s-sources.png" % subject)

This can be fixed by removing np.sort in https://github.com/mne-tools/mne-python/blob/master/mne/source_space.py#L2639

   ` to['vertno'] = np.sort(best[fro['vertno']])`

Then, the first 10 vertices of the morphed source space do match those of fsaverage:

Morphed fsaverage -> sample (after removing np.sort):

sample-sources-fixed

When sorting the vertices one loses their correspondance which is the purpose of morphing. The resulting forward operators based on these morphed source spaces would have completely mismatched locations.

Written with @agramfort

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
agramfortcommented, Jul 18, 2018

I think it’s more complicated than this. I talked to @larsoner

MNE-C also outputs sorted vertices and I don’t know why. We need @mshamalainen wisdom on this. For me it defeats the purpose of source space morphing as with this sorting you still have to do stc.morph for group studies.

If we remove the np.sort then we might break stuff like backward compat with MNE-C and also some of our functions require stc.vertno to be sorted. Or at least if it’s not you get a ValueError…

0reactions
agramfortcommented, Dec 20, 2018

no but I am not sure we can fix it in a reasonable way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Morph volumetric source estimate--discrepancy in number of ...
Every subject starts with an oct6 source space, 8196 vertices total (4098 per hemi); Some get excluded during forward computation, say for one ......
Read more >
Morphing source estimates: Moving data from one brain to ...
In this tutorial we will morph different kinds of source estimation results between individual subject spaces using mne.SourceMorph object.
Read more >
[Mne_analysis] "equalized" source spaces
The source spaces always store vertices in ascending order (this is due at the ... Thus the selection of vertices is preserved by...
Read more >
Shape discrimination along morph-spaces - ScienceDirect.com
The shapes in a morph space are constructed using weighted combinations of vertices drawn from the two base shapes, with each vertex in...
Read more >
Object-space Morphing
An unacceptable morph sequence ... Corresponding features of the source and ... Object-space Morphing source. (C) Gershon Elber, Technion. The Vertex path.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found