Repository navigation
Description
Description of the problem
Working my way slowly through a set of 180 coregistrations 😄, I've been test driving the dev versions of mne.coreg quite a bit. I do want to say, on the whole, it's looking great and working fast, so thanks @payamsash and all for the good work! With that said, there are a couple small issues I've come across.
Notably, I am sometimes, but not always, getting a crash when trying an initial fiducial fit to one of the ANTS template anats after loading in a new dig. I don't have a reliable reproduction MWE yet because I haven't been able to figure out what circumstances are differentiating the successful and crashing fid fits, but I wanted to throw this error up here so folks know about it since I know the coreg gui is under active development.
I just recently started hitting this issue, so I'll work on narrowing down an example that more reliably reproduces the behavior.
Steps to reproduce
mne.gui.coregistration(scale_by_distance=False, fullscreen=False, show=True)
# 1. Load an ANTS template.
# 2. Load an infant MEG file with dig.
# So far, the first fit after launching the gui has always worked
# 3. Click the "Fit fiducials" button.
# 4. Reset parameters.
# 5. Load a new infant MEG file with dig.
# After loading a new dig, fid fit will often succeed, but sometimes fail
# 6. Click the "Fit fiducials" button.Link to data
No response
Expected results
I expect the fiducials to fit and the gui to not crash.
Actual results
Sometimes the gui freezes.
Here's the traceback from my terminal.
`IndexError Traceback (most recent call last)
File ~/repos/mne-python/mne/gui/_coreg.py:1508, in CoregistrationUI._fit_fiducials(self)
1506 def _fit_fiducials(self):
1507 with self._lock(scale_mode=True):
-> 1508 self._fits_fiducials()
File ~/repos/mne-python/mne/gui/_coreg.py:1513, in CoregistrationUI._fits_fiducials(self)
1511 with self._lock(params=True, fitting=True):
1512 start = time.time()
-> 1513 self.coreg.fit_fiducials(
1514 lpa_weight=self._lpa_weight,
1515 nasion_weight=self._nasion_weight,
1516 rpa_weight=self._rpa_weight,
1517 verbose=self._verbose,
1518 )
1519 end = time.time()
1520 self._display_message(
1521 f"Fitting fiducials finished in {end - start:.2f} seconds."
1522 )
File :12, in fit_fiducials(self, lpa_weight, nasion_weight, rpa_weight, verbose)
File ~/repos/mne-python/mne/coreg.py:1911, in Coregistration.fit_fiducials(self, lpa_weight, nasion_weight, rpa_weight, verbose)
1889 """Find rotation and translation to fit all 3 fiducials.
1890
1891 Parameters
(...) 1908 The modified Coregistration object.
1909 """
1910 logger.info("Aligning using fiducials")
-> 1911 self._log_dig_mri_distance("Start")
1912 n_scale_params = self._n_scale_params
1913 if n_scale_params == 3:
1914 # enforce 1 even for 3-axis here (3 points is not enough)
File ~/repos/mne-python/mne/coreg.py:1869, in Coregistration._log_dig_mri_distance(self, prefix)
1868 def _log_dig_mri_distance(self, prefix):
-> 1869 errs_nearest = self.compute_dig_mri_distances()
1870 logger.info(
1871 f"{prefix} median distance: {np.median(errs_nearest * 1000):6.2f} mm"
1872 )
File ~/repos/mne-python/mne/coreg.py:2175, in Coregistration.compute_dig_mri_distances(self)
2162 """Compute distance between head shape points and MRI skin surface.
2163
2164 Returns
(...) 2171 mne.dig_mri_distances
2172 """
2173 # we don't use dig_mri_distances here because it should be much
2174 # faster to use our already-determined nearest points
-> 2175 hsp_points, mri_points, _ = self._setup_icp(0)
2176 hsp_points = apply_trans(self._head_mri_t, hsp_points)
2177 return np.linalg.norm(mri_points - hsp_points, axis=-1)
File ~/repos/mne-python/mne/coreg.py:1959, in Coregistration._setup_icp(self, n_scale_params)
1957 mri_pts = [np.zeros((0, 3))]
1958 weights = [np.zeros(0)]
-> 1959 if self._has_dig_data and self._hsp_weight > 0: # should be true
1960 head_pts.append(self._filtered_extra_points)
1961 mri_pts.append(
1962 self._processed_high_res_mri_points[
1963 self._nearest_transformed_high_res_mri_idx_hsp
1964 ]
1965 )
File ~/repos/mne-python/mne/coreg.py:1857, in Coregistration._has_dig_data(self)
1853 @Property
1854 def _has_dig_data(self):
1855 return (
1856 self._has_mri_data
-> 1857 and len(self._nearest_transformed_high_res_mri_idx_hsp) > 0
1858 )
File ~/repos/mne-python/mne/coreg.py:1787, in Coregistration._nearest_transformed_high_res_mri_idx_hsp(self)
1784 @Property
1785 def _nearest_transformed_high_res_mri_idx_hsp(self):
1786 return self._nearest_calc.query(
-> 1787 apply_trans(self._head_mri_t, self._filtered_extra_points)
1788 )[1]
File ~/repos/mne-python/mne/coreg.py:1760, in Coregistration._filtered_extra_points(self)
1758 return self._dig_dict["hsp"]
1759 else:
-> 1760 return self._dig_dict["hsp"][self._extra_points_filter]
IndexError: boolean index did not match indexed array along axis 0; size of axis is 175 but size of corresponding boolean axis is 270`
Additional information
~$ mne sys_info
Platform Linux-6.17.0-1033-oem-x86_64-with-glibc2.39 (X11)
Python 3.14.6 | packaged by conda-forge | (main, Jun 12 2026, 08:51:42) [GCC 14.3.0]
Executable /home/nordme/miniconda3/envs/bids_dev26/bin/python3.14
CPU Intel(R) Xeon(R) w5-2455X (24 cores)
Memory 125.4 GiB
Core
├☑ mne 1.14.0.dev85+g5ec89de23 (development, latest release is 1.13.2)
├☑ numpy 2.4.6 (OpenBLAS 0.3.33 with 24 threads via pthreads)
├☑ scipy 1.18.0
└☑ matplotlib 3.11.0 (backend=qtagg)
Numerical (optional)
├☑ scikit-learn 1.8.0
├☑ threadpoolctl 3.6.0
├☑ numba 0.65.1
├☑ nibabel 5.4.2
├☑ nilearn 0.14.0
├☑ dipy 1.12.1
├☑ openmeeg 2.5.16
├☑ pandas 3.0.3
├☑ h5io 0.2.5
├☑ h5py 3.16.0
└☐ unavailable python-picard, jamica, cupy
Visualization (optional)
├☑ pyvista 0.48.4 (OpenGL 4.5.0 NVIDIA 595.99.02 via NVIDIA RTX A400/PCIe/SSE2)
├☑ pyvistaqt 0.12.0
├☑ vtk 9.6.2
├☑ qtpy 2.4.3 (PySide6=6.11.1)
├☑ pyqtgraph 0.14.0
├☑ mne-qt-browser 0.7.5
├☑ ipywidgets 8.1.8
├☑ trame 3.13.2
├☑ trame_client 3.13.2
├☑ trame_server 3.12.5
├☑ trame_vtk 2.11.13
├☑ trame_vuetify 3.2.2
└☐ unavailable ipympl, trame_pyvista
Ecosystem (optional)
├☑ mne-bids 0.21.0.dev6+gcd32e35ff
├☑ mne-nirs 0.7.3
├☑ mne-connectivity 0.8.1
├☑ mne-icalabel 0.9.0
├☑ mne-bids-pipeline 1.11.0.dev84+g51b0df8e9
├☑ autoreject 0.4.4
├☑ neo 0.14.5
├☑ eeglabio 0.1.3
├☑ edfio 0.4.13
├☑ curryreader 0.1.2
├☑ mffpy 0.11.0
├☑ pybv 0.8.1
├☑ pymef 1.4.8
├☑ antio 0.7.0
├☑ defusedxml 0.7.1
└☐ unavailable mne-features
Activity
payamsash commentedon Oct 15, 2026
Thank you @nordme, when you press the "omit" button, it excludes some of the head-shape points (which are far) and saves a mask, but when you load a new recording it swaps the head-shape points but does'nt clear the mask, so if the new file has different number of points, the mask does'nt fit and in the next fit it crashes. You can see that in your error message there are 170 points in the new file but 270 entry mask from previous one.
IndexError: boolean index did not match indexed array along axis 0; size of axis is 175 but size of corresponding boolean axis is 270`
I think we can clear the mask in
Coregistration.set_info(). @larsoner ok for you?larsoner commentedon Oct 15, 2026
Yeah that makes sense!
nordme commentedon Oct 15, 2026
Ah, hsp filtration gets triggered by using the omit button, that makes sense, though I'm pretty sure coreg didn't used to hang on to the old omit mask because that hasn't caused crashes for me in the past. Thanks Payam. I see that I can manually avoid crashes by using the reset button before switching dig files, but I do think that omit masks should clear automatically!
FIX: Reset head shape point omission filter when setting new info (mn…
DOC: Add changelog entries for gh-14463 and gh-14420 [ci skip]