Skip to content

ENH: Support concatenate_epochs() for EpochsTFR#13745

Open
aman-coder03 wants to merge 4 commits intomne-tools:mainfrom
aman-coder03:enh-concatenate-epochstfr
Open

ENH: Support concatenate_epochs() for EpochsTFR#13745
aman-coder03 wants to merge 4 commits intomne-tools:mainfrom
aman-coder03:enh-concatenate-epochstfr

Conversation

@aman-coder03
Copy link
Copy Markdown
Contributor

Reference issue (if any)

towards #13191

What does this implement/fix?

concatenate_epochs() now works with EpochsTFR objects. Before this, passing a list of EpochsTFR instances would just crash with a TypeError because EpochsTFR isn't a subclass of BaseEpochs

fix adds a helper function _concatenate_epochs_tfr() in mne/epochs.pythat takes care of stacking the data, merging event IDs, offsetting event timestamps, and handling metadata, basically the same things the existing concatenation does for regular epochs
concatenate_epochs() now checks if it's dealing with EpochsTFR objects and routes to this helper automatically
tests are added in mne/time_frequency/tests/test_tfr.py

Additional information

task 1 of 3 from #13191 (as discussed with @drammock)
tasks 2 and 3(EpochsSpectrum support and allowing EpochsTFR to accept RawTFR as input) will come in follow up PRs

@aman-coder03 aman-coder03 requested a review from larsoner as a code owner March 13, 2026 13:40
Comment on lines +4713 to +4714
shift = np.int64((10 + ref.times[-1]) * ref.info["sfreq"])
events_offset = int(np.max(epochs_list[0].events[:, 0])) + shift
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.

Suggested change
shift = np.int64((10 + ref.times[-1]) * ref.info["sfreq"])
events_offset = int(np.max(epochs_list[0].events[:, 0])) + shift
shift = len(ref.times)
events_offset = ref.events[-1, 0] + shift

Copy link
Copy Markdown
Contributor

@nordme nordme left a comment

Choose a reason for hiding this comment

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

Hi @aman-coder03 ! Thanks for the PR.

I took a look at the concatenation function and tests, and it's looking pretty good so nice work. I spotted a few more EpochsTFR attributes that need handling.

Attributes to check:

  1. ep.baseline
    Even if the times arrays are equivalent across epochs instances, some instances could have baselines where others have none, and that's a problem. For concatenation, baselines should be the same across instances.
  2. ep.method
    We should check that the method of construction is the same for all our epochs instances (e.g. not mixing multitaper and morlet wavelet TFR results for example).
  3. ep.weights
    This attribute stores weights for tapers. If applicable, these need to be equivalent across epochs instances.

Attributes that need concatenation:

  1. ep.comment
    This attribute typically stores trial descriptions of some sort and might not be the same across epochs instances (e.g. 'run 1', 'run2', 'run 3'). These need to be put together for the returned epochs instance.

Cheers.

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.

3 participants