But I got into some problems, and I have doubts related to them. When I just run this part of the tutorial:
import mne
from mne.datasets.eyelink import data_path
from mne.preprocessing.eyetracking import read_eyelink_calibration
from mne.viz.eyetracking import plot_gaze
et_fpath = data_path() / “eeg-et” / “sub-01_task-plr_eyetrack.asc”
eeg_fpath = data_path() / “eeg-et” / “sub-01_task-plr_eeg.mff”
raw_et = mne.io.read_raw_eyelink(et_fpath, create_annotations=[“blinks”])
raw_eeg = mne.io.read_raw_egi(eeg_fpath, events_as_annotations=True).load_data()
raw_eeg.filter(1, 30)
print(raw_et.annotations[0][“ch_names”]) # a blink in the right eye
cals = read_eyelink_calibration(et_fpath)
print(f"number of calibrations: {len(cals)}")
first_cal = cals[0] # let’s access the first (and only in this case) calibration
print(first_cal)
first_cal.plot()
first_cal[“screen_resolution”] = (1920, 1080)
first_cal[“screen_size”] = (0.53, 0.3)
first_cal[“screen_distance”] = 0.9
mne.preprocessing.eyetracking.convert_units(raw_et, calibration=first_cal, to=“radians”)
ps_scalings = dict(pupil=1e3)
raw_et.plot(scalings=ps_scalings)
The first plot is appeared as expected and I can see it properly, but as soon as I close it the 2nd plot appears and disappears immediately unless I use block=True. Why is that so?
Also this tutorial assumes we have pandas and defusedxmlinstalled.
This happens when executing the code in an environment without a QT event loop running in the background, that is to say any other environment than ipython (or the ipython jupyter kernel) with %matplotlib qt configured.
To help you further, could you tell us the exact environment you are executing this code in? From the command line? From inside VSCode? A Jupyter Notebook?
First I entered the venv(created using python -m venv venv command and installed deps init via pip install -e .). Then I ran the app.py file(located in root dir - look at the file explorer on the left side) using python. Then I got this issue.
The case is same even when I run this in vscode with bash.
Note: I have not modified anything in the code, just ran the downloaded script as it is.
Even worse, when the raw_et.plot(scalings=ps_scalings) is being shown, and I try to open annotations, it gives a infinite recursive error stack in the terminal, untill I interrupt with ctrl+c:
import mne
import matplotlib
mne.viz.set_browser_backend(“qt”)
mne.set_config(“MNE_BROWSER_THEME”, “light”)
Using sample data
=============================================================================
sample_data_folder = mne.datasets.sample.data_path()
raw_file = sample_data_folder / “MEG” / “sample” / “sample_audvis_filt-0-40_raw.fif”
raw = mne.io.read_raw_fif(raw_file)
raw.plot()
even here, the plot dissappears as soon as it appears, giving this message in terminal: Free RAM could not be determined because “psutil” is not installed. Setting precompute- the code exits immediately.
When I use - raw.plot(block=True), the message still appears but plot is shown.
Well even after installing psutil the behaviour remains the same.
Thanks for the detailed description! I’m also a vim user on windows / powershell, so maybe I can help.
First off, if you run your script using the python command, MNE-Python is in “batch mode” by default. Meaning that scripts will run top to bottom as fast as possible and then the python process ends (closing all windows). The assumption is that you are executing some analysis pipeline on your data.
For “interactive mode”, you need to have an ipython REPL open. In your case, typing ipython in the powershell console would achieve this. Then, from within the REPL, you can first tell ipython that you want a QT event loop running by executing the command %matplotlib qt (including the %). Next, you can run code by either copy/pasting it into the REPL or by executing %run <filename>. Now, figures stay open in the background. Your code does not block and you can keep on executing python code, but as long as you don’t close the REPL, the figure windows will stay open. This is what you’re after I think.