Skip to content

BUG: One layer BEM construction fails for current ANTS6-0Months3T template #14468

Open

Description

@nordme

Description of the problem

Our current ANTS templates ship with a three layer BEM. If you want to make a 1-layer BEM for MEG solutions, you should be able to make one, but calling mne.make_bem_model with a freshly installed template throws an error about triangle ordering.

Steps to reproduce

import mne
s_dir = mne.datasets.default_path()
mne.datasets.fetch_infant_template("6mo", subjects_dir=s_dir)
subject="ANTS6-0Months3T"
bem_one_layer = mne.make_bem_model(subject, conductivity=[0.3,], subjects_dir=sdir)

Link to data

No response

Expected results

The function should complete successfully, returning a one-layer BEM.

Actual results

Traceback (most recent call last):
File "/Users/nordme/miniconda3/envs/dev_2026/lib/python3.14/site-packages/IPython/core/interactiveshell.py", line 3775, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1, in
bem_one_layer = mne.make_bem_model(subject, conductivity=[0.3,], subjects_dir=sdir)
File "", line 12, in make_bem_model
File "/Users/nordme/github/mne-python/mne/bem.py", line 716, in make_bem_model
surfaces = _surfaces_to_bem(surfaces, ids, conductivity, ico)
File "/Users/nordme/github/mne-python/mne/bem.py", line 617, in _surfaces_to_bem
surfs[si] = _ico_downsample(surf, ico)
~~~~~~~~~~~~~~~^^^^^^^^^^^
File "/Users/nordme/github/mne-python/mne/bem.py", line 489, in _ico_downsample
raise RuntimeError(
...<2 lines>...
)
RuntimeError: The source surface has a matching number of triangles but ordering is wrong

Additional information

mne sys_info
Platform             Linux-6.8.0-147-generic-x86_64-with-glibc2.39 (X11)
Python               3.14.6 | packaged by conda-forge | (main, Jul 24 2026, 16:09:24) [GCC 14.3.0]
Executable           /home/erica/miniconda3/envs/bids_dev26/bin/python3.14
CPU                  AMD Ryzen 9 3900X 12-Core Processor (24 cores)
Memory               62.7 GiB

Core
├:ballot_box_with_check: mne               1.14.0.dev113+g0616647f5 (development, latest release is 1.13.2)
├:ballot_box_with_check: numpy             2.4.6 (OpenBLAS 0.3.33 with 12 threads via pthreads)
├:ballot_box_with_check: scipy             1.18.0
└:ballot_box_with_check: matplotlib        3.11.1 (backend=qtagg)

Numerical (optional)
├:ballot_box_with_check: scikit-learn      1.9.0
├:ballot_box_with_check: threadpoolctl     3.6.0
├:ballot_box_with_check: numba             0.66.0
├:ballot_box_with_check: nibabel           5.4.2
├:ballot_box_with_check: nilearn           0.13.1
├:ballot_box_with_check: dipy              1.12.1
├:ballot_box_with_check: openmeeg          2.5.16
├:ballot_box_with_check: pandas            3.0.3
├:ballot_box_with_check: h5io              0.2.5
├:ballot_box_with_check: h5py              3.16.0
└☐ unavailable       python-picard, jamica, cupy

Visualization (optional)
├:ballot_box_with_check: pyvista           0.48.4 (OpenGL 4.6 (Core Profile) Mesa 25.2.8-0ubuntu0.24.04.4 via AMD Radeon RX 570 Series (radeonsi, polaris10, ACO, DRM 3.57, 6.8.0-147-generic))
├:ballot_box_with_check: pyvistaqt         0.12.0
├:ballot_box_with_check: vtk               9.6.2
├:ballot_box_with_check: qtpy              2.4.3 (PySide6=6.11.1)
├:ballot_box_with_check: pyqtgraph         0.14.0
├:ballot_box_with_check: mne-qt-browser    0.7.5
├:ballot_box_with_check: ipywidgets        8.1.8
├:ballot_box_with_check: trame             3.13.2
├:ballot_box_with_check: trame_client      3.13.2
├:ballot_box_with_check: trame_server      3.12.5
├:ballot_box_with_check: trame_vtk         2.11.14
├:ballot_box_with_check: trame_vuetify     3.2.5
└☐ unavailable       ipympl, trame_pyvista

Ecosystem (optional)
├:ballot_box_with_check: mne-bids          0.21.0.dev11+g085e309b9.d20261020
├:ballot_box_with_check: mne-nirs          0.7.3
├:ballot_box_with_check: mne-connectivity  0.8.1
├:ballot_box_with_check: mne-icalabel      0.9.0
├:ballot_box_with_check: mne-bids-pipeline 1.11.0.dev86+ge2a34cf44
├:ballot_box_with_check: autoreject        0.4.4
├:ballot_box_with_check: neo               0.14.5
├:ballot_box_with_check: eeglabio          0.1.3
├:ballot_box_with_check: edfio             0.4.14
├:ballot_box_with_check: curryreader       0.1.2
├:ballot_box_with_check: mffpy             0.11.0
├:ballot_box_with_check: pybv              0.8.1
├:ballot_box_with_check: pymef             1.4.8
├:ballot_box_with_check: antio             0.7.1
├:ballot_box_with_check: defusedxml        0.7.1
└☐ unavailable       mne-features

Activity

  1. sruthisureshkumar-arch commented on Nov 1, 2026

    @sruthisureshkumar-arch
    Contributor

    Hi! I'd like to work on this bug. I reproduced this on the current dev version and found that inner_skull.surf already has 5120 triangles (ico 4), and make_bem_model(..., ico=None) works fine, so only the default ico=4 path fails. This is because _ico_downsample checks the triangle ordering against MNE's icosahedron even when no downsampling is needed. I'm thinking that if the surface is already at the requested grade, we could return it as-is and skip the ordering check. Thank you!!

  2. larsoner commented on Nov 2, 2026

    @larsoner
    Member

    I think an even better fix, if possible, would be to fix the datasets such that the meshes are decimated properly. There might be places where the ico=4 decimation is assumed to be in the canonical order, and short-circuiting would thus lead to an incorrect result

  3. drammock commented on Nov 2, 2026

    @drammock
    Member

    the data comes from here: https://github.com/christian-oreilly/infant_template_paper
    So fixes to the dataset need to go in that repo, or we'll need to redistribute the fixed dataset from a fork (or incorporate into https://github.com/mne-tools/mne-data/releases)

  4. nordme commented on Nov 4, 2026

    @nordme
    ContributorAuthor

    @larsoner @drammock @sruthisureshkumar-arch I am working on creating the properly ordered surfaces and bem models (rerunning watershed, manually repairing the watershed surfaces, then decimating). 6mo and 12mo are finished; the rest are in progress. It's not straightforward because some of the T1 images need renormalization in order for the watershed algorithm to run remotely correctly -- some of the results are so wacky they can't even be manually repaired as is. See the pic below -- that's supposed to be the inner skull and the outer skull surfaces, lol! So, it's going to take me a bit to get all them straightened out.

    Image

    Meanwhile, thoughts on the ideal plan for distributing the fixed bems once I'm done making them?

  5. larsoner commented on Nov 5, 2026

    @larsoner
    Member

    A PR to the upstream repo https://github.com/christian-oreilly/infant_template_paper first would be good. Then a new release could be cut there. Let's only resort to mne-data if we can't upstream the changes

  6. scott-huberty commented on Nov 5, 2026

    @scott-huberty
    Contributor

    Christian was my PhD mentor and we still collaborate on some projects. If you don't receive a response to the PR LMK. I'm not sure how often he is on GitHub these days!

  7. sruthisureshkumar-arch commented on Nov 5, 2026

    @sruthisureshkumar-arch
    Contributor

    Thank you @nordme for taking on the surface regeneration! I'd be happy to test the fixed surfaces with make_bem_model(..., ico=4) once some are ready, since I already have the repro script. Also, once there's a new upstream release, I could do the MNE-side PR: update the release URL, the md5 hashes, and the file manifests in mne/datasets/_infant/

  8. nordme commented on Nov 5, 2026

    @nordme
    ContributorAuthor

    Thanks @scott-huberty and thanks @sruthisureshkumar-arch ! I will ping you once I've got the full set. 😊

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions