Skip to content

The lack of custom DIG montage is not correctly identified #12011

Open

Description

@mscheltienne

Description of the problem

I have a recording MEG + 10 EEG where a .set_montage("standard_1020") fails with:

Traceback (most recent call last):

  Cell In[3], line 1
    epochs.set_montage("standard_1020")

  File <decorator-gen-25>:12 in set_montage

  File ~/git/mscheltienne/mne-python/mne/_fiff/meas_info.py:419 in set_montage
    _set_montage(info, montage, match_case, match_alias, on_missing)

  File ~/git/mscheltienne/mne-python/mne/channels/montage.py:1311 in _set_montage
    "coord_frame": info["dig"].pop()["coord_frame"],

IndexError: pop from empty list

It looks like it's due to custom_eeg_ref_dig being set to True here:

# keep reference location from EEG-like channels if they
# already exist and are all the same.
# Note: ref position is an empty list for fieldtrip data
if len(ref_pos) and ref_pos[0].any() and (ref_pos[0] == ref_pos).all():
eeg_ref_pos = ref_pos[0]
# since we have an EEG reference position, we have
# to add it into the info['dig'] as EEG000
custom_eeg_ref_dig = True
else:
refs = set(ch_pos) & {"EEG000", "REF"}
assert len(refs) <= 1
eeg_ref_pos = np.zeros(3) if not refs else ch_pos.pop(refs.pop())
custom_eeg_ref_dig = False
del ref_pos

Assuming the recording did have an electrode digitization for the EEG electrodes, but we actually skipped it. The ref_pos array is:

array([[1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.]])

I'll try to get some ER recordings with/without EEG channels enabled and with/without digitization to confirm on our MEG.

Activity

  1. Famous077 commented on Feb 25, 2026

    @Famous077
    Contributor

    Hi @mscheltienne I'd like to work on this bug. The condition ref_pos[0].any() appears
    to incorrectly identify placeholder values [1., 0., 0.] as valid
    digitization positions. I'll investigate the fix in montage.py and
    open a PR shortly.

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