{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Plot point-spread functions (PSFs) and cross-talk functions (CTFs)\n\nVisualise PSF and CTF at one vertex for sLORETA.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Authors: Olaf Hauk \n# Alexandre Gramfort \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\nfrom mne.minimum_norm import (\n get_cross_talk,\n get_point_spread,\n make_inverse_resolution_matrix,\n)\n\nprint(__doc__)\n\ndata_path = sample.data_path()\nsubjects_dir = data_path / \"subjects\"\nmeg_path = data_path / \"MEG\" / \"sample\"\nfname_fwd = meg_path / \"sample_audvis-meg-eeg-oct-6-fwd.fif\"\nfname_cov = meg_path / \"sample_audvis-cov.fif\"\nfname_evo = meg_path / \"sample_audvis-ave.fif\"\n\n# read forward solution\nforward = mne.read_forward_solution(fname_fwd)\n# forward operator with fixed source orientations\nmne.convert_forward_solution(forward, surf_ori=True, force_fixed=True, copy=False)\n\n# noise covariance matrix\nnoise_cov = mne.read_cov(fname_cov)\n\n# evoked data for info\nevoked = mne.read_evokeds(fname_evo, 0)\n\n# make inverse operator from forward solution\n# free source orientation\ninverse_operator = mne.minimum_norm.make_inverse_operator(\n info=evoked.info, forward=forward, noise_cov=noise_cov, loose=0.0, depth=None\n)\n\n# regularisation parameter\nsnr = 3.0\nlambda2 = 1.0 / snr**2\n\n# compute resolution matrix for sLORETA\nrm_lor = make_inverse_resolution_matrix(\n forward, inverse_operator, method=\"sLORETA\", lambda2=lambda2\n)\n\n# get PSF and CTF for sLORETA at one vertex\nsources = [1000]\n\nstc_psf = get_point_spread(rm_lor, forward[\"src\"], sources, norm=True)\n\nstc_ctf = get_cross_talk(rm_lor, forward[\"src\"], sources, norm=True)\ndel rm_lor" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualize\nPSF:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Which vertex corresponds to selected source\nvertno_lh = forward[\"src\"][0][\"vertno\"]\nverttrue = [vertno_lh[sources[0]]] # just one vertex\n\n# find vertices with maxima in PSF and CTF\nvert_max_psf = vertno_lh[stc_psf.data.argmax()]\nvert_max_ctf = vertno_lh[stc_ctf.data.argmax()]\n\nbrain_psf = stc_psf.plot(\"sample\", \"inflated\", \"lh\", subjects_dir=subjects_dir)\nbrain_psf.show_view(\"ventral\")\nbrain_psf.add_text(0.1, 0.9, \"sLORETA PSF\", \"title\", font_size=16)\n\n# True source location for PSF\nbrain_psf.add_foci(\n verttrue, coords_as_verts=True, scale_factor=1.0, hemi=\"lh\", color=\"green\"\n)\n\n# Maximum of PSF\nbrain_psf.add_foci(\n vert_max_psf, coords_as_verts=True, scale_factor=1.0, hemi=\"lh\", color=\"black\"\n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "CTF:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "brain_ctf = stc_ctf.plot(\"sample\", \"inflated\", \"lh\", subjects_dir=subjects_dir)\nbrain_ctf.add_text(0.1, 0.9, \"sLORETA CTF\", \"title\", font_size=16)\nbrain_ctf.show_view(\"ventral\")\nbrain_ctf.add_foci(\n verttrue, coords_as_verts=True, scale_factor=1.0, hemi=\"lh\", color=\"green\"\n)\n\n# Maximum of CTF\nbrain_ctf.add_foci(\n vert_max_ctf, coords_as_verts=True, scale_factor=1.0, hemi=\"lh\", color=\"black\"\n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The green spheres indicate the true source location, and the black\nspheres the maximum of the distribution.\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 }