Python MNE - reading EEG data from array
Asked Answered
A

1

8

I have EEG data that comes in the form of a 3D numpy array (epoch * channel * timepoint). timepoint is a 256 element array containing each sampled timepoint (1s total, at 256Hz). epoch is an experimental trial.

I'm trying to import the numpy array into a form Python-MNE (http://martinos.org/mne/stable/mne-python.html) understands, but I'm having some trouble

First, I'm not sure if I should be importing this raw data as a RawArray or an EpochsArray. I tried the latter with this:

ch_names = list containing my 64 eeg channel names
allData = 3d numpy array as described above

info = mne.create_info(ch_names, 256, ch_types='eeg')

event_id = 1

#I got this from a tutorial but really unsure what it does and I think this may be the problem
events = np.array([200, event_id])  #I got this from a tutorial but really unsure what it does and I think this may be the problem

raw = mne.EpochsArray(allData, info, events=events)

picks = mne.pick_types(info, meg=False, eeg=True, misc=False)

raw.plot(picks=picks, show=True, block=True)

When I run this I get an index error: "too many indices for array"

Ultimately I want to do some STFT and CSP analysis on the data, but right now I'm in need of some help with the initial restructuring and importing into MNE.

Whats the correct way to import this numpy data that would make it easiest to complete my intended analyses?

Asphyxia answered 12/8, 2015 at 0:39 Comment(1)
How did you solve this problem? I am having the same problem. I need events and event_id but don't know how to get them.Fatten
L
0

Is there any way you can convert the data you acquired from your EEG setup into the .fif format? The 'raw' data format the MNE page talks about in their tutorial is a .fif format file. If you can get your eeg data into .fif format, you can pretty much just follow the tutorial step by step...

Functions to convert from various other EEG file formats to .fif: http://martinos.org/mne/stable/manual/convert.html

If that's not an option, here are some thoughts:

  • EpochsArray() looks to be the correct function as it expects a data array with (n_epochs, n_channels, n_times) for the shape. Just to be sure, check that the shape of your allData array matches up with np.shape(allData).

  • On a related note the help page for EpochsArray() mentioned mne.read_events() the big question though is where your events data might be stored for you to be able to read it...

  • Based on the tutorial you linked it seems like the way to get 'events' if you're starting from a .fif file is: events = mne.find_events(raw, stim_channel='STI 014'). This makes me wonder if you have more than 64 channels in your numpy array and one of your channels is in fact a stimulation channel... if that's the case you could try feeding that stim channel to the mne.read_events() function. Alternatively, perhaps your stim or events channel might be a separate array or perhaps unprocessed?

Hope this is at least somewhat helpful and good luck!

Linzy answered 12/8, 2015 at 1:59 Comment(1)
well, I cant use a .fif file because eventually I will be streaming the data live into python and won't be using a file to transport data between machines. I'm also pretty sure I only have 64 channels in my 3d array, I explicitly created it in the order recommended in the docs. I guess I'm not sure how to store events/class information which seems to be the main problemAsphyxia

© 2022 - 2024 — McMap. All rights reserved.