{ "cells": [ { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "EEG parametric leadfield computation - On all ROI elements\n", "==========================================================\n", "\n", "The computation of a parametric solution for the EEG leadfield matrix takes almost the same parameters as the single problem.\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": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Next, we import the :py:class:`~shamo.eeg.leadfield.parametric.problem.ProbParamEEGLeadfield` class and create an instance of it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from shamo.eeg import ProbParamEEGLeadfield\n", "\n", "problem = ProbParamEEGLeadfield()" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "As for the single problem, we must set the electrical conductivity of the tissues but this time, we must provide probability distributions. If a parameter is fixed, the :py:class:`~shamo.core.distributions.constant.DistConstant` can be used. Otherwise, we can pick from the following probability laws:\n", "\n", "* :py:class:`~shamo.core.distributions.uniform.DistUniform`\n", "* :py:class:`~shamo.core.distributions.normal.DistNormal`\n", "* :py:class:`~shamo.core.distributions.normal.DistTruncNormal`\n", "\n", "For the sake of this example, we only use uniform distributions and define the ranges with the values reported in :footcite:`mccann_variation_2019`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from shamo import DistUniform\n", "\n", "problem.sigmas.set(\"scalp\", DistUniform(0.137, 2.1))\n", "problem.sigmas.set(\"gm\", DistUniform(0.06, 2.47))\n", "problem.sigmas.set(\"wm\", DistUniform(0.0646, 0.81))" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "The electrodes and the regions of interest are set as for the :py:class:`~shamo.eeg.leadfield.single.problem.ProbEEGLeadfield`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "problem.reference.add(\"IZ\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "problem.markers.adds([\"NZ\", \"LeftEar\", \"RightEar\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "problem.rois.add(\"gm\")" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Finally, we can solve the problem to generate `n_evals` sub-solutions. The `method` parameter determines how the solutions are solved:\n", "\n", "* `\"sequential\"` means each solution is computed one at a time.\n", "* `\"multiprocessing\"` means `n_proc` solutions are computed in parallel on the same computing node.\n", "* `\"jobs\"` means a python script is generated for every sub-solution. Those scripts can be run in any way we like, on a HPC unit or on the computer. If this solution is chosen, the :py:func:`~shamo.eeg.leadfield.parametric.problem.ProbParamEEGLeadfield.finalize` method must be called after all the sub-solutions are generated." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "solution = problem.solve(\"parametric_ssp-elems\", \"../../derivatives/eeg_leadfield\", model, n_evals=4, method=\"multiprocessing\", n_proc=4)" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "We now have multiple sub-solutions accessible with a single parametric solution. To really use the power of those results, we still have to generate a surrogate model.\n", "\n", ".. 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 }