Skip to content

ENH: Add EpochsTFR.from_raw_tfr() to epoch RawTFR objects#13750

Open
aman-coder03 wants to merge 2 commits intomne-tools:mainfrom
aman-coder03:enh-epochstfr-from-rawtfr
Open

ENH: Add EpochsTFR.from_raw_tfr() to epoch RawTFR objects#13750
aman-coder03 wants to merge 2 commits intomne-tools:mainfrom
aman-coder03:enh-epochstfr-from-rawtfr

Conversation

@aman-coder03
Copy link
Copy Markdown
Contributor

Reference issue (if any)

towards #13191

What does this implement/fix?

adds a new classmethod EpochsTFR.from_raw_tfr() that creates an EpochsTFR from a RawTFR object by slicing the already computed TFR data at event times...similar to how Epochs(raw, events, tmin, tmax) works in the time domain

this 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..

raw_tfr = raw.compute_tfr("morlet", freqs=np.arange(8, 30))
epochs_tfr = EpochsTFR.from_raw_tfr(raw_tfr, events, tmin=-0.2, tmax=0.5)

epochs that fall outside the bounds of the RawTFR are dropped automatically. event_id, on_missing, event_repeated, metadata, and picks are all supported
tests are added in mne/time_frequency/tests/test_tfr.py

Additional information

task 3 of 3 from #13191 (as discussed with @drammock and @larsoner)
task 1 #13745
task 2 #13748

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 ! 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.

Comment thread mne/time_frequency/tfr.py
events,
event_id=None,
tmin=-0.2,
tmax=0.5,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread mne/time_frequency/tfr.py
good_event_indices = []

for idx in selected:
event_samp = events[idx, 0]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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