{ "cells": [ { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "EEG parametric leadfield computation - On regular grid\n", "======================================================\n", "\n", "This example will not be explained as all the required information is already available in the other tutorials. It simply shows that the regular grid source space can be used for the parametric solution." ] }, { "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": [ "from shamo.eeg import ProbParamEEGLeadfield\n", "\n", "problem = ProbParamEEGLeadfield()" ] }, { "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": "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": [ "import nibabel as nib\n", "from nilearn.image import crop_img\n", "\n", "img = nib.load(model.nii_path)\n", "mask = img.get_fdata() == 2\n", "mask_img = nib.Nifti1Image(mask.astype(int), img.affine)\n", "mask_img = crop_img(mask_img)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "problem.grid.set(\n", " mask_img.affine, \n", " mask_img.shape, \n", " mask=mask_img.get_fdata().astype(bool)\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "solution = problem.solve(\"parametric_ssp-grid\", \"../../derivatives/eeg_leadfield\", model, n_evals=4, method=\"multiprocessing\", n_proc=4)" ] } ], "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 }