Skip to content

Make the js backend a proper notebook backend - #14333

Open
larsoner wants to merge 17 commits into
mne-tools:mainfrom
larsoner:js-backend
Open

larsoner wants to merge 17 commits into
mne-tools:mainfrom
larsoner:js-backend

Conversation

@larsoner

Copy link
Copy Markdown
Member

Make the "jupyterlite" backend an actual interactive backend named notebook_js. Performance is not great because on changes the whole thing needs to be re-serialized, but I'm going to work on streamlining that at the pyvista-js end. Changes ended up being pretty simple, with the exception being due to this re-serialization -- we need to "double buffer", i.e., render to a new widget fully before swapping, rather than a bare replace in order to avoid flashing. And we need some JS to make it clear an interactive update is in progress but waiting on the serialization. In the meantime zooming and rotating etc. is faster than the notebook backend (and the abstraction helps our code readability actually I think).

This code:

import mne

mne.viz.set_3d_backend("notebook_js")
data_path = mne.datasets.sample.data_path()
stc = mne.read_source_estimate(
    data_path / "MEG" / "sample" / "sample_audvis-meg", subject="sample"
)
brain = stc.plot(
    subjects_dir=data_path / "subjects",
    hemi="lh",
    views="lat",
    initial_time=0.1,
    time_viewer=True,
)

in a Jupyter notebook gives:

Screenshot From 2026-09-23 15-56-45

Also fixes a little double-event-publish bug along the way.

Changes drafted with Claude Opus 5.5 (especially helping with the JS!) but understood and iterated on by me.

@larsoner
larsoner marked this pull request as draft September 24, 2026 11:57
@larsoner

Copy link
Copy Markdown
Member Author

Converting to draft since tkoyama010/pyvista-js#634 will take updates from ~2.4s to ~0.4s, and simplify things a little bit for us (we won't need the double-buffering anymore!). We'll require quite a new pyvista-js (because that needs to be merged then a release made) but I think that's okay.

@larsoner
larsoner force-pushed the js-backend branch 3 times, most recently from a787d77 to 615da3d Compare September 26, 2026 15:20
* upstream/main: (26 commits)
  Splitting _brain.py into multiple modules (phase 1) (mne-tools#14359)
  Fix small corner-case bug with moments (mne-tools#14364)
  Coregistration GUI modernisation (phase 5) (mne-tools#14353)
  FIX: Prevent memory leak in RawArray by removing data from _init_kwargs (mne-tools#14360)
  MAINT: Update code credit (mne-tools#14365)
  type-hint the rest of mne/_fiff (mne-tools#14352)
  MAINT: Update dependency specifiers (mne-tools#14362)
  MAINT: Update dependency specifiers (mne-tools#14357)
  Switch to mne-tools SPEC-0 action (mne-tools#14356)
  MAINT: Move Pixi file updates to autofix workflow (mne-tools#14345)
  BUG: Fix SNIRF landmark length unit scaling (mne-tools#14354)
  DRY dipole code and comment on implementation (mne-tools#14350)
  Speed up CSD and PSD computations (mne-tools#14355)
  [dependabot]: Bump the actions group with 4 updates (mne-tools#14349)
  MAINT: Update pre-commit hook versions (mne-tools#14347)
  Switch to `mne-tools/rename-towncrier` action (mne-tools#14344)
  Fix for latest pyvista-js (mne-tools#14343)
  Avoid copies and support larger files in EEGLAB export (mne-tools#14338)
  Remove line breaks in sponsors check issue text (mne-tools#14337)
  Fix EEGLAB events after dropped epochs (mne-tools#14067)
  ...

# Conflicts:
#	mne/viz/_brain/_brain.py
#	mne/viz/backends/tests/test_renderer.py
@larsoner
larsoner marked this pull request as ready for review October 7, 2026 17:02
@larsoner

larsoner commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

Okay this is ready! Can be tested with the "launch lite" button for the dSPM example, which links here and for me gives:

image

@drammock

drammock commented Oct 7, 2026

Copy link
Copy Markdown
Member

@natinew77-creator do you want to review this one?

@natinew77-creator

Copy link
Copy Markdown
Contributor

@natinew77-creator do you want to review this one?

Thanks for reaching out! I'd be happy to take a look. I'm currently busy with classes and midterm exams, but I'll review it as soon as I have some free time.

# Conflicts:
#	mne/viz/_brain/_brain.py
#	mne/viz/backends/_notebook.py

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants