EEG parametric leadfield computation - On all ROI elements

The computation of a parametric solution for the EEG leadfield matrix takes almost the same parameters as the single problem.

The first step is to load the finite element model created before.

[ ]:
from shamo import FEM

model = FEM.load("../../derivatives/fem_from_labels/fem_from_labels.json")

Next, we import the ProbParamEEGLeadfield class and create an instance of it.

[ ]:
from shamo.eeg import ProbParamEEGLeadfield

problem = ProbParamEEGLeadfield()

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 DistConstant can be used. Otherwise, we can pick from the following probability laws:

For the sake of this example, we only use uniform distributions and define the ranges with the values reported in 1.

[ ]:
from shamo import DistUniform

problem.sigmas.set("scalp", DistUniform(0.137, 2.1))
problem.sigmas.set("gm", DistUniform(0.06, 2.47))
problem.sigmas.set("wm", DistUniform(0.0646, 0.81))

The electrodes and the regions of interest are set as for the ProbEEGLeadfield.

[ ]:
[ ]:
problem.markers.adds(["NZ", "LeftEar", "RightEar"])
[ ]:

Finally, we can solve the problem to generate n_evals sub-solutions. The method parameter determines how the solutions are solved:

  • “sequential” means each solution is computed one at a time.

  • “multiprocessing” means n_proc solutions are computed in parallel on the same computing node.

  • “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 finalize() method must be called after all the sub-solutions are generated.

[ ]:
solution = problem.solve("parametric_ssp-elems", "../../derivatives/eeg_leadfield", model, n_evals=4, method="multiprocessing", n_proc=4)

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.


Hannah McCann, Giampaolo Pisano, and Leandro Beltrachini. Variation in Reported Human Head Tissue Electrical Conductivity Values. Brain Topography, 32(5):825–858, September 2019. URL:, doi:10.1007/s10548-019-00710-2.