{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Show EOG artifact timing\n\n\nCompute the distribution of timing for EOG artifacts.\n\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Authors: Eric Larson <larson.eric.d@gmail.com>\n#\n# License: BSD (3-clause)\n\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nimport mne\nfrom mne import io\nfrom mne.datasets import sample\n\nprint(__doc__)\n\ndata_path = sample.data_path()" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Set parameters\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'\n\n# Setup for reading the raw data\nraw = io.read_raw_fif(raw_fname, preload=True)\nevents = mne.find_events(raw, 'STI 014')\neog_event_id = 512\neog_events = mne.preprocessing.find_eog_events(raw, eog_event_id)\nraw.add_events(eog_events, 'STI 014')\n\n# Read epochs\npicks = mne.pick_types(raw.info, meg=False, eeg=False, stim=True, eog=False)\ntmin, tmax = -0.2, 0.5\nevent_ids = {'AudL': 1, 'AudR': 2, 'VisL': 3, 'VisR': 4}\nepochs = mne.Epochs(raw, events, event_ids, tmin, tmax, picks=picks)\n\n# Get the stim channel data\npick_ch = mne.pick_channels(epochs.ch_names, ['STI 014'])[0]\ndata = epochs.get_data()[:, pick_ch, :].astype(int)\ndata = np.sum((data.astype(int) & 512) == 512, axis=0)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Plot EOG artifact distribution\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "plt.stem(1e3 * epochs.times, data)\nplt.xlabel('Times (ms)')\nplt.ylabel('Blink counts (from %s trials)' % len(epochs))\nplt.show()" ], "outputs": [], "metadata": { "collapsed": false } } ], "metadata": { "kernelspec": { "display_name": "Python 2", "name": "python2", "language": "python" }, "language_info": { "mimetype": "text/x-python", "nbconvert_exporter": "python", "name": "python", "file_extension": ".py", "version": "2.7.13", "pygments_lexer": "ipython2", "codemirror_mode": { "version": 2, "name": "ipython" } } } }