ENH: Add EpochsTFR.from_raw_tfr() to epoch RawTFR objects#13750
ENH: Add EpochsTFR.from_raw_tfr() to epoch RawTFR objects#13750aman-coder03 wants to merge 2 commits intomne-tools:mainfrom
EpochsTFR.from_raw_tfr() to epoch RawTFR objects#13750Conversation
nordme
left a comment
There was a problem hiding this comment.
Hi @aman-coder03 ! Ok, I took a look at the code here. A couple points to adjust for the main function. For epochs created from a raw object, we'll want to let the user specify the baseline they desire (for TFR instances created from epochs objects, the original epochs baseline is preserved). Also, the code matching events to times needs to account for the value of the first sample of the recording for cases where the first samp is not 0.
| events, | ||
| event_id=None, | ||
| tmin=-0.2, | ||
| tmax=0.5, |
There was a problem hiding this comment.
Baseline attribute probably should go here. I'd use (None, 0) as the default value to use the start of the epoch to stim onset.
| good_event_indices = [] | ||
|
|
||
| for idx in selected: | ||
| event_samp = events[idx, 0] |
There was a problem hiding this comment.
Samples don't necessarily start from 0 with the start of the recording. Often, the first time in the time list for the raw object corresponds with a high valued sample number, e.g. 30000. To match times to event samples, the first sample of the raw object must be subtracted from the event sample, then the result divided by sfreq. To my knowledge, this isn't stored in the RawTFR object. @drammock Is the original raw first sample stored somewhere that I've missed?
Basically, the code here needs to add a way to account for the starting sample offset value.
One way to address this might be to add a parameter in the function call where the user must specify the raw.first_samp value.
Reference issue (if any)
towards #13191
What does this implement/fix?
adds a new classmethod
EpochsTFR.from_raw_tfr()that creates anEpochsTFRfrom aRawTFRobject by slicing the already computed TFR data at event times...similar to howEpochs(raw, events, tmin, tmax)works in the time domainthis is useful when you want to compute TFR on continuous raw data first(to avoid edge artifacts around individual trials) then epoch the result afterward..
epochs that fall outside the bounds of the
RawTFRare dropped automatically.event_id,on_missing,event_repeated,metadata, andpicksare all supportedtests are added in
mne/time_frequency/tests/test_tfr.pyAdditional information
task 3 of 3 from #13191 (as discussed with @drammock and @larsoner)
task 1 #13745
task 2 #13748