{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Compute real-time evoked responses using moving averages\n\n\nThis example demonstrates how to connect to an MNE Real-time server\nusing the RtClient and use it together with RtEpochs to compute\nevoked responses using moving averages.\n\nNote: The MNE Real-time server (mne_rt_server), which is part of mne-cpp,\nhas to be running on the same computer.\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Authors: Martin Luessi \n# Mainak Jas \n#\n# License: BSD (3-clause)\n\nimport matplotlib.pyplot as plt\n\nimport mne\nfrom mne.datasets import sample\nfrom mne.realtime import RtEpochs, MockRtClient\n\nprint(__doc__)\n\n# Fiff file to simulate the realtime client\ndata_path = sample.data_path()\nraw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'\nraw = mne.io.read_raw_fif(raw_fname, preload=True)\n\n# select gradiometers\npicks = mne.pick_types(raw.info, meg='grad', eeg=False, eog=True,\n stim=True, exclude=raw.info['bads'])\n\n# select the left-auditory condition\nevent_id, tmin, tmax = 1, -0.2, 0.5\n\n# create the mock-client object\nrt_client = MockRtClient(raw)\n\n# create the real-time epochs object\nrt_epochs = RtEpochs(rt_client, event_id, tmin, tmax, picks=picks,\n decim=1, reject=dict(grad=4000e-13, eog=150e-6))\n\n# start the acquisition\nrt_epochs.start()\n\n# send raw buffers\nrt_client.send_data(rt_epochs, picks, tmin=0, tmax=150, buffer_size=1000)\nfor ii, ev in enumerate(rt_epochs.iter_evoked()):\n print(\"Just got epoch %d\" % (ii + 1))\n ev.pick_types(meg=True, eog=False) # leave out the eog channel\n if ii == 0:\n evoked = ev\n else:\n evoked = mne.combine_evoked([evoked, ev], weights='nave')\n plt.clf() # clear canvas\n evoked.plot(axes=plt.gca()) # plot on current figure\n plt.pause(0.05)" ], "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" } } } }