Kernel crashes while executing stc.plot

I am using Ubuntu 22.04 (WSL2) on Windows 10. My Kernel crashes when running stc.plot.

I was testing the stc.plot by testing the MNE example code Visualize source time courses (stcs). MNE example stc file was loaded and plot in the code.

It seems to me is the problem of backend or I miss some information packages for Ubuntu, but I can not find out the reason. It seems that pyvista is installed properly. I can execute pyvista example in my Jupyter notebook.

Here is the testing code:

import matplotlib.pyplot as plt

import numpy as np

import mne

from mne import read_evokeds

from mne.datasets import fetch_hcp_mmp_parcellation, sample

from mne.minimum_norm import apply_inverse, read_inverse_operator

data_path = sample.data_path()

meg_path = data_path / "MEG" / "sample"

subjects_dir = data_path / "subjects"

fname_evoked = meg_path / "sample_audvis-ave.fif"

fname_stc = meg_path / "sample_audvis-meg"

fetch_hcp_mmp_parcellation(subjects_dir)

stc = mne.read_source_estimate(fname_stc, subject="sample")

initial_time = 0.1
brain = stc.plot(
    subjects_dir=subjects_dir,
    initial_time=initial_time,
    clim=dict(kind="value", lims=[3, 6, 9]),
    smoothing_steps=7,
)

It returns:

Using pyvistaqt 3d backend.
Using control points [ 5.01632618 6.06303297 21.63565434]
The Kernel crashed while executing code in the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click here for more info. View Jupyter log for further details.

The Jupyter log can not specify the error reson:

[error] Disposing session as kernel process died ExitCode: undefined, Reason:

However, if I use matplotlib for my backend, the figure can be returned.

mpl_fig = stc.plot(
    subjects_dir=subjects_dir,
    initial_time=0,
    backend="matplotlib",
    verbose="error",
    smoothing_steps=7,
)

The figure can be returned:

  • MNE version: 1.8.0
  • operating system: Ubuntu 22.04 on WSL2

Further system_info:

Platform Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python 3.9.19 | packaged by conda-forge | (main, Mar 20 2024, 12:50:21) [GCC 12.3.0]
Executable /home/gs/miniconda3/envs/eeg_env/bin/python3.9
CPU x86_64 (6 cores)
Memory 31.3 GB

Core
โ”œโ˜‘ mne 1.8.0 (latest release)
โ”œโ˜‘ numpy 1.26.4 (OpenBLAS 0.3.27 with 6 threads)
โ”œโ˜‘ scipy 1.13.1
โ””โ˜‘ matplotlib 3.9.2 (backend=qtagg)

Numerical (optional)
โ”œโ˜‘ sklearn 1.5.1
โ”œโ˜‘ numba 0.60.0
โ”œโ˜‘ nibabel 5.2.1
โ”œโ˜‘ nilearn 0.10.4
โ”œโ˜‘ dipy 1.9.0
โ”œโ˜‘ openmeeg 2.5.12
โ”œโ˜‘ pandas 2.2.2
โ”œโ˜‘ h5io 0.2.4
โ”œโ˜‘ h5py 3.11.0
โ””โ˜ unavailable cupy

Visualization (optional)
โ”œโ˜‘ pyvista 0.44.1 (OpenGL 4.5 (Core Profile) Mesa 24.1.5 via llvmpipe (LLVM 18.1.8, 256 bits))
โ”œโ˜‘ pyvistaqt 0.11.1
โ”œโ˜‘ vtk 9.3.1
โ”œโ˜‘ qtpy 2.4.1 (PyQt5=5.15.8)
โ”œโ˜‘ pyqtgraph 0.13.7
โ”œโ˜‘ mne-qt-browser 0.6.3
โ”œโ˜‘ ipywidgets 8.1.5
โ”œโ˜‘ trame_client 3.2.5
โ”œโ˜‘ trame_server 3.0.3
โ”œโ˜‘ trame_vtk 2.8.10
โ”œโ˜‘ trame_vuetify 2.6.2
โ””โ˜ unavailable ipympl

Ecosystem (optional)
โ”œโ˜‘ eeglabio 0.0.2-4
โ”œโ˜‘ edfio 0.4.3
โ”œโ˜‘ mffpy 0.9.0
โ”œโ˜‘ pybv 0.7.5
โ””โ˜ unavailable mne-bids, mne-nirs, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline, neo

I wonder if you are hitting X Error of failed request: BadWindow (invalid Window parameter) ยท Issue #445 ยท pyvista/pyvistaqt ยท GitHub
The solution proposed worked for me, I added:

import os

os.environ["QT_QPA_PLATFORM"] = "xcb"  # wayland crashes pyvistaqt background plotter

Mathieu

Dear Mathieu, thanks for your post.

I tried your code, and it was still not working.

This crash because matplotlib is missing. After installing matplotlib, the kernel is no longer crashing during the stc.plot()

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.