EEG leadfield computation - On regular grid

The leadfield matrix can be computed on different source spaces in shamo. In this example, we compute it on a regular grid that can be processed as a NIFTI image.

The first steps are the same as in the previous example.

[ ]:
import logging
import sys

logger = logging.getLogger("shamo")
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter("[{levelname}] {message}", style="{"))
logger.addHandler(handler)
logger.setLevel(logging.INFO)
[ ]:
from shamo import FEM

model = FEM.load("../../derivatives/fem_from_labels/fem_from_labels.json")
[ ]:
from shamo.eeg import ProbEEGLeadfield

problem = ProbEEGLeadfield()
[ ]:
problem.sigmas.set("scalp", 0.4137)
problem.sigmas.set("gm", 0.4660)
problem.sigmas.set("wm", 0.2126)
[ ]:
problem.reference.add("IZ")
[ ]:
problem.markers.adds(["NZ", "LeftEar", "RightEar"])

Grid definition

The grid is stored as a CompGridSampler instance. It provides the set() method which requires an affine matrix and a shape. An additional mask can be set to reduce the region of interest.

[ ]:
import nibabel as nib
from nilearn.image import crop_img

img = nib.load(model.nii_path)
mask = img.get_fdata() == 2
mask_img = nib.Nifti1Image(mask.astype(int), img.affine)
mask_img = crop_img(mask_img)
[ ]:
problem.grid.set(
    mask_img.affine,
    mask_img.shape,
    mask=mask_img.get_fdata().astype(bool)
)
[ ]:
solution = problem.solve("single_ssp-grid", "../../derivatives/eeg_leadfield", model)