Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ dependencies:
- trame
- trame-pyvista
- trame-vtk
- trame-vuetify
- trame-vuetify !=3.2.3
- vtk ==9.6.2
- xlrd
- pip:
Expand Down
32 changes: 32 additions & 0 deletions mne/viz/backends/_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os
import os.path as op
import warnings
from contextlib import contextmanager, nullcontext

from ipyevents import Event
Expand Down Expand Up @@ -112,6 +113,37 @@

_JUPYTER_BACKEND = "trame"


class _NotebookPlotter(Plotter):
"""PyVista ``Plotter`` for the notebook backend.

Validate the object returned by show, as PyVista silently falls back static PIL
when the trame Jupyter backend cannot be loaded.
"""

def show(self, *args, **kwargs):
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
viewer = super().show(*args, **kwargs)
if not isinstance(viewer, Widget):
reasons = "\n".join(
f"- {w.message}"
for w in caught
if any(key in str(w.message) for key in ("backend", "trame", "static"))
)
raise RuntimeError(
f'The notebook 3D backend is not functional: the "{_JUPYTER_BACKEND}" '
"PyVista Jupyter backend returned a "
f"{type(viewer).__module__}.{type(viewer).__qualname__} instead of an "
"interactive widget. This usually means the installed trame packages "
"(trame, trame-vtk, trame-vuetify, trame-pyvista) are missing or "
"mutually incompatible."
+ (f"\n\nPyVista reported:\n{reasons}" if reasons else "")
)
if kwargs["return_viewer"]:
return viewer


# %%
# Widgets
# -------
Expand Down
6 changes: 4 additions & 2 deletions mne/viz/backends/_pyvista.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy as np
import pyvista
from pyvista import Line, Plotter, PolyData, close_all
from pyvista import Line, Plotter, PolyData, close_all # noqa: F401 # re-exported
from pyvista.plotting.plotter import _ALL_PLOTTERS
from pyvistaqt import BackgroundPlotter
from vtkmodules.util.numpy_support import numpy_to_vtk
Expand Down Expand Up @@ -131,7 +131,9 @@ def _init(

self.store["app_window_class"] = _MNEMainWindow
else:
self._plotter_class = Plotter
from ._notebook import _NotebookPlotter

self._plotter_class = _NotebookPlotter

self._nrows, self._ncols = self.store["shape"]

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ full-no-qt = [
"trame",
"trame-pyvista",
"trame-vtk",
"trame-vuetify",
"trame-vuetify != 3.2.3",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@wmvanvliet see pin here, just avoid 3.2.3 and you should be good ☝️

"vtk >= 9.2",
"xlrd",
]
Expand Down
2 changes: 1 addition & 1 deletion tools/install_pre_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ python -m pip install $STD_ARGS \
git+https://github.com/h5io/h5io \
git+https://github.com/BUNPC/pysnirf2 \
git+https://github.com/the-siesta-group/edfio \
trame trame-vtk trame-vuetify trame-pyvista nest-asyncio2 jupyter ipyevents ipympl \
trame trame-vtk "trame-vuetify!=3.2.3" trame-pyvista nest-asyncio2 jupyter ipyevents ipympl \
openmeeg imageio-ffmpeg xlrd mffpy traitlets pybv eeglabio defusedxml antio curryreader \
filelock
echo "::endgroup::"
Expand Down
Loading