{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Compute Rap-Music on evoked data\n\nCompute a Recursively Applied and Projected MUltiple Signal Classification\n(RAP-MUSIC) :footcite:`MosherLeahy1999` on evoked data.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Author: Yousra Bekhti \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.beamformer import rap_music\nfrom mne.datasets import sample\nfrom mne.viz import plot_dipole_amplitudes, plot_dipole_locations\n\nprint(__doc__)\n\ndata_path = sample.data_path()\nsubjects_dir = data_path / \"subjects\"\nmeg_path = data_path / \"MEG\" / \"sample\"\nfwd_fname = meg_path / \"sample_audvis-meg-eeg-oct-6-fwd.fif\"\nevoked_fname = meg_path / \"sample_audvis-ave.fif\"\ncov_fname = meg_path / \"sample_audvis-cov.fif\"\n\n# Read the evoked response and crop it\ncondition = \"Right Auditory\"\nevoked = mne.read_evokeds(evoked_fname, condition=condition, baseline=(None, 0))\n# select N100\nevoked.crop(tmin=0.05, tmax=0.15)\n\nevoked.pick(picks=\"meg\", exclude=\"bads\")\n\n# Read the forward solution\nforward = mne.read_forward_solution(fwd_fname)\n\n# Read noise covariance matrix\nnoise_cov = mne.read_cov(cov_fname)\n\ndipoles, residual = rap_music(\n evoked, forward, noise_cov, n_dipoles=2, return_residual=True, verbose=True\n)\ntrans = forward[\"mri_head_t\"]\nplot_dipole_locations(dipoles, trans, \"sample\", subjects_dir=subjects_dir)\nplot_dipole_amplitudes(dipoles)\n\n# Plot the evoked data and the residual.\nevoked.plot(ylim=dict(grad=[-300, 300], mag=[-800, 800], eeg=[-6, 8]), time_unit=\"s\")\nresidual.plot(ylim=dict(grad=[-300, 300], mag=[-800, 800], eeg=[-6, 8]), time_unit=\"s\")" ] }, { "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 }