Repository: mne-tools/mne-python

Issue:
MAINT: Decrease doc build time
Now that we have https://mne.tools/dev/sg_execution_times.html we can more easily see how each example contributes to our doc build time. In particular it looks like the following are all over a minute, we should use `py-spy` and `line_profiler` to figure out how to speed these up:

- [ ] `examples/inverse/dics_epochs.py`
- [ ] `tutorials/intro/70_report.py`
- [ ] `tutorials/stats-sensor-space/75_cluster_ftest_spatiotemporal.py`
- [ ] `tutorials/inverse/60_visualize_stc.py` (should maybe also combine with `examples/visualization/brain.py`)
- [ ] `tutorials/forward/30_forward.py`
- [ ] `tutorials/io/60_ctf_bst_auditory.py`

These examples use > 1 GB memory, `mprof` hopefully could help with that:

- [ ] `examples/inverse/dics_epochs.py`
- [ ] `tutorials/clinical/60_sleep.py`

I'll probably try it in the next week unless someone else beats me to it.


Discussion:

Resolving patch:
diff --git a/examples/inverse/dics_epochs.py b/examples/inverse/dics_epochs.py
--- a/examples/inverse/dics_epochs.py
+++ b/examples/inverse/dics_epochs.py
@@ -45,7 +45,7 @@
 events = mne.find_events(raw)
 epochs = mne.Epochs(
     raw,
-    events,
+    events[:22],  # just for execution speed of the tutorial
     event_id=1,
     tmin=-1,
     tmax=2.5,
@@ -56,7 +56,6 @@
     ),
     preload=True,
 )
-epochs = epochs[:10]  # just for speed of execution for the tutorial
 
 # We are mostly interested in the beta band since it has been shown to be
 # active for somatosensory stimulation
@@ -121,7 +120,7 @@
     subjects_dir=subjects_dir,
     hemi="both",
     views="dorsal",
-    initial_time=0.55,
+    initial_time=1.2,
     brain_kwargs=dict(show=False),
     add_data_kwargs=dict(
         fmin=fmax / 10,
@@ -131,7 +130,3 @@
         colorbar_kwargs=dict(label_font_size=10),
     ),
 )
-
-# You can save a movie like the one on our documentation website with:
-# brain.save_movie(tmin=0.55, tmax=1.5, interpolation='linear',
-#                  time_viewer=True)
diff --git a/tutorials/intro/70_report.py b/tutorials/intro/70_report.py
--- a/tutorials/intro/70_report.py
+++ b/tutorials/intro/70_report.py
@@ -203,12 +203,9 @@
 # ignored; instead, only the explicitly passed projectors will be plotted.
 
 ecg_proj_path = sample_dir / "sample_audvis_ecg-proj.fif"
-eog_proj_path = sample_dir / "sample_audvis_eog-proj.fif"
-
 report = mne.Report(title="Projectors example")
 report.add_projs(info=raw_path, title="Projs from info")
 report.add_projs(info=raw_path, projs=ecg_proj_path, title="ECG projs from path")
-report.add_projs(info=raw_path, projs=eog_proj_path, title="EOG projs from path")
 report.save("report_projs.html", overwrite=True)
 
 # %%
@@ -289,7 +286,11 @@
 
 report = mne.Report(title="BEM example")
 report.add_bem(
-    subject="sample", subjects_dir=subjects_dir, title="MRI & BEM", decim=20, width=256
+    subject="sample",
+    subjects_dir=subjects_dir,
+    title="MRI & BEM",
+    decim=40,
+    width=256,
 )
 report.save("report_mri_and_bem.html", overwrite=True)
 
@@ -452,7 +453,7 @@
 
 mne_logo_path = Path(mne.__file__).parent / "icons" / "mne_icon-cropped.png"
 fig_array = plt.imread(mne_logo_path)
-rotation_angles = np.linspace(start=0, stop=360, num=17)
+rotation_angles = np.linspace(start=0, stop=360, num=8, endpoint=False)
 
 figs = []
 captions = []
@@ -462,7 +463,7 @@
     fig_array_rotated = fig_array_rotated.clip(min=0, max=1)
 
     # Create the figure
-    fig, ax = plt.subplots()
+    fig, ax = plt.subplots(figsize=(3, 3), constrained_layout=True)
     ax.imshow(fig_array_rotated)
     ax.set_axis_off()
 
@@ -470,17 +471,11 @@
     figs.append(fig)
     captions.append(f"Rotation angle: {round(angle, 1)}°")
 
-# can also be a MNEQtBrowser instance
-with mne.viz.use_browser_backend("qt"):
-    figs.append(raw.plot())
-captions.append("... plus a raw data plot")
-
 report = mne.Report(title="Multiple figures example")
 report.add_figure(fig=figs, title="Fun with figures! 🥳", caption=captions)
 report.save("report_custom_figures.html", overwrite=True)
-for fig in figs[:-1]:
+for fig in figs:
     plt.close(fig)
-figs[-1].close()
 del figs
 
 # %%
@@ -517,7 +512,9 @@
 
 report = mne.Report(title="Tags example")
 report.add_image(
-    image=mne_logo_path, title="MNE Logo", tags=("image", "mne", "logo", "open-source")
+    image=mne_logo_path,
+    title="MNE Logo",
+    tags=("image", "mne", "logo", "open-source"),
 )
 report.save("report_tags.html", overwrite=True)
 
@@ -611,7 +608,7 @@
 report = mne.Report(
     title="parse_folder example 3", subject="sample", subjects_dir=subjects_dir
 )
-report.parse_folder(data_path=data_path, pattern="", mri_decim=25)
+report.parse_folder(data_path=data_path, pattern="", mri_decim=40)
 report.save("report_parse_folder_mri_bem.html", overwrite=True)
 
 # %%
@@ -638,8 +635,8 @@
 
 baseline = (None, 0)
 cov_fname = sample_dir / "sample_audvis-cov.fif"
-pattern = "sample_audvis-no-filter-ave.fif"
-evoked = mne.read_evokeds(sample_dir / pattern)[0]
+pattern = "sample_audvis-ave.fif"
+evoked = mne.read_evokeds(sample_dir / pattern)[0].pick("eeg").decimate(4)
 report = mne.Report(
     title="parse_folder example 4", baseline=baseline, cov_fname=cov_fname
 )
@@ -650,22 +647,6 @@
     )
 report.save("report_parse_folder_evoked.html", overwrite=True)
 
-# %%
-# If you want to actually *view* the noise covariance in the report, make sure
-# it is captured by the pattern passed to :meth:`~mne.Report.parse_folder`, and
-# also include a source for an :class:`~mne.Info` object (any of the
-# :class:`~mne.io.Raw`, :class:`~mne.Epochs` or :class:`~mne.Evoked`
-# :file:`.fif` files that contain subject data also contain the measurement
-# information and should work):
-
-pattern = "sample_audvis-cov.fif"
-info_fname = sample_dir / "sample_audvis-ave.fif"
-report = mne.Report(title="parse_folder example 5", info_fname=info_fname)
-report.parse_folder(
-    data_path, pattern=pattern, render_bem=False, n_time_points_evokeds=5
-)
-report.save("report_parse_folder_cov.html", overwrite=True)
-
 # %%
 #
 # Adding custom HTML (e.g., a description text)
diff --git a/tutorials/stats-sensor-space/75_cluster_ftest_spatiotemporal.py b/tutorials/stats-sensor-space/75_cluster_ftest_spatiotemporal.py
--- a/tutorials/stats-sensor-space/75_cluster_ftest_spatiotemporal.py
+++ b/tutorials/stats-sensor-space/75_cluster_ftest_spatiotemporal.py
@@ -58,7 +58,7 @@
 
 # Setup for reading the raw data
 raw = mne.io.read_raw_fif(raw_fname, preload=True)
-raw.filter(1, 30)
+raw.filter(1, 25)
 events = mne.read_events(event_fname)
 
 # %%
@@ -75,6 +75,7 @@
     tmin,
     tmax,
     picks=picks,
+    decim=2,  # just for speed!
     baseline=None,
     reject=reject,
     preload=True,


Test patch: