{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Compute sLORETA inverse solution on raw data\n\nCompute sLORETA inverse solution on raw dataset restricted\nto a brain label and stores the solution in stc files for\nvisualisation.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Author: 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 matplotlib.pyplot as plt\n\nimport mne\nfrom mne.datasets import sample\nfrom mne.minimum_norm import apply_inverse_raw, read_inverse_operator\n\nprint(__doc__)\n\ndata_path = sample.data_path()\nfname_inv = data_path / \"MEG\" / \"sample\" / \"sample_audvis-meg-oct-6-meg-inv.fif\"\nfname_raw = data_path / \"MEG\" / \"sample\" / \"sample_audvis_raw.fif\"\nlabel_name = \"Aud-lh\"\nfname_label = data_path / \"MEG\" / \"sample\" / \"labels\" / f\"{label_name}.label\"\n\nsnr = 1.0 # use smaller SNR for raw data\nlambda2 = 1.0 / snr**2\nmethod = \"sLORETA\" # use sLORETA method (could also be MNE or dSPM)\n\n# Load data\nraw = mne.io.read_raw_fif(fname_raw)\ninverse_operator = read_inverse_operator(fname_inv)\nlabel = mne.read_label(fname_label)\n\nraw.set_eeg_reference(\"average\", projection=True) # set average reference.\nstart, stop = raw.time_as_index([0, 15]) # read the first 15s of data\n\n# Compute inverse solution\nstc = apply_inverse_raw(\n raw, inverse_operator, lambda2, method, label, start, stop, pick_ori=None\n)\n\n# Save result in stc files\nstc.save(f\"mne_{method}_raw_inverse_{label_name}\", overwrite=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "View activation time-series\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plt.plot(1e3 * stc.times, stc.data[::100, :].T)\nplt.xlabel(\"time (ms)\")\nplt.ylabel(f\"{method} value\")\nplt.show()" ] } ], "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 }