mne.EpochsArray format

I have ECoG data (sampling freq = 2000) in the following format:

ecog data = channels x data points #(18 channels x 386400 points)
events_markers = no. of event marker x ([index of marker ,nan, ‘marker name’]) #(39 markers)

To use : epochs = mne.EpochsArray(epochs_data, info=info, events=events, event_id={‘arbitrary’: 1})

The epochs_data should be in the format (n_epochs, n_channels, n_samples) and number of epochs = number of events

I don’t understand how to divide my data into number of epochs so that it is equal to the number of events.

Hello,

Raw represents continuous data. The underlying data array shape is (n_channels, n_times).
Epoch represents discontinuous data with all epoch of the same length. The underlying data array shape is (n_epochs, n_channels, n_times).

In your case, you have continuous data and events that will be used to create the epochs. You will also need to define the tmin and tmax delimiting an epoch around each event (for instance, tmin=-0.2, tmax=0.5 will cut your continuous data in epochs of 700 ms starting 200 ms before the provided events).

The first step is to load the continuous data in a Raw object. See: mne.io.RawArray — MNE 1.0.3 documentation

from mne import create_info
from mne.io import RawArray

ch_names = [f"ch{k}" for k in range(1, 19, 1)]
info = create_info(ch_names, 2000, "ecog")
raw = RawArray(data, info)  # data of shape (n_channels, n_times)

Then you can create epochs from this raw object by providing the events, tmin and tmax to mne.Epochs. See: mne.Epochs — MNE 1.0.3 documentation
As it’s not clear what the format of your event_markers is, I can’t give you exact code, but you’ll need to format it as an array of integers of shape (n_events, 3). Have a look in some of the tutorial for examples.

Mathieu

Hello,

Thank you so much for your reply.

I have the raw data and info ready.

My event_markers are in this format (shape= 39 x3) :

array([[6670, nan, ‘bothankle_ma_go’],
[16608, nan, ‘rest’],
[28213, nan, ‘bothankle_ma_go’],

[366194, nan, ‘bothankle_ma_go’],
[376261, nan, ‘rest’],
[386243, nan, ‘End Experiment’]])

I am unsure how to get it into the (n_epochs, n_channels, n_samples) and what will it’s dimensions be.

Thanks for the help!

That looks close enough, replace the nan by 0 and the strings in the last columns by an integer. Map this integer to each string and provide it to Epochs in event_id as dict(str: int). For instance:

events = array([
    [6670,  0, 1],
    [16608, 0, 2],
    [28213, 0, 1],
]).astype(int)
event_id = dict(bothankle_ma_go=1, rest=2)

EDIT: In event_id you need to set the events that you want to keep in your epochs. /!\ They will have the same duration. If you want Epochs of e.g. 1 seconds around your bothankle_ma_go event, and 2 seconds around rest, you’ll have to create 2 Epochs objects, one for each.

Hi,

I have done all of that. That is not my problem.

I do not understand how to get the Epoch data shape from my raw data and event markers. How should I divide it into :
n_epochs x n_channels x n_times

What is the window size I need to choose because I need the Epoch data to be in?
n_channels = 18
n_times = 386400 ? (equal to the number of data points?? )
n_epochs= ???

This is what I can’t figure out.

You have continuous data. This is why I suggest you start by creating a Raw object.
To create epochs from a Raw object, you need to provide the following information:

  • a continuous data recording, i.e. a Raw
  • events that correspond to your epochs
  • the duration of the epochs in the form of a tuple (tmin, tmax) (an epoch can start before an event, thus tmin can be negative), which is what you also called window-size.

Those 3 pieces of information can not be guessed. You already have the 2 first ones, you now need to defined the last one: the duration of your epochs.


The creation of an Epoch object will create the underlying associated array of shape (n_epochs, n_channels, n_times).

Please have a look at the introductory tutorials Overview of MEG/EEG analysis, and especially at the Epoching continuous data section. It should help you understand the data structure used by MNE.

1 Like