Concatenate epochs across subjects in Python-MNE

I switched to open source science in my case done by open sourceย Python module MNE. Python-MNE has also module for MATLAB (for reading MNE dedicated FIF files containing everything) and C (for source localization and channel corregistration toolbox, which I believe only works on Linux and macOS). It works with Python 3 and above same as with good old 2.7.

Spectral topography of click sound stimulation (just for education purpose).

One thing come across your mind when you preprocess your data with MNE. You end up with cleaned raw files, epoched file and you want to do say spectral analysis over just one group of events.

I have recording of data of several event types. And now I want them to plot on spectral topography. It is not hard but it require a bit coding.

Let take a look on basics of code:

# Import MNE module
import mne

# Prepare paths and file names
path = '/Users/michael/experiments/'
sub1 = path + 'test_1-epo.fif'
sub2 = path + 'test_2-epo.fif'
sub3 = path + 'test_3-epo.fif'

# Load each subjects epochs file
sub1_epo = mne.read_epochs(sub1)
sub2_epo = mne.read_epochs(sub2)
sub3_epo = mne.read_epochs(sub3)

# In each epoch set is stored several
# event types, but I am interested say
# in just one and it is called click.
clicks = mne.epochs.concatenate_epochs([sub1_epo['click'], sub2_epo['click'], sub3_epo['click']])

# Now I have all epochs of click in
# one variable which is basicaly
#ย type of epoch e.g., Python-MNE reads
# it as it would be normally created
# epochs type from raw data from subejct.
# Vizualize<span class="p">
clicks.plot_psd_topomap(ch_type='eeg', dB=true, proj=True)

Now we are done. Next time we take a look closer to automate this with functions.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s