How can I add events data from a csv file and analyse it with the raw data

How can we add event information from a different csv file and analyse the raw data which is in a different csv file. I created a mne info object for the raw data but how can we do the same for events and analyse the data.

Here is the event data
Start (min) End (min) Duration Motion Artifact
0 00:00 01:00 1.0 Eyes Closed
1 01:00 02:00 1.0 Silent Movie and Arithmetic every 10s
2 02:00 03:00 1.0 Eyes Closed
3 03:00 04:00 1.0 Break
4 04:00 04:05 5.0 Blinking
5 05:00 05:05 5.0 Tapping
6 06:00 06:05 5.0 Side to Side Eye Movements
7 07:00 07:05 5.0 Jaw Movements
8 08:00 08:05 5.0 Up and Down Eye Movements
9 09:00 09:05 5.0 Tapping
10 10:00 10:05 5.0 Blinking
11 11:00 11:05 5.0 Jaw Movements
12 12:00 12:05 5.0 Side to Side Eye Movements
13 13:00 13:05 5.0 Up and Down Eye Movements
14 0 14:00 0.0 0

I already added the raw info from the csv file.

import pandas as pd
import mne
import matplotlib.pyplot as plt
import numpy as np
%matplotlib qt

Load the CSV file using Pandas, skipping rows starting with

data = pd.read_csv(“C:\Users\acer\Downloads\Claire Test Files FEB 2023\Claire_Music drop- updated.csv”, comment=“#”)

Extract the data values from the Pandas DataFrame and transpose it

data_array = data.values[:, 1:].T / 1E7 # Scaling just makes plotting easier!

Define the channel names and types

channel_names = data.columns[1:].tolist()
channel_types = [“eeg”] * len(channel_names)

Create an MNE Info object to store information about the data

sfreq = 1000 # Set the sampling frequency of the data
info = mne.create_info(channel_names, sfreq, channel_types)

Create an MNE Raw object from the NumPy array and Info object

raw = mne.io.RawArray(data_array, info)

Print information about the data

print(raw.info)

Thank you! would be grateful for any help with this.

Hi Esha,

It sounds like you want to create an Annotation object after reading the events using pandas:

https://mne.tools/stable/generated/mne.Annotations.html

and set it to the raw data using:

https://mne.tools/stable/generated/mne.io.Raw.html#mne.io.Raw.set_annotations

If you need to convert these into events, you can use:

https://mne.tools/stable/generated/mne.events_from_annotations.html

Mainak

3 Likes

Thank you very much for your helpful response! I appreciate it.
I will try out this suggestions and let you know how it goes.