epoch data with start and end event markers?

Hello all,

I am working with a dataset that the trial length varies that each trial is marked with a start and end marker. I plan to only run band freq analysis and am wondering if MNE can epoch the data not based on time but between markers, this is to extract only the relevant data from the whole recording. After that, I plan to further epoch the data into 2 secs block with 50% overlaps, can this be done?

The marker look like this (which 1 2 3 is the start of the trial in different condition, where as 99 is the end of the trial)
1 99 2 99 3 99 2 99

I was using EEGLab but unfortunately all the EEGlab study functions as far as I know only supports epochs that are the same length, so am trying to see if MNE will work.

Here is a way to accomplish what you are asking. There may be more efficient ways to do this.

This assumes that your onset/offset is coded in the annotations:

import pandas as pd
dframe = pd.DataFrame(raw.annotations)
c1on = dframe.query('description==1').onset.values[0]
c1off = dframe.query('description==99').onset.values[0]

c2on = dframe.query('description==2').onset.values[0]
c2off = dframe.query('description==99').onset.values[1]  #Note the 1 - each additional 99 will increment
......

#Make a cropped version of your data between onset/offset
c1raw = raw.copy().crop(c1on, c1off)

#Option1 - directly compute PSD off of raw
c1raw.compute_psd()

#Option2 - create epochs out of your data w/ 50% overlap as in your question
#The compute psd will already do welch overlap method - so it is maybe unnecessary to do the overlap with the epochs.
c1epo = mne.make_fixed_length_epochs(c1raw, overlap=0.5, duration=2.0)
c1epo.compute_psd()  

This is only a preliminary code above. I didn’t see that you have multiple repeats on condition 2. You can chop the data up – create epochs. Combine the 2s epochs together and then use them as needed.

-Jeff

Wow, thanks so much for the detailed responses, I will give it a try.