mne-python: [BUG] `mne.viz.Brain` volume rendering doesn't show up

If you don’t set alpha=0, you get an opaque inflated brain along with your volume source estimate. I think the default arguments could handle this better.

image

To replicate:

import mne
from mne.datasets import sample
from mne import read_evokeds
from mne.minimum_norm import apply_inverse, read_inverse_operator

data_path = sample.data_path()
meg_path = data_path / 'MEG' / 'sample'
fname_inv = meg_path / 'sample_audvis-meg-vol-7-meg-inv.fif'
fname_evoked = meg_path / 'sample_audvis-ave.fif'

snr = 3.0
lambda2 = 1.0 / snr ** 2
method = "dSPM"  # use dSPM method (could also be MNE or sLORETA)

# Load data
evoked = read_evokeds(fname_evoked, condition=0, baseline=(None, 0))
inverse_operator = read_inverse_operator(fname_inv)
src = inverse_operator['src']

# Compute inverse solution
stc = apply_inverse(evoked, inverse_operator, lambda2, method)
stc.crop(0.0, 0.2)

brain = mne.viz.plot_source_estimates(stc, subject='sample', subjects_dir=data_path / 'subjects', src=src)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

I thought about it a bit more and maybe a major refactoring isn’t the best use of time either,

Agreed, seems like something we can do later

My suggestion would be to make plot_source_estimates and internal function since it’s not maintained to give the right output for every class given the input

plot_source_estimates has been around since at least MNE-Python 0.5, i.e., 10 years:

https://github.com/mne-tools/mne-python/blob/2de217d600e5b198820adb992d5f1b8bda2b006e/mne/viz.py#L875

And while a lot of these will be false positives, the “2k” count here gives me pause as well:

https://github.com/search?q=plot_source_estimates&type=code

So I’d rather fix than deprecate. Or the easiest route is to just .. note:: after the one-line description of the function that it isn’t guaranteed yet to give the correct output for each input, and that stc.plot for surface and stc.plot_3d for vol source estimates should be preferred for optimal behavior

Argh yes we should fix that bug first. Maybe doing a plot that currently on broken main produces an all black screenshot would be a good way to test, because it’s easy to check in CIs (e.g., that the .mean() of the screenshot is greater than 0.005 for example)