ENH: Support concatenate_epochs() for EpochsTFR#13745
Open
aman-coder03 wants to merge 4 commits intomne-tools:mainfrom
Open
ENH: Support concatenate_epochs() for EpochsTFR#13745aman-coder03 wants to merge 4 commits intomne-tools:mainfrom
concatenate_epochs() for EpochsTFR#13745aman-coder03 wants to merge 4 commits intomne-tools:mainfrom
Conversation
This was referenced Mar 13, 2026
drammock
reviewed
Apr 1, 2026
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 |
Member
There was a problem hiding this comment.
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 |
nordme
reviewed
Apr 1, 2026
Contributor
nordme
left a comment
There was a problem hiding this comment.
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:
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.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).ep.weights
This attribute stores weights for tapers. If applicable, these need to be equivalent across epochs instances.
Attributes that need concatenation:
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference issue (if any)
towards #13191
What does this implement/fix?
concatenate_epochs()now works withEpochsTFRobjects. Before this, passing a list ofEpochsTFRinstances would just crash with aTypeErrorbecauseEpochsTFRisn't a subclass ofBaseEpochsfix adds a helper function
_concatenate_epochs_tfr()inmne/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 epochsconcatenate_epochs()now checks if it's dealing withEpochsTFRobjects and routes to this helper automaticallytests are added in
mne/time_frequency/tests/test_tfr.pyAdditional information
task 1 of 3 from #13191 (as discussed with @drammock)
tasks 2 and 3(
EpochsSpectrumsupport and allowingEpochsTFRto acceptRawTFRas input) will come in follow up PRs