{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Show EOG artifact timing\n\nCompute the distribution of timing for EOG artifacts.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Authors: Eric Larson \n#\n# License: BSD-3-Clause\n# Copyright the MNE-Python contributors." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nimport mne\nfrom mne import io\nfrom mne.datasets import sample\n\nprint(__doc__)\n\ndata_path = sample.data_path()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set parameters\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "meg_path = data_path / \"MEG\" / \"sample\"\nraw_fname = meg_path / \"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\ndata = epochs.get_data(picks=\"STI 014\").squeeze()\ndata = np.sum((data.astype(int) & eog_event_id) == eog_event_id, axis=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot EOG artifact distribution\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fig, ax = plt.subplots(layout=\"constrained\")\nax.stem(1e3 * epochs.times, data)\nax.set(xlabel=\"Times (ms)\", ylabel=f\"Blink counts (from {len(epochs)} trials)\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 0 }