{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Plotting topographic arrowmaps of evoked data\n\nLoad evoked data and plot arrowmaps along with the topomap for selected time\npoints. An arrowmap is based upon the Hosaka-Cohen transformation and\nrepresents an estimation of the current flow underneath the MEG sensors.\nThey are a poor man's MNE.\n\nSee :footcite:`CohenHosaka1976` for details.\n\n## References\n.. footbibliography::\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Authors: Sheraz Khan \n#\n# License: BSD-3-Clause\n# Copyright the MNE-Python contributors." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n\nimport mne\nfrom mne import read_evokeds\nfrom mne.datasets import sample\nfrom mne.datasets.brainstorm import bst_raw\nfrom mne.viz import plot_arrowmap\n\nprint(__doc__)\n\npath = sample.data_path()\nfname = path / \"MEG\" / \"sample\" / \"sample_audvis-ave.fif\"\n\n# load evoked data\ncondition = \"Left Auditory\"\nevoked = read_evokeds(fname, condition=condition, baseline=(None, 0))\nevoked_mag = evoked.copy().pick(picks=\"mag\", exclude=\"bads\")\nevoked_grad = evoked.copy().pick(picks=\"grad\", exclude=\"bads\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot magnetometer data as an arrowmap along with the topoplot at the time\nof the maximum sensor space activity:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "max_time_idx = np.abs(evoked_mag.data).mean(axis=0).argmax()\nplot_arrowmap(evoked_mag.data[:, max_time_idx], evoked_mag.info)\n\n# Since planar gradiometers takes gradients along latitude and longitude,\n# they need to be projected to the flatten manifold span by magnetometer\n# or radial gradiometers before taking the gradients in the 2D Cartesian\n# coordinate system for visualization on the 2D topoplot. You can use the\n# ``info_from`` and ``info_to`` parameters to interpolate from\n# gradiometer data to magnetometer data." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot gradiometer data as an arrowmap along with the topoplot at the time\nof the maximum sensor space activity:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plot_arrowmap(\n evoked_grad.data[:, max_time_idx],\n info_from=evoked_grad.info,\n info_to=evoked_mag.info,\n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since Vectorview 102 system perform sparse spatial sampling of the magnetic\nfield, data from the Vectorview (info_from) can be projected to the high\ndensity CTF 272 system (info_to) for visualization\n\nPlot gradiometer data as an arrowmap along with the topoplot at the time\nof the maximum sensor space activity:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "path = bst_raw.data_path()\nraw_fname = path / \"MEG\" / \"bst_raw\" / \"subj001_somatosensory_20111109_01_AUX-f.ds\"\nraw_ctf = mne.io.read_raw_ctf(raw_fname)\nraw_ctf_info = mne.pick_info(\n raw_ctf.info, mne.pick_types(raw_ctf.info, meg=True, ref_meg=False)\n)\nplot_arrowmap(\n evoked_grad.data[:, max_time_idx],\n info_from=evoked_grad.info,\n info_to=raw_ctf_info,\n scale=6e-10,\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 }