From 431e98268e8771cdca0f4cb0136e311382b3738c Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Sun, 7 Oct 2012 22:10:34 +0200 Subject: [PATCH 1/2] cosmit --- examples/export/README.txt | 6 +++++ examples/export/epochs_as_data_frame.py | 34 ++++++++++++++++++------- 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 examples/export/README.txt diff --git a/examples/export/README.txt b/examples/export/README.txt new file mode 100644 index 00000000000..3d60a864e26 --- /dev/null +++ b/examples/export/README.txt @@ -0,0 +1,6 @@ + +Export of MNE data for us in other packages +------------------------------------------- + +Export as data frames in Pandas, TimeSeries in nitime etc. + diff --git a/examples/export/epochs_as_data_frame.py b/examples/export/epochs_as_data_frame.py index 998412322fc..68563ade50a 100644 --- a/examples/export/epochs_as_data_frame.py +++ b/examples/export/epochs_as_data_frame.py @@ -1,27 +1,41 @@ +""" +====================================== +Export Epochs to a dataframe in Pandas +====================================== + +""" + +# Author: Denis Engemann +# +# 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")] @@ -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 @@ -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 @@ -58,3 +72,5 @@ grouped_epochs.std()["MEG 0113"].plot() grouped_tsl.agg(np.std).plot(legend=0) + +pl.show() From 69d2033920082e7b06e2f5531f1886622df5358c Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Sun, 7 Oct 2012 22:11:02 +0200 Subject: [PATCH 2/2] for proper doc generation --- .../{epochs_as_data_frame.py => plot_epochs_as_data_frame.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/export/{epochs_as_data_frame.py => plot_epochs_as_data_frame.py} (100%) diff --git a/examples/export/epochs_as_data_frame.py b/examples/export/plot_epochs_as_data_frame.py similarity index 100% rename from examples/export/epochs_as_data_frame.py rename to examples/export/plot_epochs_as_data_frame.py