Skip to content

Lead field generation

Santtu Söderholm edited this page Sep 8, 2023 · 11 revisions

TODO

Lead field generation via the GUI

TODO

Generating a lead field programmatically

To generate a lead field matrix programmatically, one must first start up an instance of Zeffiro Interface and capture its core struct, usually referred to as zef, so that the lead field -related fields can be modified:

% Start up Zeffiro.

zef = zeffiro_interface('start_mode', 'nodisplay');

% Set meshing-related fields.

zef.lead_field_field_1 = some_value;

...

zef.lead_field_field_N = some_value;

% Call one of the lead field generation routines.

zef = zef_lead_field_eeg_fem( ...
    zef, ...
    nodes, ...
    elements, ...
    sigma, ...
    electrodes, ...
    p_nearest_neighbour_inds, ...
    optimization_system_type, ...
    varargin ...
);

% or

zef = zef_lead_field_meg_fem( ...
    zef, ...
    nodes, ...
    elements, ...
    sigma, ...
    electrodes, ...
    p_nearest_neighbour_inds, ...
    optimization_system_type, ...
    varargin ...
);

% or

zef = zef_lead_field_meg_grad_fem( ...
    zef, ...
    nodes, ...
    elements, ...
    sigma, ...
    electrodes, ...
    p_nearest_neighbour_inds, ...
    optimization_system_type, ...
    varargin ...
);

% or

zef = zef_lead_field_tes_fem( ...
    zef, ...
    nodes, ...
    elements, ...
    sigma, ...
    electrodes, ...
    p_nearest_neighbour_inds, ...
    optimization_system_type, ...
    varargin ...
);

% or

zef = zef_lead_field_eit_fem( ...
    zef, ...
    nodes, ...
    elements, ...
    sigma, ...
    electrodes, ...
    p_nearest_neighbour_inds, ...
    optimization_system_type, ...
    varargin ...
);

% Save the project.

zef_save(zef,'zef_meshing_example.mat','data/');

The list of the meshing-related fields is given below.

Fields of zef related to lead field generation

acceptable_source_depth

size: (1,1)
type: double
validators: { mustBeNonnegative }
default value: 0

Starting from the surface of the active layers, how deep one must go before one can find sources. The point of this field is to prevent sources from appearing right next to active layer boundaries, to prevent numerical errors from occurring because of discintinuities in conductivity.

lead_field_filter_quantile

size: (1,1)
type: double
validators: { mustBeGreaterThanOrEqual( 0 ), mustBeLessThanOrEqual( 1 ) }
default value: 1

This field adjusts the quantile, above which columns would be removed from the lead field based on their column norm.

lead_field_type

size: (1,1)
type: double
validators: { mustBeMember ( [ 1, 2, 3, 4, 5 ] ) }
default value: 1

The type of lead field one wishes to compute. Here 1 ↦ EEG, 2 ↦ MEG, 3 ↦ gMEG, 4 ↦ EIT and 5 ↦ tES.

lf_normalization

size: (1,1)
type: double
validators: { mustBeMember ( [1, 2, 3, 4] ) }
default value: 1

Sets whether a lead field is normalized based on the maximum value in a column, the column norm, etc. This is possibly a legacy field related to the Lead Field Bank Tool, but it is listed here for completeness (for now).

location_unit

size: (1,1)
type: double
validators: { mustBeMember( [1,2,3]) }
default value: 1

Sets the unit of the source positions the lead field was constructed from, in relation to meters. Here 1 ↦ mm, 2 ↦ cm and 3 ↦ m.

n_sources

size: (1,1)
type: double
validators: { mustBePositive }
default value: 1e4

The number of sources that are to be generated at the start of the lead field computation. Note that this is an approximation, the goodness of which depends on the value of source_space_creation_iterations, as the placement of sources into the volume is an iterative process.

optimization_system_type

size: (1,1)
type: double
validators: { mustBeMember ( [ "pbo", "mpo" ] ) }
default value: "pbo"

This defines which type of optimization method is used when dipoles are interpolated into place, when the Whitney/Raviart–Thomas or H(div) source models are used. Here "pbo" ↦ Position-Based Optimization and "mpo" ↦ Mean Position and Orientation.

preconditioner

size: (1,1)
type: double
validators: { mustBeMember ( [1, 2] ) }
default value: 1

Defines the type of preconditioner used by the preconditioned conjugate gradient solver of the transfer matrix (lead field before adjustments). Here 1 ↦ Cholinc and 2 ↦ SSOR.

preconditioner_tolerance

size: (1,1)
type: double
validators: { mustBePositive }
default value: 0.001

Determines the numerical tolerance (accyracy) of the used preconditioner.

solver_tolerance

size: (1,1)
type: double
validators: { mustBePositive }
default value: 1e-8

Determines the accuracy of the solver during PCG iteration.

source_direction_mode

size: (1,1)
type: double
validators: { mustBeMember ( [1, 2, 3] ) }
default value: 1

Determines whether to generate use Cartesian (1), surface-normal (2) or face-based (3) sources. Note that Cartesian sources are usually utilized in literature.

source_interpolation_on

size: (1,1)
type: logical
validators: { }
default value: true

If this is false, sources will not be interpolated into a place after a lead field has been constructed.

source_model

size: (1,1)
type: core.ZefSourceModel
validators: { }
default value: core.ZefSourceModel.Hdiv

Determines which source model is to be used when generating sources. Most tested ones are core.ZefSourceModel.{Whitney,Hdiv}, so one should probably stick to these for now.

source_space_creation_iterations

size: (1,1)
type: double
validators: { mustBeInteger, mustBePositive }
default value: 10

Determines many iterations of source placements are attempted, to get to the number of sources specified by n_sources.

use_depth_electrodes

size: (1,1)
type: double
validators: { mustBeGreaterThanOrEqual( 0 ), mustBeLessThanOrEqual( 1 ) }
default value: false

This might determine how deeply electrodes or other sensors are forced into the volume conductor. Mainly used by the function zef_attach_sensors_volume.