Skip to content

Add more options to sphere argument in topomap plots.#13400

Merged
drammock merged 9 commits intomne-tools:mainfrom
wmvanvliet:fit-sphere
Aug 29, 2025
Merged

Add more options to sphere argument in topomap plots.#13400
drammock merged 9 commits intomne-tools:mainfrom
wmvanvliet:fit-sphere

Conversation

@wmvanvliet
Copy link
Copy Markdown
Contributor

@wmvanvliet wmvanvliet commented Aug 28, 2025

Fixes #13399

This PR adds some more options to the sphere argument of plot_sensors. With this you can control what digitized points the sphere is fitted to. Specifically, it now passes the sphere string on to mne.bem.fit_sphere_to_headshape as dig_kinds, so supports all the options for that function. For example, to fix #13399, one could do: raw.plot_sensors(ch_type="eeg", sphere="eeg") to fit the sphere to just the EEG digitization points.

In addition, the "auto" setting has been made a bit more clever. By default, it tries to fit the sphere with just the "extra" digitization points just like before. The new thing is that if it produces a weird fit that generates a warning about an unlikely head position, it will now try again with all digitization points. This also fixes #13399.

Copy link
Copy Markdown
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

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

changes look good. Can you touch tutorials/intro/40_sensor_locations.py so we can make sure none of the figures have changed? I don't think the tutorial needs a new section, as the docstring is pretty clear and thorough already. Maybe just an extra sentence in the sidebar box here: https://mne.tools/dev/auto_tutorials/intro/40_sensor_locations.html#plotting-2d-sensor-locations-like-eeglab saying "see the docstring of plot_sensors for more info about the sphere parameter"

@wmvanvliet
Copy link
Copy Markdown
Contributor Author

I changed the line wrapping in the tutorial to our new line length. Docs look good to me!

@drammock drammock merged commit 2881652 into mne-tools:main Aug 29, 2025
32 checks passed
@drammock
Copy link
Copy Markdown
Member

Thanks @wmvanvliet!

Comment on lines +1097 to +1103
if dig_kinds == "auto":
logger.info(msg)
logger.info("Trying again with all digitization points.")
return _fit_sphere_to_headshape(
info, dig_kinds=("extra", "eeg", "hpi", "cardinal"), verbose=verbose
)
warn(msg)
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.

Technically this is a backward incompatible change, so needs to be considered a bugfix with an entry in the bug section. For that, we'd want to be fairly certain it's better in 95%+ of cases. For example, anyone using the default origin="auto" in maxwell_filter who formerly got a warning will now have their origin change in 1.11 (assuming they have extra dig points). I am not sure we want to do this... but maybe it's okay?

@wmvanvliet WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I hadn't considered non-visualization cases like maxwell_filter. No, we don't want to change default behavior like that, even though I believe it will be better in almost all cases. Let's revert for now.

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.

Bad EEG topomaps for ds000117

3 participants