Failed to concatenate epochs with different durations

  • MNE version: 1.7.1
  • operating system: Windows 10

Hi,


I am very new to MNE, so I apologise if this is an elementary question. :slight_smile:


I was trying to epoch EEG data based on three stimuli types, meaning there are three event_id. I want to epoch the data as below:


if event_id = 1, tmin = -1, tmax = 42
if event_id = 2/3, tmin = -1, tmax = 7


Besides, the order of the appearance of stimuli was: 1,1,1,1,2,3,2,3 (just a short version example).


I want to get a whole epoched data with the mne.epochs() and mne.concatenate_epochs(). Below is my code:

for i in events_ica_subj13[:, 2]: 
    if i == 1:
        epochs_encode_subj13 = mne.Epochs(raw_eeg_subj13_1Hz_notch2, events_ica_subj13, 
                                           event_id = i,
                                           tmin = -1, tmax = 42,  
                                           baseline = (None, None),
                                           preload = True)
    elif i == 2:
        epochs_retr_audio_subj13 = mne.Epochs(raw_eeg_subj13_1Hz_notch2, events_ica_subj13,
                                           event_id = i,
                                           tmin = -1, tmax = 7, 
                                           baseline = (None, None),
                                           preload = True)
    else:
        epochs_retr_pic_subj13 = mne.Epochs(raw_eeg_subj13_1Hz_notch2, events_ica_subj13,
                                           event_id = 3,
                                           tmin = -1, tmax = 7,  
                                           baseline = (None, None),
                                           preload = True) 


This part can work. But when I add mne.concatenate_epochs(), it returns an error as below:

epochs_ica_subj13_01Hz = mne.concatenate_epochs([epochs_encode_subj13, 
                                                epochs_retr_audio_subj13,
                                                epochs_retr_pic_subj13])


Error message:
operands could not be broadcast together with shapes (4097,) (22017,)


I have read about other discussions that this error might be due to the different lengths of the epochs, in my case, 43 and 8. However, since the experimental design is like this, are there any solutions to this problem?


PS. I also tried the numpy.concatenate() method in this link but also failed…


Thank you very much for your help! :slight_smile:
Yi

How do you want to analyze your data? MNE indeed does not support epochs with different lengths, which is why you cannot concatenate them, but maybe this is not even necessary.

1 Like

Hi Clemens,


Thank you for your quick reply. I am just practising preprocessing, and this is not my project, so I don’t have a detailed analysis plan in mind yet. I only know that I will use time-frequency analysis. I was wondering whether we should always have a complete epoched dataset after preprocessing, or if it is also acceptable to have three separate parts in some cases.


Sorry for my very inexperienced question, and thank you for your help!

No, you don’t always need to create a single Epochs object. It really depends on what you want to do. If you have different epoch lengths, this is not even possible, so you could e.g. compute the mean band power (in a specific time window) across epochs, which will yield a single value for each epoch. This is what I frequently do, but again, it’s really a very individual question, and you should have a plan for what you would like to do with your data before trying to implement it.

1 Like

Hey @Yih, I sometimes face the challenge that I want to look at two events or time points, e.g., 2 seconds before a stimulus and 5 seconds after, but with different epochs durations. I would like to keep all pre-processing and data cleaning steps between these two sets of epochs in sync. So what I would do in such a situation is create one set of “long” epochs (in this case e.g. –2.5 to +7 seconds), annotated with epochs metadata, which I would later use to carve out smaller epochs around the events of interest from the larger epochs (via epochs.crop()). It’s a bit cumbersome, but so far it’s been working quite well for me. However, my epochs are never as long are yours, so I don’t know if this approach is feasible for your data.

Richard

1 Like

Hi Clemens,

Thank you very much for the explanation! Now I understand more about epochs with different lengths. I will double-check the main analysis and try out your methods! :smiley:

Hi Richard,

Thank you very much for your reply! This method is quite inspiring. I will later have a try on my data to check! :smiley:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.