From b656479d092dc79b46116109614e70e6d185e209 Mon Sep 17 00:00:00 2001 From: Clemens Brunner Date: Tue, 27 May 2025 08:48:49 +0200 Subject: [PATCH 1/5] Allow BaseRaw --- mne/io/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/io/base.py b/mne/io/base.py index c5808726264..5e296869c59 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -3104,7 +3104,7 @@ 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])): + if not isinstance(raw[ri], BaseRaw): raise ValueError(f"raw[{ri}] type must match") for key in ("nchan", "sfreq"): a, b = raw[ri].info[key], raw[0].info[key] From 7f8336febb70e49bb8cbbb4539b677f9259997cb Mon Sep 17 00:00:00 2001 From: Clemens Brunner Date: Tue, 27 May 2025 09:00:58 +0200 Subject: [PATCH 2/5] Add changelog entry --- doc/changes/devel/13263.newfeature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changes/devel/13263.newfeature.rst diff --git a/doc/changes/devel/13263.newfeature.rst b/doc/changes/devel/13263.newfeature.rst new file mode 100644 index 00000000000..e7919f861cc --- /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 `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 From eca66ff65bdc4d8ed6aaafd7a38132c84a456aac Mon Sep 17 00:00:00 2001 From: Clemens Brunner Date: Tue, 27 May 2025 09:19:06 +0200 Subject: [PATCH 3/5] Add test --- mne/io/fiff/tests/test_raw_fiff.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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", From 9704c366f6975d6fab56fb69a8e2b0a274271b6f Mon Sep 17 00:00:00 2001 From: Clemens Brunner Date: Tue, 27 May 2025 11:21:14 +0200 Subject: [PATCH 4/5] Fix for non BaseRaw objects --- mne/io/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mne/io/base.py b/mne/io/base.py index 5e296869c59..f1b90ae152a 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -3105,7 +3105,8 @@ 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], BaseRaw): - raise ValueError(f"raw[{ri}] type must match") + 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: From aeb72bd56421c11b2d5dbc2dc9f1a9d67c2de31e Mon Sep 17 00:00:00 2001 From: Clemens Brunner Date: Tue, 27 May 2025 14:26:50 +0200 Subject: [PATCH 5/5] Fix RST --- doc/changes/devel/13263.newfeature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/devel/13263.newfeature.rst b/doc/changes/devel/13263.newfeature.rst index e7919f861cc..7d4db015b69 100644 --- a/doc/changes/devel/13263.newfeature.rst +++ b/doc/changes/devel/13263.newfeature.rst @@ -1 +1 @@ -It is now possible to concatenate raw objects with :func:`mne.concatenate_raws` as long as they inherit from `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 +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