diff --git a/doc/changes/dev/14188.bugfix.rst b/doc/changes/dev/14188.bugfix.rst new file mode 100644 index 00000000000..f18e7a43e3a --- /dev/null +++ b/doc/changes/dev/14188.bugfix.rst @@ -0,0 +1 @@ +Fix :func:`mne.concatenate_epochs` failing on epochs cropped after baseline correction, by `Kalle Makela`_. diff --git a/mne/epochs.py b/mne/epochs.py index 04f55977a61..0beb7a1da1d 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -4907,7 +4907,7 @@ def concatenate_epochs( events=events, event_id=event_id, tmin=tmin, - baseline=baseline, + baseline=None, selection=selection, drop_log=drop_log, proj=False, @@ -4915,6 +4915,8 @@ def concatenate_epochs( metadata=metadata, raw_sfreq=raw_sfreq, ) + # Don't reapply baseline correction. Restore the original baseline metadata. + out.baseline = baseline out.drop_bad() return out diff --git a/mne/tests/test_epochs.py b/mne/tests/test_epochs.py index f0636c019d5..922ee4e4d8a 100644 --- a/mne/tests/test_epochs.py +++ b/mne/tests/test_epochs.py @@ -3867,6 +3867,17 @@ def test_concatenate_epochs(): concatenate_epochs([epochs, epochs2], add_offset=True) +def test_concatenate_epochs_cropped_baseline(): + """Test concatenating epochs cropped after baseline correction.""" + data = np.arange(21.0)[np.newaxis, np.newaxis] + epochs = EpochsArray(data, create_info(["x"], 10, "eeg"), tmin=-1) + epochs.apply_baseline((-1, 0)).crop(0, 1) + expected = epochs.get_data() + epochs_conc = concatenate_epochs([epochs]) + assert epochs_conc.baseline == (-1.0, 0.0) + assert_allclose(epochs_conc.get_data(), expected) + + @pytest.mark.slowtest def test_concatenate_epochs_large(): """Test concatenating epochs on large data."""