Skip to content

ENH: Support EpochsSpectrum in concatenate_epochs - #14564

Open
ishaaaan17 wants to merge 5 commits into
mne-tools:mainfrom
ishaaaan17:feat/concatenate-epochs-spectrum
Open

ishaaaan17 wants to merge 5 commits into
mne-tools:mainfrom
ishaaaan17:feat/concatenate-epochs-spectrum

Conversation

@ishaaaan17

@ishaaaan17 ishaaaan17 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Reference issue (if any)

Towards #13191. This picks up the EpochsSpectrum work left in #13748.

What does this implement/fix?

mne.concatenate_epochs() can now combine EpochsSpectrum objects from different runs. Events, selection, drop logs, and metadata are handled by the same logic that is already used for epochs. It also checks that the spectra match in frequencies, method, dimensions, data type, and weights before combining them.

Additional information

Tests are added in the existing epochs and spectrum test files. On the final commit, those two files gave 245 passed, 5 skipped, and 3 expected failures when I ran them locally.

I used GPT-6.2 Astra in Codex for help with the implementation and the tests. I have verified the changes and the test results myself.

autofix-ci Bot and others added 2 commits November 18, 2026 18:51
- Separate spectrum and standard epochs initialization to avoid None typing on tmax.
- Guard events overflow indexing when events is None.
- Credit Aman Srivastava as co-author for EpochsSpectrum concatenation in changelog.

Co-authored-by: Aman Srivastava <amansri345@gmail.com>
@ishaaaan17
ishaaaan17 force-pushed the feat/concatenate-epochs-spectrum branch from 6e3a2bc to 19df1af Compare November 26, 2026 00:03

@tsbinns tsbinns left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for updating the test. Just two things I missed before.

Comment thread mne/epochs.py Resolved
Comment thread mne/epochs.py
raw_sfreq = out._raw_sfreq
if spectrum:
baseline = tmin = tmax = raw_sfreq = None
shift = len(out.freqs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Defining a shift value for events here is tricky. I don't see a "correct" value, but in most cases this will probably be an offset of much fewer samples than the 'epoch end + 10 s' shift set for Epochs inputs. This could also lead to the first event of a concatenated object "starting" before the last one from the previous object should have ended.

I don't think there's anything in MNE that would complain about this. @drammock or @larsoner, do you think this might cause issues when working with the concatenated object, or it's irrelevant?

This branch has not been deployed

No deployments
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.

2 participants