简体   繁体   中英

Python read EEG data form .csv file using mne?

I want to use Python mne library. I have a .csv file with EEG data . The first column is Time (ms) and the next 16 columns are EEG data for 16 channels. Sampling rate is 2048Hz. I want to use mne to analyse data. Have tried mne.io.RawArray but get the error: ValueError: len(data) does not match len(info["ch_names"]) . What should I do?

Code I tried:

import numpy as np
import pandas as pd 
import mne

path = 'my path'
data = pd.read_csv(path + 'file.csv', 
                   skiprows=0, usecols=[*range(0, 17)]) 
ch_names = ['CH 1', 'CH 2', 'CH 3', 'CH 4', 'CH 5', 'CH 6', 'CH 7', 'CH 8', 'CH 9',
            'CH 10', 'CH 11', 'CH 12', 'CH 13', 'CH 14', 'CH 15', 'CH 16']

sfreq = 2048 
info = mne.create_info(ch_names = ch_names, sfreq = sfreq)
raw = mne.io.RawArray(data, info)
raw.plot()

Sample data screenshot attached. Please note there is another column "Channel 16" not shown. EEG sample data 16 channels

Your data frame has channels as columns. But,

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

This expects channels as rows. Try passing data.transpose()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM