Skip to content

Commit 8a27d6d

Browse files
FIX: add sys.platform guards for interactive plots and large datasets in JupyterLite
- tutorials/evoked/40_whitened.py: guard raw.plot() and epochs.plot() (interactive Qt widgets not available in Pyodide/emscripten) - examples/preprocessing/muscle_ica.py: guard all ica.plot_sources(), ica.plot_properties(), ica.plot_overlay(), ica.plot_scores() calls - tutorials/io/60_ctf_bst_auditory.py: raise RuntimeError on emscripten; BST auditory dataset is 2.9 GB and cannot be downloaded in the browser - tutorials/io/70_reading_eyetracking_data.py: raise RuntimeError on emscripten; EyeLink dataset not available in browser - examples/visualization/eyetracking_plot_heatmap.py: raise RuntimeError on emscripten; EyeLink dataset not available in browser Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7c133c7 commit 8a27d6d

5 files changed

Lines changed: 50 additions & 11 deletions

File tree

examples/preprocessing/muscle_ica.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
# %%
2121

22+
import sys
23+
2224
import mne
2325

2426
data_path = mne.datasets.sample.data_path()
@@ -44,7 +46,8 @@
4446

4547
# %%
4648
# Remove components with postural muscle artifact using ICA
47-
ica.plot_sources(raw)
49+
if sys.platform != "emscripten":
50+
ica.plot_sources(raw)
4851

4952
# %%
5053
# By inspection, let's select out the muscle-artifact components based on
@@ -71,19 +74,22 @@
7174
# slope in log-log units; this is a very typical pattern for muscle artifact.
7275

7376
muscle_idx = [6, 7, 8, 9, 10, 11, 12, 13, 14]
74-
ica.plot_properties(raw, picks=muscle_idx, log_scale=True)
77+
if sys.platform != "emscripten":
78+
ica.plot_properties(raw, picks=muscle_idx, log_scale=True)
7579

7680
# first, remove blinks and heartbeat to compare
7781
blink_idx = [0]
7882
heartbeat_idx = [5]
7983
ica.apply(raw, exclude=blink_idx + heartbeat_idx)
80-
ica.plot_overlay(raw, exclude=muscle_idx)
84+
if sys.platform != "emscripten":
85+
ica.plot_overlay(raw, exclude=muscle_idx)
8186

8287
# %%
8388
# Finally, let's try an automated algorithm to find muscle components
8489
# and ensure that it gets the same components we did manually.
8590
muscle_idx_auto, scores = ica.find_bads_muscle(raw)
86-
ica.plot_scores(scores, exclude=muscle_idx_auto)
91+
if sys.platform != "emscripten":
92+
ica.plot_scores(scores, exclude=muscle_idx_auto)
8793
print(
8894
f"Manually found muscle artifact ICA components: {muscle_idx}\n"
8995
f"Automatically found muscle artifact ICA components: {muscle_idx_auto}"
@@ -107,10 +113,12 @@
107113
n_components=15, method="picard", max_iter="auto", random_state=97
108114
)
109115
ica.fit(raw)
110-
ica.plot_sources(raw)
116+
if sys.platform != "emscripten":
117+
ica.plot_sources(raw)
111118
muscle_idx_auto, scores = ica.find_bads_muscle(raw)
112-
ica.plot_properties(raw, picks=muscle_idx_auto, log_scale=True)
113-
ica.plot_scores(scores, exclude=muscle_idx_auto)
119+
if sys.platform != "emscripten":
120+
ica.plot_properties(raw, picks=muscle_idx_auto, log_scale=True)
121+
ica.plot_scores(scores, exclude=muscle_idx_auto)
114122

115123
print(
116124
f"Manually found muscle artifact ICA components: {muscle_idx}\n"

examples/visualization/eyetracking_plot_heatmap.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,20 @@
2626
# :ref:`example data <eyelink-dataset>`: eye-tracking data recorded from SR research's
2727
# ``'.asc'`` file format.
2828

29+
import sys
30+
2931
import matplotlib.pyplot as plt
3032

3133
import mne
3234
from mne.viz.eyetracking import plot_gaze
3335

36+
if sys.platform == "emscripten":
37+
raise RuntimeError(
38+
"This example requires the MNE EyeLink dataset, "
39+
"which is not available in the browser. Please run this example "
40+
"locally. Visit https://mne.tools for instructions."
41+
)
42+
3443
task_fpath = mne.datasets.eyelink.data_path() / "freeviewing"
3544
et_fpath = task_fpath / "sub-01_task-freeview_eyetrack.asc"
3645
stim_fpath = task_fpath / "stim" / "naturalistic.png"

tutorials/evoked/40_whitened.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
# %%
2323

24+
import sys
25+
2426
import mne
2527
from mne.datasets import sample
2628

@@ -52,14 +54,16 @@
5254
)
5355

5456
# butterfly mode shows the differences most clearly
55-
raw.plot(events=events, butterfly=True)
56-
raw.plot(noise_cov=noise_cov, events=events, butterfly=True)
57+
if sys.platform != "emscripten":
58+
raw.plot(events=events, butterfly=True)
59+
raw.plot(noise_cov=noise_cov, events=events, butterfly=True)
5760

5861
# %%
5962
# Epochs with whitening
6063
# ---------------------
61-
epochs.plot(events=True)
62-
epochs.plot(noise_cov=noise_cov, events=True)
64+
if sys.platform != "emscripten":
65+
epochs.plot(events=True)
66+
epochs.plot(noise_cov=noise_cov, events=True)
6367

6468
# %%
6569
# Evoked data with whitening

tutorials/io/60_ctf_bst_auditory.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
# %%
2828

29+
import sys
30+
2931
import numpy as np
3032
import pandas as pd
3133

@@ -35,6 +37,13 @@
3537
from mne.io import read_raw_ctf
3638
from mne.minimum_norm import apply_inverse
3739

40+
if sys.platform == "emscripten":
41+
raise RuntimeError(
42+
"This tutorial requires the Brainstorm auditory dataset (~2.9 GB) "
43+
"which is not available in the browser. Please run this tutorial "
44+
"locally. Visit https://mne.tools for instructions."
45+
)
46+
3847
# %%
3948
# To reduce memory consumption and running time, some of the steps are
4049
# precomputed. To run everything from scratch change ``use_precomputed`` to

tutorials/io/70_reading_eyetracking_data.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,17 @@
8585
"""
8686

8787
# %%
88+
import sys
89+
8890
import mne
8991

92+
if sys.platform == "emscripten":
93+
raise RuntimeError(
94+
"This tutorial requires the MNE misc dataset with eyetracking data, "
95+
"which is not available in the browser. Please run this tutorial "
96+
"locally. Visit https://mne.tools for instructions."
97+
)
98+
9099
# %%
91100
fpath = mne.datasets.misc.data_path() / "eyetracking" / "eyelink"
92101
fname = fpath / "px_textpage_ws.asc"

0 commit comments

Comments
 (0)