{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Interpolate bad channels for MEG/EEG channels\n\nThis example shows how to interpolate bad MEG/EEG channels\n\n- Using spherical splines from :footcite:`PerrinEtAl1989` for EEG data.\n- Using field interpolation for MEG and EEG data.\n\nIn this example, the bad channels will still be marked as bad.\nOnly the data in those channels is replaced.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Authors: Denis A. Engemann \n# Mainak Jas \n#\n# License: BSD-3-Clause\n# Copyright the MNE-Python contributors." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import mne\nfrom mne.datasets import sample\n\nprint(__doc__)\n\ndata_path = sample.data_path()\nmeg_path = data_path / \"MEG\" / \"sample\"\nfname = meg_path / \"sample_audvis-ave.fif\"\nevoked = mne.read_evokeds(fname, condition=\"Left Auditory\", baseline=(None, 0))\n\n# plot with bads\nevoked.plot(exclude=[], picks=(\"grad\", \"eeg\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compute interpolation (also works with Raw and Epochs objects)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "evoked_interp = evoked.copy().interpolate_bads(reset_bads=False)\nevoked_interp.plot(exclude=[], picks=(\"grad\", \"eeg\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also use minimum-norm for EEG as well as MEG\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "evoked_interp_mne = evoked.copy().interpolate_bads(\n reset_bads=False, method=dict(eeg=\"MNE\"), verbose=True\n)\nevoked_interp_mne.plot(exclude=[], picks=(\"grad\", \"eeg\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## References\n.. footbibliography::\n\n" ] } ], "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 }