Skip to content

Add set_head_sphere method to store head outline in info - #14313

Merged
wmvanvliet merged 7 commits into
mne-tools:mainfrom
wmvanvliet:info-head-sphere
Sep 17, 2026
Merged

wmvanvliet merged 7 commits into
mne-tools:mainfrom
wmvanvliet:info-head-sphere

Conversation

@wmvanvliet

Copy link
Copy Markdown
Contributor

closes #14307

Adds MontageMixin.set_head_sphere(sphere=None) so that object such as Raw, Epochs, Evoked and Info all have this method. The method can be used to set the head sphere for topomaps once and then have it be used as the default head sphere every time a topomap-like figure is created.

No AI was used.

… dict

This allows a user to store a sphere fitted to the participants head
inside the info dict. Whenever we need to draw the head sphere, for
example in topomap figures, we will now use the stored head sphere by
default. This can be overriden with the `sphere` parameter as usual.
@wmvanvliet
wmvanvliet requested a review from larsoner September 16, 2026 08:20
@wmvanvliet

Copy link
Copy Markdown
Contributor Author

The head_sphere is stored inside the FIFF file using a FIFF.FIFFB_SPHERE block with FIFF.FIFF_SPHERE_ORIGIN and FIFF.FIFF_SPHERE_RADIUS tags inside it. This is my solution for the moment, but @larsoner suggested that there may be precedent of storing spherical BEM models in FIFF files and we should look at how that is implemented. So far I haven't found anything that actually stores spherical BEM models though (MNE-Python doesn't support this, perhaps we should add that at some point). I asked Lauri and he said that maybe mrilab can store a spherical BEM model...

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wmvanvliet updated writing code to use existing / corrected constants and updated a tutorial. Feel free to merge if you're happy!

…d-sphere

* commit '0311e444b0450ce9d2b2b304cebe7d5343533357':
  Fix static doc viewing in IDEs (mne-tools#14195)
  Fix COLA for odd sizes (mne-tools#14312)
  add type hints to mne/_fiff/ module (mne-tools#14278)
  ENH: wire the JupyterLite build into the docs (JupyterLite split 5/5) (mne-tools#14157)
  MAINT: Update pre-commit hook versions (mne-tools#14306)
  Small documentation fix for "Frequency and time-frequency sensor analysis" tutorial (mne-tools#14304)
  FIX: don't mutate cached ICA sources in plot_sources properties (mne-tools#14303)
  Fix bug with lite backend closing (mne-tools#14302)
  Fix for NumPy eig change [circle deploy] (mne-tools#14300)
  No PyQt5 [circle deploy] [skip azp] [skip actions]
  ENH: add the JupyterLite notebook setup cell (JupyterLite split 4/5) (mne-tools#14150)
  FIX: Ver [circle deploy] [skip azp] [skip actions]
  Hotfix
  fix EDF round-trip (mne-tools#14296)
  Brain GUI modernization (Phase 7) (mne-tools#14270)
  Fix bug with SciPy 1.18.0 EEGLAB reading (mne-tools#14293)
  remove plotting abs as the defauls for plotting volumetric (mne-tools#13989)
  Coregistration GUI modernisation (phase 4) (mne-tools#14285)
  Dipole GUI interactivity and visual enhancements (phase 2) (mne-tools#14291)
@wmvanvliet

Copy link
Copy Markdown
Contributor Author

You also added the full BEM model instead of just the sphere. Is that based on how mrilab does it?

@wmvanvliet

Copy link
Copy Markdown
Contributor Author

Mocking a full BEM model instead of just adding a FIFFB_SPHERE block is more complicated. What do we gain by it? Compatibility with something?

@larsoner

Copy link
Copy Markdown
Member

The idea is it's easier to reuse existing constants for something that already exists than it is to define a new constant for something very similar. There is already a way to specify a head sphere radius and center, so why not reuse it, even if it in theory allows specifying other stuff (that we don't and probably won't use).

Comment thread mne/_fiff/constants.py
FIFF.FIFFV_COND_MODEL_UNKNOWN = 0
FIFF.FIFFV_COND_MODEL_SPHERE = 1 # Spherically symmetric
FIFF.FIFFV_COND_MODEL_BEM_HOMOG = 2 # Homogeneous BEM model (single layer)
FIFF.FIFFV_COND_MODEL_BEM = 3 # Multilayer BEM model

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two constants are the only "full bem" part, the rest is all spherically symmetric model

@wmvanvliet

Copy link
Copy Markdown
Contributor Author

Ah, now I understand. FIFF_SPHERE_RADIUS was part of _fiff.constants.py, so I though we could just use that. But it was never actually an existing FIFF constant, was it?

@wmvanvliet
wmvanvliet merged commit 2ceb25b into mne-tools:main Sep 17, 2026
26 checks passed
@larsoner

Copy link
Copy Markdown
Member

But it was never actually an existing FIFF constant, was it?

Correct. The number was being used for something else. Not sure why we had it that way...

larsoner added a commit to ttaiv/mne-python that referenced this pull request Sep 21, 2026
* upstream/main:
  FIX: Restore bads when interpolate_bridged_electrodes raises for bad_limit (mne-tools#14320)
  BUG: Fix fNIRS `interpolate_bads` on `Epochs` (mne-tools#14323)
  [dependabot]: Bump the actions group with 3 updates (mne-tools#14324)
  MAINT: Update pre-commit hook versions (mne-tools#14322)
  Fully populate docstrings (mne-tools#14316)
  Add `set_head_sphere` method to store head outline in info (mne-tools#14313)

# Conflicts:
#	mne/minimum_norm/inverse.py
@wmvanvliet
wmvanvliet deleted the info-head-sphere branch November 25, 2026 10:09
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.

Store head sphere in the info dictionary

2 participants