{ "cells": [ { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "EEG leadfield computation - On all ROI elements\n", "===============================================\n", "\n", "The leadfield matrix can be computed on different source spaces in *shamo*. In this example, we consider all the elements of the region of interest as potential dipoles.\n", "\n", "The first step is to load the finite element model created before." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from shamo import FEM\n", "\n", "model = FEM.load(\"../../derivatives/fem_from_labels/fem_from_labels.json\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import logging\n", "import sys\n", "\n", "logger = logging.getLogger(\"shamo\")\n", "handler = logging.StreamHandler(sys.stdout)\n", "handler.setFormatter(logging.Formatter(\"[{levelname}] {message}\", style=\"{\"))\n", "logger.addHandler(handler)\n", "logger.setLevel(logging.INFO)" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Then we import the :py:class:`~shamo.eeg.ProbEEGLeadfield` class and instatiate it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from shamo.eeg import ProbEEGLeadfield\n", "\n", "problem = ProbEEGLeadfield()" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Electrical conductivity definition\n", "----------------------------------\n", "\n", "The electrical conductivity of the tissues is stored in a :py:class:`~shamo.core.problems.single.components.tissue_property.CompTissueProp` instance providing the :py:func:`~shamo.core.problems.single.components.tissue_property.CompTissueProp.set` and :py:func:`~shamo.core.problems.single.components.tissue_property.CompTissueProp.sets` methods that can be used to define the values of :math:`\\sigma`.\n", "\n", ".. note::\n", "\n", " The electrical conductivity is defined in Sm:math:`^{-1}`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "problem.sigmas.set(\"scalp\", 0.4137)\n", "problem.sigmas.set(\"gm\", 0.4660)\n", "problem.sigmas.set(\"wm\", 0.2126)" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Electrodes definition\n", "---------------------\n", "\n", "To compute the leadfield matrix on an element basis as described in :footcite:`weinstein_lead_2000`, a reference electrode must be set. The reference is stored in a :py:class:`~shamo.core.problems.single.components.sensors.CompSensors` instance and must be defined with the :py:func:`~shamo.core.problems.single.components.sensors.CompSensors.add` method." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "problem.reference.add(\"IZ\")" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Optionally, inactive electrodes can be listed to make sure no computation is performed for them. As for the reference, they can be added with the :py:func:`~shamo.core.problems.single.components.sensors.CompSensors.add` method. If multiple markers must be added, the :py:func:`~shamo.core.problems.single.components.sensors.CompSensors.adds` function is also available." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "problem.markers.adds([\"NZ\", \"LeftEar\", \"RightEar\"])" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Region of interest definition\n", "-----------------------------\n", "\n", "The last parameter for the problem is the region of interest. The tissues to compute the leadfield for are stored in a :py:class:`~shamo.core.problems.single.components.tissues.CompTissues` instance and can be added with the :py:func:`~shamo.core.problems.single.components.tissues.CompTissues.add` and :py:func:`~shamo.core.problems.single.components.tissues.CompTissues.adds` functions." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "problem.rois.add(\"gm\")" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Problem resolution\n", "------------------\n", "\n", "Now that the problem is fully defined, we just have to solve it and set a name and a directory for the output." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "solution = problem.solve(\"single_ssp-elems\", \"../../derivatives/eeg_leadfield\", model)" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. footbibliography::" ] } ], "metadata": { "kernelspec": { "display_name": "shamo", "language": "python", "name": "shamo" }, "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }