"mne.EpochsArrays" seems to set "times" values by default

  • MNE-Python version: v0.22
  • operating system: linux

Hi there, doing some cooking to run regression stats for which the order of epochs matters.

1) I start with a list called epos_list, containing roughly the same numbers of epochs per bins, and most importantly, all of them with the correct times of “-1 -0 sec”:

epos_list
[<EpochsFIF |  45 events (all good), -1 - 0 sec, baseline [0, 0] sec, ~24.8 MB, data loaded, with metadata,
  '12': 9
  '22': 6
  '32': 30>,
 <EpochsFIF |  45 events (all good), -1 - 0 sec, baseline [0, 0] sec, ~24.8 MB, data loaded, with metadata,
  '12': 15
  '22': 15
  '32': 15>,
[....]

2) I concatenate those making sure the order I defined in metadata is preserved:

#recreate an Epochs array for stats
if bidx == ['1', '2', '3', '4', '5']:                    
       data = np.concatenate([epos_list[0].get_data(), 
                                       epos_list[1].get_data(), 
                                       epos_list[2].get_data(),
                                       epos_list[3].get_data(),
                                       epos_list[4].get_data()])
else: 
     print(f'Indexing error : {sid}')

3) I create an EpochsArray with these data for subsequent single-trial analysis:

data_epo = mne.EpochsArray(data, info = blah.info)

and surprise, data_epo shows incorrect times!

<EpochsArray |  224 events (all good), 0 - 1 sec, baseline off, ~94.6 MB, data loaded,
 '1': 224>

4) To make sure, the info I provided have the right times:

blah.times
array([-1.   , -0.998, -0.996, -0.994, -0.992, -0.99 , -0.988, -0.986,
       -0.984, -0.982, -0.98 , -0.978, -0.976, -0.974, -0.972, -0.97 ,
        [...] -0.016, -0.014, -0.012, -0.01 ,
       -0.008, -0.006, -0.004, -0.002,  0.   ])

What’s going on with EpochsArray?

Troubleshooting:

  1. the same results is returned when using the more straightforward:

data_epo = mne.EpochsArray(mne.concatenate_epochs(epos_list), info = blah.info)
(mine is convoluted to insure proper indexing)

  1. the same issue is there when using directly the info of the same epochs that actually fed the epochs list (blah being a subset of those anyways):

data_epo = mne.EpochsArray(data, info = epos[0].info)

Of course, east workaround by adding the proper times but unfortunately I did not see this coming at all when analysing data and lost a day of work troubleshooting this seeing the nonsensical stat outcomes

update: data_epo.times = blah.times will not do as a simple workaround

Cheers,
Virginie

Hello @virvw,

sorry to hear you were running into trouble here!

info in fact doesn’t contain the time, as far as I know. So simply passing info to EpochsArray is not sufficient!

However, EpochsArray has an additional parameter: tmin. By default, it’s set to 0. What you can try is call:

EpochsArray(..., info=blah.info, tmin=blah.tmin)

I’m also wondering why you’re not using mne.concatenate_epochs() directly? You could do:

epochs_concat = mne.concatenate_epochs(
    [epos for idx, epos in enumerate(epos_list)
     if idx in ['1', '2', '3', '4']]
)

and then access the data via epochs_concat.get_data(). Wouldn’t that work too, and be easier? :slight_smile:

2 Likes

Great, thanks for the clarification @richard :+1:

The code you suggest only insures epochs group are part of the wanted list not that they are concatenated in a specified order.

For sake of closure :
1) option novice

if bidx == ['1', '2', '3', '4', '5']:                    
        data = np.concatenate([epos_list[0].get_data(), 
                                       epos_list[1].get_data(), 
                                       epos_list[2].get_data(),
                                       epos_list[3].get_data(),
                                       epos_list[4].get_data()])
else: 
         print(f'Indexing error : {sid}')

data_epo = mne.EpochsArray(data, info = blah.info, tmin = blah.tmin) 

2) option aficionado

data_epo = mne.concatenate_epochs([epos_list[ei] for ei, e in enumerate(epos_list) 
                                               if bidx == ['1', '2', '3', '4', '5']])

Both give equivalent outcomes (what matters :wink: ) but 2) is more elegant and efficient! :slight_smile:

Danke Sehr!

1 Like

PS: I create data because I also needed it for the stats design ! (not so novice :upside_down_face:)

… but sometimes more confusing :smiley: So it’s really a matter of taste. Pick your poison :skull_and_crossbones:

Ah, I see! Parfait !

Kein Problem! :pretzel: