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.

[BUG] `mne.viz.Brain` raises cryptic error when plotting 'seghead', works for `mne.viz.plot_alignment`

See original GitHub issue

Here’s some minimally reproducible code:

import os.path as op
from mne.datasets import sample
import mne

data_path = sample.data_path()
sample_dir = op.join(data_path, 'MEG', 'sample')
subjects_dir = op.join(data_path, 'subjects')
evoked = mne.read_evokeds(op.join(sample_dir, 'sample_audvis-ave.fif'))[0]
trans = mne.read_trans(op.join(sample_dir, 'sample_audvis_raw-trans.fif'))
mne.viz.plot_alignment(evoked.info, trans, subject='sample', subjects_dir=subjects_dir, surfaces=['seghead'])  # works
mne.viz.Brain('sample', 'lh', 'seghead', subjects_dir=subjects_dir)  # raises error

Stack trace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/alexrockhill/projects/mne-python/mne/viz/_brain/_brain.py", line 523, in __init__
    mesh.add_overlay(
  File "/Users/alexrockhill/projects/mne-python/mne/viz/_brain/_brain.py", line 178, in add_overlay
    self._apply()
  File "/Users/alexrockhill/projects/mne-python/mne/viz/_brain/_brain.py", line 194, in _apply
    self._renderer._set_mesh_scalars(
  File "/Users/alexrockhill/projects/mne-python/mne/viz/backends/_pyvista.py", line 699, in _set_mesh_scalars
    mesh.point_arrays[name] = scalars
  File "/Users/alexrockhill/software/anaconda3/envs/mne/lib/python3.9/site-packages/pyvista/core/datasetattributes.py", line 57, in __setitem__
    self.append(narray=value, name=key)
  File "/Users/alexrockhill/software/anaconda3/envs/mne/lib/python3.9/site-packages/pyvista/core/datasetattributes.py", line 211, in append
    raise ValueError(f'narray length of ({narray.shape[0]}) != required length ({array_len})')
ValueError: narray length of (155407) != required length (267122)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
larsonercommented, Jul 19, 2021

I think eventually they might all need a remove_XXX that will complicate things a bit but that is a +1 from me for style.

Can you open an issue for this and ping @GuillaumeFavelier to consider after the coreg class refactor is done at some point? One way to make this simple is to have each method return a list of VTK actors, and the Brain instance can keep track internally of a list of actors it has added. Then we can just have a brain.remove(actors) method that .pops each actor from the internal list and removes it from each plotter.

1reaction
larsonercommented, Jul 19, 2021

I would really rather not add a new parameter to the Brain constructor, the signature is already too long. Plus there are options one might want to specify (which surface/density/filename, color, opacity) so a dedicated add_head method seems better to me

Are there any other surfaces that are formatted as lh.? that also don’t work

I would raise an error for surface=seghead, I’m not sure if there are other surfaces that are incompatible

Read more comments on GitHub >

github_iconTop Results From Across the Web

mne.viz.plot_alignment — MNE 1.2.2 documentation
Plot head, sensor, and source space alignment in 3D. Parameters: info mne. ... For single layer BEMs it is recommended to use 'brain'...
Read more >
[BUG] mne.viz.Brain volume rendering doesn't show up #10519
I thought about it a bit more and maybe a major refactoring isn't the best use of time either, since stc.plot and stc.plot_3d...
Read more >
Problems running mne.viz.plot_alignment() from within Spyder
I'm trying to use mne.viz.plot_alignment (which doesn't have “block=” argument). The only way I've found to keep the plot window open is to...
Read more >
Colorbar for mne.viz.plot_topomap ? Python - Stack Overflow
Here is the answer to this question: https://mne.discourse.group/t/mne-viz-plot-topomap-and-color-bar/3141/4.
Read more >
Averaging ERPs: Creating MNE Evoked objects
import mne mne.set_log_level('error') # reduce extraneous MNE output # Participant ID ... We use the function mne.viz.plot_compare_evokeds() , which plots ...
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