Adding a separate events csv file & Epoching

:question: If you have a question or issue with MNE-Python, please include the following info:

  • MNE version: e.g. mne-1.5.1-py3-
  • operating system: Windows 10

Hi,

I am new to EEG signal analysis. A data that I am working on right now consists of two files, one for events and one for continuous EEG signal.

I would like to find an efficient way to add the events file to the eeg signal and to create a raw object.

My event file looks like the following:

Columns: Class1, Class2, Class3, Class 4
0 1 0 0
.
.
1 0 0 0

And so on, so it looks like it’s one-hot encoded. Each class contains 1 for the priod of 150 data points.

My question is how can I add this to my eeg and start epoching and processing the data through MNE?
Thanks in advance.

to read in the events data file I would probably use pandas.read_csv() (setting delim=" " for space-separated, or delim="\t" for tab-separated as appropriate, if it’s not actually a CSV).

This code just creates a fake dataframe similar to the one you’d read in:

import numpy as np
import pandas as pd
data = np.zeros((12, 4), dtype=int)
for ix, row in enumerate(data):
    row[ix % 4] = 1
df = pd.DataFrame(columns=["Class1", "Class2", "Class3", "Class4"], data=data)

If each class is β€œactive” for 150 data samples, you could make an events file like this:

sample_num = np.arange(0, df.shape[0] * 150, 150)
middle_col = np.zeros_like(sample_num)
event_col = np.nonzero(df.to_numpy())[1]
events = np.vstack([sample_num, middle_col, event_col]).T

Then when you epoch, set tmin=0 and tmax at whatever the duration is corresponding to 150 samples (i.e., 150 / raw.info['sfreq'])

2 Likes