Skip to content

[MRG] allow to pass a BEM as an instance not just as a string - #5954

Merged
larsoner merged 10 commits into
mne-tools:masterfrom
agramfort:simplify_create_volume_source_space
Feb 20, 2019
Merged

larsoner merged 10 commits into
mne-tools:masterfrom
agramfort:simplify_create_volume_source_space

Conversation

@agramfort

Copy link
Copy Markdown
Member

Here are a few disturbing facts about the setup_volume_source_space.

mne.setup_volume_source_space(subject, subjects_dir=subjects_dir) returns by default a discrete source space that cannot be use for morphing. Even if i have a BEM computed form the T1 MRI if I pass the bem=bem parameter I get a discrete source space :( To have a volume source space which I assume is what most users want I need to type mri='T1.mgz'.

Illustration:

In [2]: src = mne.setup_volume_source_space(subject, subjects_dir=subjects_dir, bem=bem)

In [3]: src
Out[3]: <SourceSpaces: [<discrete, n_used=10376, coordinate_frame=MRI (surface RAS)>]>

In [4]: src = mne.setup_volume_source_space(subject, subjects_dir=subjects_dir, mri='T1.mgz')

In [5]: src.kind
Out[5]: 'volume'

In [6]: src
Out[6]: <SourceSpaces: [<volume, shape=[39 39 39], n_used=20377, coordinate_frame=MRI (surface RAS)>]>

I think we should have better defaults so you don't get trapped so easily as reported by @OlehKSS.

thoughts?

@larsoner

Copy link
Copy Markdown
Member

IIRC you must pass T1 to provide all the metadata necessary for it to be a proper volume source space type

@agramfort

Copy link
Copy Markdown
Member Author

what I would suggest:

  • make sure that everytime you pass a bem then you get as output a volume source space
  • move to mri='auto' by default. If T1.mgz is present you get a volume source space and if not you fall back to a discrete source space. The benefit is that

src = mne.setup_volume_source_space(subject, subjects_dir=subjects_dir)

just works out of the box.

wdyt? @larsoner ?

@larsoner

Copy link
Copy Markdown
Member

Sounds good to me. Though instead of mri='auto' we could just keep mri=None as is and have it mean "auto" as we do in many places.

@codecov

codecov Bot commented Feb 18, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #5954 into master will increase coverage by 0.09%.
The diff coverage is 88.23%.

@@            Coverage Diff            @@
##           master   #5954      +/-   ##
=========================================
+ Coverage   88.71%   88.8%   +0.09%     
=========================================
  Files         401     401              
  Lines       72754   72767      +13     
  Branches    12162   12165       +3     
=========================================
+ Hits        64542   64621      +79     
+ Misses       5272    5217      -55     
+ Partials     2940    2929      -11

@agramfort

Copy link
Copy Markdown
Member Author

@larsoner let me know what you think

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

Comment thread mne/source_space.py Outdated
(``sphere=(0.0, 0.0, 0.0, 90.0)``) if ``bem`` or ``surface`` is not
``None`` then ``sphere`` is ignored.
If you're going to use a BEM conductor model for forward model
it is recommended to pass it here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this should move to Notes

@agramfort

Copy link
Copy Markdown
Member Author

cc @drammock you'll see that it's not documented anywhere how to compute a volume source space. If used in our examples it's using a precomputed volume source space. Can you put this in your todo list? thanks

@jhouck

jhouck commented Feb 18, 2019

Copy link
Copy Markdown
Contributor

cc @drammock you'll see that it's not documented anywhere how to compute a volume source space. If used in our examples it's using a precomputed volume source space. Can you put this in your todo list? thanks

FWIW there's an example of this lurking in mne-scripts/sample-data/run_meg_volume_tutorial.py

@agramfort

agramfort commented Feb 19, 2019 via email

Copy link
Copy Markdown
Member Author

@agramfort agramfort changed the title [WIP] allow to pass a BEM as an instance not just as a string [MRG] allow to pass a BEM as an instance not just as a string Feb 19, 2019

@drammock drammock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are a few things I noticed skimming through the docstring changes.

Comment thread doc/glossary.rst Outdated
model. Both are related to the forward model computation and more
specifically the definion of the conductor model. The
boundary element model consists of surfaces such as the inner skull,
outer skull and outer skill that define compartments of tissues

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outer skill -> outer skin? or outer scalp?

Comment thread tutorials/plot_forward.py Outdated
# the inner skull surface, the outer skull surface and the outer skill
# The :term:`BEM` surfaces are the triangulations of the interfaces between
# different tissues needed for forward computation. These surfaces are for
# example the inner skull surface, the outer skull surface and the outer skill

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outer skill -> outer skin

Comment thread mne/source_space.py Outdated
volume source space can then be morphed onto the MRI volume
using this interpolator. If pos is a dict, this can be None.
using this interpolator. If pos is a dict, this cannot be None.
If subject name is provided then the mri will default to 'T1.mgz'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capitalize: mri -> MRI

Comment thread mne/source_space.py Outdated
Parameters
----------
subject : str | None
Subject to process. If None, the path to the mri volume must be

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capitalize: mri -> MRI

Comment thread mne/source_space.py Outdated
Volume source spaces are related to an MRI image such as T1 and allow to
visualize source estimates overlaid on MRIs and to morph estimates
to a template brain for group analysis. Discrete source spaces
don't allow this. If you provide a subject name the T1 mri will be

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capitalize: mri -> MRI

@agramfort

Copy link
Copy Markdown
Member Author

comments addressed

thx @drammock for the close look.

@OlehKSS please confirm it fixes your problem and documentation is clear for you. thanks

Comment thread mne/source_space.py
volume_label is None and isinstance(pos, (float, int))):
mri = 'T1.mgz'

if volume_label is not None and mri == 'T1.mgz':

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have noticed that this if-statement is similar to the one on 1594 (1572), do you think they can be combined?

@OlehKSS

OlehKSS commented Feb 20, 2019

Copy link
Copy Markdown
Contributor

It works on the sample data perfectly. It raises errors when I provide labels, as far as I get it is the expected behavior.

@larsoner
larsoner force-pushed the simplify_create_volume_source_space branch from 75458bf to 98bf00b Compare February 20, 2019 19:14
@larsoner
larsoner merged commit 5778168 into mne-tools:master Feb 20, 2019
@larsoner

Copy link
Copy Markdown
Member

Thanks @agramfort @OlehKSS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants