Skip to content

mne.concatenate_raws(raws) wrongly concatenates raws if the order of the channel names varies across raws #11633

Closed

Description

@moritz-gerster

Description of the problem

For a description of the problem check this pdf.

mne.concatenate_raws(raws) wrongly concatenates raws if the order of the channel names varies across raws.

In my opinion, this is a huge bug that I noticed only accidentally. In my data, I add reference channels when they are missing and the index of this channel varies across my raws. In other words, the order of raw.ch_names is not consistent across my raws.

We should probably prepare the raws within mne.concatenate_raws with

for raw in raws:
    raw.reorder_channels(sorted(raw.ch_names))

I don't think we can expect all mne users to know this and do it themselves. I would have never thought that this function does not check the names of the channels it concatenates.

Steps to reproduce

See jupyter-notebook pdf above.

Link to data

No response

Expected results

mne.concatenate_raws reads in the channel names and only concatenates "ch1" of raw1 with "ch1" of raw2.

Actual results

mne.concatenate_raws concatenates raw1.ch_names[0] with raw2.ch_names[0] without checking whether raw1.ch_names[0] == raw2.ch_names[0].

Additional information

Platform: macOS-11.7.3-x86_64-i386-64bit
Python: 3.11.0 | packaged by conda-forge | (main, Jan 15 2023, 05:44:48) [Clang 14.0.6 ]
Executable: /opt/anaconda3/envs/bids_neu/bin/python
CPU: i386: 8 cores
Memory: 16.0 GB

mne: 1.3.0
numpy: 1.23.4 {OpenBLAS 0.3.20 with 4 threads}
scipy: 1.10.0
matplotlib: 3.7.0 {backend=module://matplotlib_inline.backend_inline}

sklearn: 1.2.1
numba: Not found
nibabel: 5.0.1
nilearn: Not found
dipy: Not found
openmeeg: Not found
cupy: Not found
pandas: 1.5.3
pyvista: Not found
pyvistaqt: Not found
ipyvtklink: Not found
vtk: Not found
qtpy: Not found
ipympl: Not found
pyqtgraph: Not found
pooch: v1.6.0

mne_bids: 0.12
mne_nirs: Not found
mne_features: Not found
mne_qt_browser: Not found
mne_connectivity: Not found
mne_icalabel: Not found

Activity

  1. larsoner commented on Apr 17, 2023

    @larsoner
    Member

    We should probably prepare the raws within mne.concatenate_raws with

    Sure this seems reasonable, can you open a PR for this?

  2. added this to the 1.4 milestone on Apr 17, 2023
  3. moritz-gerster commented on Apr 20, 2023

    @moritz-gerster
    ContributorAuthor

    Sure this seems reasonable, can you open a PR for this?

    @larsoner done 👍

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions