diff --git a/doc/changes/devel/13263.newfeature.rst b/doc/changes/devel/13263.newfeature.rst new file mode 100644 index 00000000000..7d4db015b69 --- /dev/null +++ b/doc/changes/devel/13263.newfeature.rst @@ -0,0 +1 @@ +It is now possible to concatenate raw objects with :func:`mne.concatenate_raws` as long as they inherit from :class:`~mne.io.BaseRaw`, even if their specific types differ (e.g., :class:`~mne.io.Raw` and :class:`~mne.io.RawArray`), by `Clemens Brunner`_. \ No newline at end of file diff --git a/mne/io/base.py b/mne/io/base.py index c5808726264..f1b90ae152a 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -3104,8 +3104,9 @@ def _write_raw_buffer(fid, buf, cals, fmt): def _check_raw_compatibility(raw): """Ensure all instances of Raw have compatible parameters.""" for ri in range(1, len(raw)): - if not isinstance(raw[ri], type(raw[0])): - raise ValueError(f"raw[{ri}] type must match") + if not isinstance(raw[ri], BaseRaw): + if type(raw[ri]) is not type(raw[0]): + raise ValueError(f"raw[{ri}] type must match") for key in ("nchan", "sfreq"): a, b = raw[ri].info[key], raw[0].info[key] if a != b: diff --git a/mne/io/fiff/tests/test_raw_fiff.py b/mne/io/fiff/tests/test_raw_fiff.py index 3ae49189161..8fe7ab98a4c 100644 --- a/mne/io/fiff/tests/test_raw_fiff.py +++ b/mne/io/fiff/tests/test_raw_fiff.py @@ -487,6 +487,22 @@ def test_concatenate_raws_order(): assert np.all(ch0 == 0) +def test_concatenate_raws_different_subtypes(tmp_path): + """Test concatenating raws with different subtypes.""" + sfreq = 100.0 + ch_names = ["EEG 001", "EEG 002"] + ch_types = ["eeg"] * 2 + info = create_info(ch_names=ch_names, sfreq=sfreq, ch_types=ch_types) + data = np.random.randn(len(ch_names), 1000) + + raw_array = RawArray(data, info) + raw_array.save(tmp_path / "temp_raw.fif", overwrite=True) + raw_fiff = read_raw_fif(tmp_path / "temp_raw.fif", preload=True) + + with pytest.warns(RuntimeWarning, match="raw files do not all have the same"): + concatenate_raws([raw_fiff, raw_array]) + + @testing.requires_testing_data @pytest.mark.parametrize( "mod",