Epochs with variable durations... again

  • MNE-Python version: 0.21.0
  • operating system: Linux

Dear MNE developers,

I am working with MEG data of sentence listening. I need to epoch the data on the basis of sentence duration - and they are all different. This means I want epochs with variable durations - but in the Epochs class, it’s not possible to specify a variable tmax.

An idea I had to get this done, was to epoch using the longest possible sentence duration as tmax, and then trim each epoch based on the duration it’s supposed to have… But is there a better (faster, cleaner) way to do this? I have offset triggers, as well as a dataframe with samples and times for both onsets and offsets to work with.

I have found the following related issues:
The exact same issue - closed as ‘wontfix’
An issue that arises when dealing with variable length epochs (though I don’t need to do TFR)

Thanks a lot!

Best,

Sophie Slaats

hi @sslaats

this is a tricky issue. It’s a trade off on the MNE side. Having a fixed length simplifies and accelerates a lot of code.

once you have epochs what do you do?

Alex

1 Like

Hi @agramfort,
Thanks for your quick reply! I use them to estimate temporal response functions - so more specifically, I compute the covariance matrix of the data with a time-lagged stimulus feature.
Sophie

have you add a look at

or

?

Alex

I’m not sure I understood what you want to do with your variable-length epochs, but you could always roll your own solution (e.g. put epochs in a list and then do whatever you need to do). Of course you could achieve this by epoching the data using the longest duration as tmax and then prune the individual epochs as needed. Another option if you must squeeze all data into a 2D table is to set samples exceeding individual epoch lengths to np.nan.

1 Like

Hi @agramfort and @cbrnr,

Thanks a lot for your replies. I am aware of the possibilities for regressing continuous data (although I had not looked at MNE options for this in detail, so thanks for the references @agramfort :slight_smile:). For some design reasons it was handy to epoch the data, and I actually already have (using FieldTrip). The rest of my pipeline is in Python with MNE, and I would like to rewrite the first part using MNE as well, for continuity reasons.

I’ll go for pruning the epochs then. Thanks again to you both!

Best,

Sophie