add_head() method in mne.viz.Brain

  • MNE version: e.g. 0.24.0
  • operating system: macOS 12
    Hi, everyone. add_head() method in mne.viz.Brain yielded TypeError. I would like to know what is causing this.

Here is an example. I got TypeError after following the example in mne.

import os.path as op
import matplotlib.pyplot as plt
import matplotlib as mpl

import mne
from mne.datasets import sample

brain_kwargs = dict(alpha=0.1, background='white', cortex='low_contrast')
brain = mne.viz.Brain('sample', subjects_dir=subjects_dir, **brain_kwargs)

stc = mne.read_source_estimate(op.join(sample_dir, 'sample_audvis-meg'))
stc.crop(0.09, 0.1)

kwargs = dict(fmin=stc.data.min(), fmax=stc.data.max(), alpha=0.25,
              smoothing_steps='nearest', time=stc.times)

brain.add_head()
brain.show_view(distance=500,view='sagittal')

The detailed description of the error is:
TypeError Traceback (most recent call last)
Input In [31], in <cell line: 2>()
1 from matplotlib import pyplot as plt
----> 2 brain.add_head()
3 brain.show_view(distance=500,view=‘sagittal’)

File ~/opt/anaconda3/envs/3dbrain/lib/python3.9/site-packages/mne/viz/_brain/_brain.py:2421, in Brain.add_head(self, dense, color, alpha)
2418 color = _to_rgb(color, alpha, alpha=True)
2420 for _ in self._iter_views(‘vol’):
→ 2421 actor, _ = self._renderer.mesh(
2422 *verts.T, triangles=triangles, color=color,
2423 opacity=alpha, reset_camera=False, render=False)
2424 self._add_actor(‘head’, actor)
2426 self._renderer._update()

File ~/opt/anaconda3/envs/3dbrain/lib/python3.9/site-packages/mne/viz/backends/_pyvista.py:333, in PyVistaRenderer.mesh(self, x, y, z, triangles, color, opacity, shading, backface_culling, scalars, colormap, vmin, vmax, interpolate_before_map, representation, line_width, normals, polygon_offset, **kwargs)
331 triangles = np.c
[np.full(len(triangles), 3), triangles]
332 mesh = PolyData(vertices, triangles)
→ 333 return self.polydata(
334 mesh=mesh,
335 color=color,
336 opacity=opacity,
337 normals=normals,
338 backface_culling=backface_culling,
339 scalars=scalars,
340 colormap=colormap,
341 vmin=vmin,
342 vmax=vmax,
343 interpolate_before_map=interpolate_before_map,
344 representation=representation,
345 line_width=line_width,
346 polygon_offset=polygon_offset,
347 **kwargs,
348 )

File ~/opt/anaconda3/envs/3dbrain/lib/python3.9/site-packages/mne/viz/backends/_pyvista.py:304, in _PyVistaRenderer.polydata(self, mesh, color, opacity, normals, backface_culling, scalars, colormap, vmin, vmax, interpolate_before_map, representation, line_width, polygon_offset, **kwargs)
302 rgba = kwargs[“rgba”]
303 kwargs.pop(‘rgba’)
→ 304 actor = _add_mesh(
305 plotter=self.plotter,
306 mesh=mesh, color=color, scalars=scalars,
307 rgba=rgba, opacity=opacity, cmap=colormap,
308 backface_culling=backface_culling,
309 rng=[vmin, vmax], show_scalar_bar=False,
310 smooth_shading=self.figure.smooth_shading,
311 interpolate_before_map=interpolate_before_map,
312 style=representation, line_width=line_width, **kwargs,
313 )
315 if polygon_offset is not None:
316 mapper = actor.GetMapper()

File ~/opt/anaconda3/envs/3dbrain/lib/python3.9/site-packages/mne/viz/backends/_pyvista.py:881, in _add_mesh(plotter, *args, **kwargs)
879 if ‘render’ not in kwargs and ‘render’ in _get_args(plotter.add_mesh):
880 kwargs[‘render’] = False
→ 881 actor = plotter.add_mesh(*args, **kwargs)
882 if smooth_shading and ‘Normals’ in _point_data(mesh):
883 prop = actor.GetProperty()

File ~/opt/anaconda3/envs/3dbrain/lib/python3.9/site-packages/pyvista/plotting/plotting.py:2175, in BasePlotter.add_mesh(self, mesh, color, style, scalars, clim, show_edges, edge_color, point_size, line_width, opacity, flip_scalars, lighting, n_colors, interpolate_before_map, cmap, label, reset_camera, scalar_bar_args, show_scalar_bar, multi_colors, name, texture, render_points_as_spheres, render_lines_as_tubes, smooth_shading, split_sharp_edges, ambient, diffuse, specular, specular_power, nan_color, nan_opacity, culling, rgb, categories, silhouette, use_transparency, below_color, above_color, annotations, pickable, preference, log_scale, pbr, metallic, roughness, render, component, **kwargs)
2172 prop.EdgeVisibilityOn()
2174 rgb_color = parse_color(color, default_color=self._theme.color)
→ 2175 prop.SetColor(rgb_color)
2176 if isinstance(opacity, (float, int)):
2177 prop.SetOpacity(opacity)

TypeError: SetColor argument 1: expected a sequence of 3 values, got 4 values

Please provide your environment first. Using

mne.sys_info()

Mine is OK.


Please make sure you have all the latest packages installed, especially pyvista.

Here is the environment information. Thank you for your reply. I will install the unfound package and try in again.
Platform: macOS-10.16-x86_64-i386-64bit
Python: 3.8.12 (default, Oct 12 2021, 06:23:56) [Clang 10.0.0 ]
Executable: /Users/brunnerlab/opt/anaconda3/envs/csc/bin/python
CPU: i386: 4 cores
Memory: 32.0 GB

mne: 0.24.1
numpy: 1.22.2 {blas=NO_ATLAS_INFO, lapack=lapack}
scipy: 1.8.0
matplotlib: 3.5.1 {backend=module://matplotlib_inline.backend_inline}

sklearn: 1.0.2
numba: 0.53.1
nibabel: 3.2.2
nilearn: 0.9.0
dipy: 1.3.0
cupy: Not found
pandas: 1.4.0
mayavi: 4.7.2
pyvista: 0.33.2 {OpenGL 4.1 ATI-4.7.29 via AMD Radeon R9 M390 OpenGL Engine}
pyvistaqt: 0.7.0
ipyvtklink: Not found
vtk: 9.0.3
PyQt5: 5.12.3
ipympl: Not found
mne_qt_browser: 0.1.7
pooch: v1.6.0

Your vtk might be out of date, looks fairly new though. I’d try pip install -U vtk

1 Like