Skip to content

Allow concatenating BaseRaw objects #13263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cbrnr
Copy link
Contributor

@cbrnr cbrnr commented May 27, 2025

As reported in this forum post, mne.concatenate_raws() only works if all objects share the exact same type. In particular, this means that it is not possible to concatenate Raw (an alias for RawFIF) and RawArray objects, and other types like RawEDF, RawEEGLAB, etc. do not work either. However, since all concrete types inherit from BaseRaw, I think we could relax the compatibility check accordingly.

The following example fails on main, but works on this branch:

import numpy as np

import mne

sfreq = 100.0
ch_names = ["EEG 001", "EEG 002"]
ch_types = ["eeg"] * 2
info = mne.create_info(ch_names=ch_names, sfreq=sfreq, ch_types=ch_types)
data = np.random.randn(len(ch_names), 1000)

raw_array = mne.io.RawArray(data, info)
raw_array.save("temp_raw.fif", overwrite=True)
raw_fiff = mne.io.read_raw_fif("temp_raw.fif", preload=True)

mne.concatenate_raws([raw_fiff, raw_array])

@cbrnr cbrnr force-pushed the concatenate-baseraw branch from d7aa4dd to b656479 Compare May 27, 2025 06:48
@hoechenberger
Copy link
Member

I didn't review any of the changes and don't know if there's any side effects to be expected; but purely from a user's POV, I'd say we should definitely try to support this

Copy link
Member

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think we should support this. Potential issues could arise from concatenating Raw types that support different attributes. For example, the BrainVision Raw supports impedances, but other Raws might not.

@larsoner
Copy link
Member

At a bare minimum we would have to ensure all data are preloaded. And as @sappelhoff points out to keep things simple the resulting class should probably be RawArray since IIRC it doesn't have any extra attributes like impedance and such. (We could later maybe think about how to combine/keep them but I'd rather instead move toward removing them entirely.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants