Skip to content

Use weighted cHPI coils during position fitting#14034

Merged
larsoner merged 4 commits into
mne-tools:mainfrom
larsoner:chpiw
Jul 15, 2026
Merged

Use weighted cHPI coils during position fitting#14034
larsoner merged 4 commits into
mne-tools:mainfrom
larsoner:chpiw

Conversation

@larsoner

@larsoner larsoner commented Jul 8, 2026

Copy link
Copy Markdown
Member

Closes #11330

This turned out to way simpler than I realized:

  1. Use a linear ramp from gof_limit to 1.
  2. Combine this with the dist_limit coil goodness estimate
  3. Pass these weights to our quat fitting function, which already supports weights

Implementation drafted with Opus 4.8 but I edited and vouch for all code.

Adapting the minimal example from the linked issue (data available there):

Minimial code
import mne
raw_file = 'te01a1.fif'
raw = mne.io.read_raw_fif(raw_file)
chpi_amps = mne.chpi.compute_chpi_amplitudes(raw, t_step_min=0.25, t_window=0.5)
chpi_locs = mne.chpi.compute_chpi_locs(raw.info, chpi_amps)
head_pos = mne.chpi.compute_head_pos(raw.info, chpi_locs, weighted=False)
mne.viz.plot_head_positions(head_pos)
head_pos = mne.chpi.compute_head_pos(raw.info, chpi_locs, weighted=True)
mne.viz.plot_head_positions(head_pos)
weighted=False weighted=True
image image

@larsoner

Copy link
Copy Markdown
Member Author

cc @SeungCheolBaek did you want to try this?

@larsoner larsoner added this to the 1.13 milestone Jul 14, 2026
@SeungCheolBaek

Copy link
Copy Markdown

cc @SeungCheolBaek did you want to try this?

Wow, great! Thanks for working on this problem.

I'd be nice if I can try this.

But this functionality has not implemented in the current dev. version (1.13), right?
Because I couldn't find the weighted argument in the mne.chpi.compute_head_pos.

Thanks for letting me know about this!

@larsoner

Copy link
Copy Markdown
Member Author

Correct, it hasn't been merged into main or released yet. You should be able to do something like pip install "mne @ https://github.com/larsoner/mne-python/archive/refs/heads/chpiw.zip" and it should install this branch directly to test it out.

@SeungCheolBaek

Copy link
Copy Markdown

Correct, it hasn't been merged into main or released yet. You should be able to do something like pip install "mne @ https://github.com/larsoner/mne-python/archive/refs/heads/chpiw.zip" and it should install this branch directly to test it out.

I've just tried it out, and it seems like it works pretty well!
Thanks again for introducing this to me :)

I hope it will be implemented in stable MNE versions soon!

@larsoner
larsoner merged commit 8f3e8b4 into mne-tools:main Jul 15, 2026
29 checks passed
@larsoner
larsoner deleted the chpiw branch July 15, 2026 11:53
@larsoner

Copy link
Copy Markdown
Member Author

Okay great, thanks for testing!

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.

unstable estimation of the head position based on the HPI coils

2 participants