Head Model and Forward Computation tutorial

Hi!

I’m trying to reproduce the Head Model and Forward Computation tutorial, and I was getting the same error: RuntimeError: Render window interactor must be initialized before processing events.

After reading the messages here, I installed pyvistaqt through conda (pyvistaqt conda-forge/noarch::pyvistaqt-0.5.0-pyhd8ed1ab_0), and now I’m getting the following error when executing cell [4] in the tutorial:

Read a total of 3 projection items:
    PCA-v1 (1 x 102)  idle
    PCA-v2 (1 x 102)  idle
    PCA-v3 (1 x 102)  idle

Using lh.seghead for head surface.
Getting helmet for system 306m
Using pyvista 3d backend.

qt.qpa.xcb: QXcbConnection: XCB error: 128 (Unknown), sequence: 418, resource id: 0, major code: 130 (Unknown), minor code: 2

<mne.viz.backends._pyvista._Figure at 0x7fe19a3d9f10>

I have a fresh install using : https://mne.tools/stable/install/mne_python.html#collapse_server-if-you-are-installing-on-a-headless-server

I also have xvfb running, I started both xvfb and jupyter following pyvista’s instructions: Redirecting to https://docs.pyvista.org/version/stable/getting-started/installation.html

Here is my mne.sys_info()

Platform: Linux-5.4.0-80-generic-x86_64-with-glibc2.10
Python: 3.8.0 | packaged by conda-forge | (default, Nov 22 2019, 19:11:38) [GCC 7.3.0]
Executable: /home/lbarbosa/miniconda3/envs/mnes/bin/python
CPU: x86_64: 128 cores
Memory: Unavailable (requires “psutil” package)
mne: 0.23.1
numpy: 1.21.2 {blas=NO_ATLAS_INFO, lapack=lapack}
scipy: 1.7.1
matplotlib: 3.4.3 {backend=module://matplotlib_inline.backend_inline}

sklearn: 0.24.2
numba: Not found
nibabel: 3.2.1
nilearn: 0.8.0
dipy: Not found
cupy: Not found
pandas: 1.3.2
mayavi: Not found
pyvista: 0.31.3 {pyvistaqt=0.5.0, OpenGL 3.3 (Core Profile) Mesa 18.3.1 via llvmpipe (LLVM 7.0, 128 bits)}
vtk: 9.0.0
PyQt5: 5.15.4

Thank you very much for any help!

I often see this when running code on a remote server, and find that the plots actually do work (I can assign the plot to a variable, save them as PDF or PNG, and then view them). In fact, the next line of your “error” shows that the function did in fact return a Figure object:

Can you check whether that works for you? Also please say more about how you’re trying to plot (in a notebook? Interactively in python/ipython with the “pop-up” plot window? are you connected to a remote server? Does the server have a display attached, or is it “headless”?

Thank you for the reply (and sorry for necroposting in the other thread)!

Indeed I noticed that part of the output was the normal stdout with the output of the mne.viz.plot_alignment function. However, I imagined that that object was just empty.

I also was not really sure what this object represented, since the documentation says that mne.viz.plot_alignment returns * instance of [ mayavi.mlab.Figure ]*, and it is clearly returning another object.

I did some inspection on the mne/viz/backends/_pyvista.py and found that the build funciton returns a plotter, so together with the pyvista tutorial I was actually able to plot the figure!

If possible, I’d like to be able to simply use the normal interactive plot… Thank you very much for any help!

This may help to shed some light in the problem: I installed XQuartz in my macbook and run ssh with -Y so that I can do X11 forwarding. I run the tutorial code in ipython and got the following error when trying to run mne.viz.plot_alignment

2021-08-27 01:08:08.371 ( 85.275s) [ 5D364740]vtkXOpenGLRenderWindow.:635 ERR| vtkXOpenGLRenderWindow (0x555d6501bd10): Cannot create GLX context. Aborting.

This happens with both pyvista and mayavi. I’m going through stackexchange, this seems to be related: Mayavi off screen rendering not working for VTK 7.1.0 · Issue #477 · enthought/mayavi · GitHub

I believe XQuartz doesn’t have 3D acceleration support, hence GLX context creation fails. I doubt this is related to the problem you observed on your Linux computer.

That is good to know. Also sorry if I was not clear, but I have always been using the same setup: a macbook BigSur 11.5 as client (with firefox 91.0.2) and a linux Ubuntu 18.04.5 LTS as server.

1 Like

Yes but if you ssh -Y into the Linux box from XQuartz, the Linux machine will use XQartz on your Mac as X11 server

I fixed my problem by downgrading pyvista to 0.29.1 (last version before 0.30). Following the error stack, I noticed that viewer.layout had no property width on viz/backends/_notebook.py line 352. The object was from the type PIL.Image.Image, which looks like some default class returned by pyvista when it is not happy with the backend (for instance if I change the backend to ipygany, the viewer is from a class from ipygany and not PIL.Image.Image, and it “kinda” works). So I tried a few things to fix the vtk/ipyvtk installation since the backend chosen by MNE is ipyvtk_simple, but nothing worked. I noticed that in the code, for older versions of pyvista, the parameters passed to self.plotter.show were different, so I gave it a shot, and it worked!

I’m still not sure why it doesn’t work with the most recent versions of pyvista, since I have vtk 9.0.0 installed, etc. I even tried to manually install the package ipyvtk-simple, but didn’t work. Thank you for the help (I didn’t need to install pyvistaqt btw, I think in the jupyter/headless server setup, it is better to use the notebook backend and avoid qt).

1 Like