{ "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 with FieldTrip client\n\n\nThis example demonstrates how to connect the MNE real-time\nsystem to the Fieldtrip buffer using FieldTripClient class.\n\nThis example was tested in simulation mode\n\nneuromag2ft --file MNE-sample-data/MEG/sample/sample_audvis_raw.fif\n\nusing a modified version of neuromag2ft available at\n\nhttp://neuro.hut.fi/~mainak/neuromag2ft-2.0.0.zip\n\nto run the FieldTrip buffer. Then running this example acquires the\ndata on the client side.\n\nSince the Fieldtrip buffer does not contain all the\nmeasurement information required by the MNE real-time processing\npipeline, an info dictionary must be provided to instantiate FieldTripClient.\nAlternatively, the MNE-Python script will try to guess the missing\nmeasurement info from the Fieldtrip Header object.\n\nTogether with RtEpochs, this can be used to compute evoked\nresponses using moving averages.\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Author: Mainak Jas \n#\n# License: BSD (3-clause)\n\nimport matplotlib.pyplot as plt\n\nimport mne\nfrom mne.viz import plot_events\nfrom mne.realtime import FieldTripClient, RtEpochs\n\nprint(__doc__)\n\n# select the left-auditory condition\nevent_id, tmin, tmax = 1, -0.2, 0.5\n\n# user must provide list of bad channels because\n# FieldTrip header object does not provide that\nbads = ['MEG 2443', 'EEG 053']\n\nplt.ion() # make plot interactive\n_, ax = plt.subplots(2, 1, figsize=(8, 8)) # create subplots\n\nwith FieldTripClient(host='localhost', port=1972,\n tmax=150, wait_max=10) as rt_client:\n\n # get measurement info guessed by MNE-Python\n raw_info = rt_client.get_measurement_info()\n\n # select gradiometers\n picks = mne.pick_types(raw_info, meg='grad', eeg=False, eog=True,\n stim=True, exclude=bads)\n\n # create the real-time epochs object\n rt_epochs = RtEpochs(rt_client, event_id, tmin, tmax,\n stim_channel='STI 014', picks=picks,\n reject=dict(grad=4000e-13, eog=150e-6),\n decim=1, isi_max=10.0, proj=None)\n\n # start the acquisition\n rt_epochs.start()\n\n for ii, ev in enumerate(rt_epochs.iter_evoked()):\n print(\"Just got epoch %d\" % (ii + 1))\n\n ev.pick_types(meg=True, eog=False)\n if ii == 0:\n evoked = ev\n else:\n evoked = mne.combine_evoked([evoked, ev], weights='nave')\n\n ax[0].cla()\n ax[1].cla() # clear axis\n\n plot_events(rt_epochs.events[-5:], sfreq=ev.info['sfreq'],\n first_samp=-rt_client.tmin_samp, axes=ax[0])\n\n evoked.plot(axes=ax[1]) # plot on second subplot\n ax[1].set_title('Evoked response for gradiometer channels'\n '(event_id = %d)' % event_id)\n\n plt.pause(0.05)\n plt.draw()\n\n plt.close()" ], "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" } } } }