简体   繁体   中英

Python MNE - reading EEG data from array

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?

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!

In case someone else is wondering, they added a tutorial to their doc: Creating MNE-Python data structures from scratch . You should be able to find the 2 needed steps:

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