Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data frame #1

Merged
merged 2 commits into from
Oct 7, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/export/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

Export of MNE data for us in other packages
-------------------------------------------

Export as data frames in Pandas, TimeSeries in nitime etc.

Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
"""
======================================
Export Epochs to a dataframe in Pandas
======================================

"""

# Author: Denis Engemann <d.engemann@fz-juelich.de>
#
# License: BSD (3-clause)

print __doc__

import mne
import pylab as pl
import numpy as np
from mne.fiff import Raw
from mne.datasets import sample

from pandas.stats.api import rolling_mean

data_path = sample.data_path('examples/')
data_path = sample.data_path('..')
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'

raw = Raw(raw_fname)
events = mne.find_events(raw, stim_channel='STI 014')
exclude = raw.info['bads'] + ['MEG 2443', 'EEG 053']
picks = mne.fiff.pick_types(raw.info, meg=True, eeg=True, eog=True, stim=False, exclude=exclude)
raw.info['bads'] = ['MEG 2443', 'EEG 053']
picks = mne.fiff.pick_types(raw.info, meg=True, eeg=True, eog=True, stim=False,
exclude=raw.info['bads'])

event_id = 1
tmin = -0.2
tmax = 0.5
tmin, tmax, event_id = -0.2, 0.5, 1
baseline = (None, 0)
reject = dict(grad=4000e-13, mag=4e-12, eog=150e-6)

epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks,
baseline=baseline, preload=False, reject=reject)

epochs_df = epochs.to_data_frame()
epochs_df = epochs.as_data_frame()

meg_chs = [c for c in epochs.ch_names if c.startswith("MEG")]

Expand All @@ -34,7 +48,7 @@
# then create a quick average plot
grouped_tsl.mean().plot(legend=0)

# or a trellis plot on a few channels
# or a trellis plot on a few channels
grouped_tsl.mean()[meg_chs[:10]].plot(subplots=1)

# use median instead
Expand All @@ -43,7 +57,7 @@
# use custom numpy function
grouped_tsl.agg(np.std).plot(legend=0)

# average and then smooth using a rolling mean and finally plot in one sinfle line!
# average then smooth using a rolling mean and finally plot in one single line!
grouped_tsl.apply(lambda x: rolling_mean(x.mean(), 10)).plot(legend=0)

# apply different functio for channels
Expand All @@ -58,3 +72,5 @@
grouped_epochs.std()["MEG 0113"].plot()

grouped_tsl.agg(np.std).plot(legend=0)

pl.show()