Skip to content

No on_missing in mne.channels.combine_channels #12591

Closed

Description

@toddrjen

Description of the problem

When using mne.channels.combine_channels on mne.Epochs or mne.EpochsArray objects with missing channels where the user had previously used on_missing='ignore' or on_missing='warn' it will raise an exception. There does not appear to be a way within mne.channels.combine_channels to avoid the exception.

Steps to reproduce

import mne

sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = sample_data_folder / "MEG" / "sample" / "sample_audvis_raw.fif"
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False).crop(tmax=60)

events = mne.find_events(raw, stim_channel="STI 014")

# event ID 1000 does not exist
event_id = [5, 1000]

epochs = mne.Epochs(raw, events=events, event_id=event_id, on_missing='warn')

mne.channels.combine_channels(inst=epochs, groups={'test': [0, 1]})

Link to data

No response

Expected results

Ideally the previous use of on_missing='ignore' or on_missing='warn' would be stored and used again for constructing the new mne.EpochsArray object, but at least having an on_missing argument in mne.channels.combine_channels would allow this problem to be avoided.

Actual results

The following exception is raised, with apparently no way to avoid it other than manually removing the unused events:

ValueError: No matching events found for 1000 (event id 1000)

Additional information

Platform Linux-5.15.0-105-generic-x86_64-with-glibc2.31
Python 3.10.11 (main, May 16 2023, 00:28:57) [GCC 11.2.0]
Executable /home/toddrjen/bin/anaconda3/envs/mne/bin/python3
CPU x86_64 (16 cores)
Memory 31.2 GB

Core
├☑ mne 1.7.0 (latest release)
├☑ numpy 1.26.4 (OpenBLAS 0.3.23.dev with 16 threads)
├☑ scipy 1.13.0
└☑ matplotlib 3.8.4 (backend=TkAgg)

Numerical (optional)
├☑ sklearn 1.4.2
├☑ numba 0.59.1
├☑ nibabel 5.2.1
├☑ pandas 2.2.1
└☐ unavailable nilearn, dipy, openmeeg, cupy, h5io, h5py

Visualization (optional)
├☑ ipympl 0.9.4
├☑ ipywidgets 8.1.2
└☐ unavailable pyvista, pyvistaqt, vtk, qtpy, pyqtgraph, mne-qt-browser, trame_client, trame_server, trame_vtk, trame_vuetify

Ecosystem (optional)
└☐ unavailable mne-bids, mne-nirs, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline, neo, eeglabio, edfio, mffpy, pybv

Activity

  1. welcome commented on Apr 30, 2024

    @welcome

    Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴

  2. sappelhoff commented on Jul 27, 2024

    @sappelhoff
    Member

    this is where on_missing would need to be added:

    elif isinstance(inst, BaseEpochs):
    combined_inst = EpochsArray(
    new_data,
    info,
    events=inst.events,
    event_id=inst.event_id,
    tmin=inst.times[0],
    baseline=inst.baseline,
    )

  3. added this to the 1.9 milestone on Jul 27, 2024
  4. modified the milestones: 1.9, 1.10 on Dec 9, 2024
  5. removed this from the 1.10 milestone on Jun 26, 2025
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