Skip to content

Commit bb41f3d

Browse files
authored
Update forward module documentation for clarity
Clarify high-level and low-level function calls, update function names, and improve descriptions of volume conduction models and sensor transformations. WIP, but save for now because I am going for a coffee.
1 parent 30275b8 commit bb41f3d

File tree

1 file changed

+48
-34
lines changed

1 file changed

+48
-34
lines changed

development/module/forward.md

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The following forward methods are implemented for computing the magnetic field (
5252

5353
Normally, end-users of the FieldTrip toolbox would use the functions in the main FieldTrip directory and not be calling the functions that are part of the forward module directly . The high-level FieldTrip functions characterize themselves by having a cfg argument as the first input, doing data handling, conversions of objects and try to support backward-compatibility with older end-user analysis scripts.
5454

55-
Some high-level functions that are of relevance for forward modeling are
55+
Some high-level functions FieldTrip functions that are of relevance for forward modeling are
5656

5757
- **[ft_read_mri](/reference/fileio/ft_read_mri)** and **[ft_read_sens](/reference/fileio/ft_read_sens)**
5858
- **[ft_volumerealign](/reference/ft_volumerealign)**, **[ft_volumereslice](/reference/ft_volumereslice)**, and **[ft_volumesegment](/reference/ft_volumesegment)**
@@ -61,6 +61,12 @@ Some high-level functions that are of relevance for forward modeling are
6161
- **[ft_prepare_headmodel](/reference/ft_prepare_headmodel)**, this calls ft_headmodel_xxx (see below)
6262
- **[ft_prepare_leadfield](/reference/ft_prepare_leadfield)**, this calls ft_prepare_vol_sens and ft_compute_leadfield (see below)
6363

64+
In addition, there are some utility functions (residing in fieldtrip/utilities) that may be relevant, but which are not part of the module
65+
66+
- **[ft_determine_coordsys](/reference/utilities/ft_determine_coordsys)**
67+
- **[ft_convert_coordsys](/reference/utilities/ft_convert_coordsys)**
68+
- **[ft_transform_geometry](/reference/utilities/ft_transform_geometry)**
69+
6470
These are explained in more detail in the appropriate [tutorials](/tutorial).
6571

6672
## Definition of the low-level function-calls (API)
@@ -76,58 +82,61 @@ This assumes that the volume conduction model was created in external software (
7682

7783
Alternative to reading the volume conduction model from an external file, you can of course also generate a volume conduction model based on a geometrical description of the head. For example, you can fit a single or multiple spheres to a set of points that describes the head surface. FieldTrip provides a separate function for the constructing of a head model for each of the EEG/MEG computational forward method
7884

79-
[headmodel] = ft_headmodel_asa(filename, ...)
80-
[headmodel] = ft_headmodel_bem_cp(geom, ...)
81-
[headmodel] = ft_headmodel_concentricspheres(geom, ...)
82-
[headmodel] = ft_headmodel_dipoli(geom, ...)
83-
[headmodel] = ft_headmodel_halfspace(location, orientation, ...)
84-
[headmodel] = ft_headmodel_hbf(geom, ...)
85-
[headmodel] = ft_headmodel_infinite(...)
86-
[headmodel] = ft_headmodel_localspheres(geom, grad, ...)
87-
[headmodel] = ft_headmodel_openmeeg(geom, ...)
88-
[headmodel] = ft_headmodel_singleshell(geom, sens, ...)
89-
[headmodel] = ft_headmodel_singlesphere(pnt, ...)
90-
91-
Most of these functions take a geometrical description of the head, skull and/or brain surface as input. These geometrical descriptions of the shape of the head can for example be derived from an anatomical MRI, from a CT scan, or from a Polhemus measurement of the outside of the scalp. In most cases the geometrical model consists of a Nx3 matrix with surface points, which is sometimes accompanied with a description of the triangles that form the surface. The processing of the anatomical data such as MRIs to construct a geometrical model is not part of the forward module and is described elsewhere specifically for [MEG](/tutorial/headmodel_meg) and [EEG](/tutorial/headmodel_eeg).
85+
headmodel = ft_headmodel_asa(filename, ...)
86+
headmodel = ft_headmodel_bemcp(geom, ...)
87+
headmodel = ft_headmodel_concentricspheres(geom, ...)
88+
headmodel = ft_headmodel_dipoli(geom, ...)
89+
headmodel = ft_headmodel_duneuro(geom, ...)
90+
headmodel = ft_headmodel_halfspace(location, orientation, ...)
91+
headmodel = ft_headmodel_hbf(geom, ...)
92+
headmodel = ft_headmodel_infinite(...)
93+
headmodel = ft_headmodel_interpolate(filename, sens, sourcemodel, ...)
94+
headmodel = ft_headmodel_localspheres(geom, grad, ...)
95+
headmodel = ft_headmodel_openmeeg(geom, ...)
96+
headmodel = ft_headmodel_simbio(geom, ...)
97+
headmodel = ft_headmodel_singleshell(geom, sens, ...)
98+
headmodel = ft_headmodel_singlesphere(pnt, ...)
99+
100+
Most of these functions take a geometrical description of the head, skull and/or brain surface as input. These geometrical descriptions of the shape of the head can for example be derived from an anatomical MRI, from a CT scan, or from a Polhemus measurement of the outside of the scalp. In many cases the geometrical model consists of an Nx3 matrix with surface points, which is sometimes accompanied by a description of the triangles that form the scalp surface, or a set of surfaces forming tissue boundaries. For some methods the geometrical model will need to be described a volumetric mesh, i.e. an Nx3 matrix of points, accompanied by a description of volumetric elements (tetrahedra or hexahedra) and their optional conductivities. The processing of the anatomical data such as MRIs to construct a geometrical model is not part of the forward module and is described elsewhere specifically for [MEG](/tutorial/headmodel_meg) and [EEG](/tutorial/headmodel_eeg).
92101

93102
Detailed information for each of the functions that creates a head model can be found in the respective reference documentation:
94103

95104
- **[ft_headmodel_asa](/reference/forward/ft_headmodel_asa)**
96105
- **[ft_headmodel_bemcp](/reference/forward/ft_headmodel_bemcp)**
97106
- **[ft_headmodel_concentricspheres](/reference/forward/ft_headmodel_concentricspheres)**
98107
- **[ft_headmodel_dipoli](/reference/forward/ft_headmodel_dipoli)**
108+
- **[ft_headmodel_duneuro](/reference/forward/ft_headmodel_duneuro)**
99109
- **[ft_headmodel_halfspace](/reference/forward/ft_headmodel_halfspace)**
100110
- **[ft_headmodel_hbf](/reference/forward/ft_headmodel_hbf)**
101111
- **[ft_headmodel_infinite](/reference/forward/ft_headmodel_infinite)**
112+
- **[ft_headmodel_interpolate](/reference/forward/ft_headmodel_interpolate)**
102113
- **[ft_headmodel_localspheres](/reference/forward/ft_headmodel_localspheres)**
103114
- **[ft_headmodel_openmeeg](/reference/forward/ft_headmodel_openmeeg)**
115+
- **[ft_headmodel_siimbio](/reference/forward/ft_headmodel_simbio)**
104116
- **[ft_headmodel_singleshell](/reference/forward/ft_headmodel_singleshell)**
105117
- **[ft_headmodel_singlesphere](/reference/forward/ft_headmodel_singlesphere)**
106118

107-
If desired the volume conduction model and the sensor array can be spatially transformed using a 4x4 homogenous transformation matrix. e.g., the electrodes can be translated and rotated to align them with head coordinate system, or they can be translated and rotated to switch to another coordinate system.
108-
109-
[headmodel] = ft_transform_geometry(transform, headmodel)
110-
[sens] = ft_transform_geometry(transform, sens)
111-
112-
The reason for using the **[ft_transform_geometry](/reference/utilities/ft_transform_geometry)** function is that they allow you to transform any sensor type (EEG and/or MEG) and any volume conduction model without you having to manipulate the elements within the `sens` or `headmodel` structure.
119+
An important prerequisite for correct forward computations, is that the geometrical information in the relevant data objects is comparable, i.e. that they are coregistered with respect to one another, and that the metric units, and the coordinate systems in which the spatial coordinates are expressed are the same. If needed, the units and coordinate system of data objects containing geometrical information can be explored using **[ft_determine_units](/reference/forward/ft_determine_units)** and **[ft_determine_coordsys](/reference/forward/ft_determine_coordsys)**. These functions require visualization functions from the [plotting](/development/module/module). If desired, the spatial coordinates of the geometries in the data objects can be manipulated with **[ft_transform_geometry](/reference/utilities/ft_transform_geometry)**, **[ft_convert_units](/reference/forward/ft_convert_units)** and **[ft_convert_coordsys](/reference/utilities/ft_convert_coordsys)**
113120

114121
Up to here the head model only depends on the geometrical description of the volume conductor and is independent of the data, with exception of the MEG localspheres model. The consequence is that the head model can be used for multiple experimental sessions, multiple electrode or gradiometer placements, or different selections of channels for a single session. The head model, i.e. the `headmodel` structure, can be saved to disk and re-used in an analysis on the next day.
115122

116123
Following the initial set-up of the head model, but prior to the actual forward computations, the **[ft_prepare_vol_sens](/reference/forward/ft_prepare_vol_sens)** function should be called to link the head model and the sensors and make a data dependent forward model (consisting of the `headmodel` and `sens`).
117124

118125
[headmodel, sens] = ft_prepare_vol_sens(headmodel, sens, ...)
119126

120-
The **[ft_prepare_vol_sens](/reference/forward/ft_prepare_vol_sens)** function does a variety of things, depending on the peculiarities of the sensors and head model. It can be used for channel selection, which sometimes involves both the sensors and volume conduction model (e.g., in case of a localspheres MEG model). It will project EEG electrodes (which are described as a Nx3 set of points) onto the scalp surface. It will provide an interpolation of the BEM potential (which is usually computed at the vertices) onto the electrodes. In general the **[ft_prepare_vol_sens](/reference/forward/ft_prepare_vol_sens)** function tries to carry out as many preparations as possible, so that subsequently the leadfields can be computed as efficiently as possible.
127+
The **[ft_prepare_vol_sens](/reference/forward/ft_prepare_vol_sens)** function does a variety of things, depending on the peculiarities of the sensors and head model. It can be used for channel selection, which sometimes involves both the sensors and volume conduction model (e.g., in case of a localspheres MEG model). It will ensure that the positions of the EEG electrodes (which are described as a Nx3 set of points) are projected onto the scalp surface. It may provide a transfer matrix that specifies a linear mapping of the electric potential from boundary surface (BEM) or volumetric (FEM) elements onto the electrodes. In general the **[ft_prepare_vol_sens](/reference/forward/ft_prepare_vol_sens)** function tries to carry out as many preparations as possible, so that subsequently the leadfields can be computed as efficiently as possible. The computations performed by **[ft_prepare_vol_sens](/reference/forward/ft_prepare_vol_sens)** can take a long time (up to 10 hours) depending on the type and the spatial detail of the volume conduction model.
121128

122129
Finally the subsequent computation of the EEG potential or MEG field distribution is done with the **[ft_compute_leadfield](/reference/forward/ft_compute_leadfield)** function, which returns a nchan\*3 matrix or a nchan\*(3*ndipoles) matrix if you specify more than one dipole position.
123130

124131
[lf] = ft_compute_leadfield(pos, sens, headmodel, ...)
125132

126133
Most functions have additional optional input arguments that are specified as key-value pairs.
127134

128-
## Boundary element method (BEM) implementations
135+
## Dependence on external software for the computations
129136

130-
FieldTrip relies on external contributed software for the low-level computations of the BEM system matrix. The external software is included in the standard FieldTrip release in the external directory.
137+
FieldTrip relies on externally contributed software for some of the low-level computations, specifically for the BEMs and FEMs. Wrapper functions to interact with the respective external software are included in the standard FieldTrip release in the method specific external sub-directory (e.g. external/dipoli). For most of the supported methods (also for the FEMs, see below) FieldTrip either executes a compiled application as a mex-file, or executes a compiled application in a system-call. In the latter case (e.g. openmeeg), the application will always interact with (input/output and configuration) data on disk, and the FieldTrip wrapper code ensures that the relevant data and results are written and read from disk. In the case of a mex-file, some methods allow for direct interaction of the data with the compiled software. Other mex-files still require intermediate data to be written to disk. For some methods, platform-specific mex-files may be provided in the respective external folder. These mex-files may or may not work on your platform, depending on the compatibility of the system on which the mex-file was compiled and the system on which it is executed. If the mex-file fails on a specific system, some methods allow for the executable to be built from source.
138+
139+
## Boundary element method (BEM) implementations
131140

132141
### fieldtrip/external/openmeeg
133142

@@ -138,6 +147,9 @@ The MATLAB interface to the [OpenMEEG](https://openmeeg.github.io) implementatio
138147
### fieldtrip/external/bemcp
139148

140149
The bemcp implementation is kindly provided by [Christophe Phillips]([http://www2.ulg.ac.be/crc/en/cphillips.html](https://christophephillips.github.io), hence the "CP" in the name.
150+
- based on mex-files
151+
- source code is provided (in FieldTrip)
152+
-
141153

142154
### fieldtrip/external/dipoli
143155

@@ -147,26 +159,28 @@ The dipoli implementation is kindly provided by [Thom Oostendorp](http://www.mbf
147159

148160
The dipole implementation is kindly provided by [Matti Stenroos](https://github.com/MattiStenroos), and [George O'Neill](https://georgeoneill.github.io) wrote the code to directly access this method.
149161

150-
## Finite element method (FEM) implementation
151-
152-
FieldTrip makes use of external contributed software for the low-level computations of the finite element method, which is included in the standard FieldTrip release in the external directory.
162+
## Finite element method (FEM) implementations
153163

154164
### fieldtrip/external/simbio
155165

156166
The simbio implementation is kindly provided by [Carsten Wolters](http://www.uni-muenster.de/OCCMuenster/members/carsten-wolters.html) and colleagues. More information can be found [here](https://www.mrt.uni-jena.de/simbio/index.php/Main_Page).
157167

168+
### fieldtrip/external/duneuro
169+
170+
The original MATLAB interface to [DUNEuro](https://www.medizin.uni-muenster.de/duneuro/startseite.html) is kindly provided by the
171+
172+
158173
## Standard International Units
159174

160-
MATLAB allows the representation of any data in arrays, but does not have an explicit mechanism for dealing with the representation of physical properties of the numbers in those arrays. The FieldTrip data structures provide slightly more information on the units of the numbers represented in the arrays and consider
175+
The forward module functions are written such that they operate correctly if all input data to the functions is specified according to the [International System of Units](https://en.wikipedia.org/wiki/International_System_of_Units), i.e. in meter, Volt, Tesla, Ohm, Ampere, etc. The high-level FieldTrip code or any other code that calls the forward module functions (e.g., EEGLAB) is responsible for data handling and bookkeeping and for converting data stored in MATLAB arrays and structures such that the physical units conform SI units prior to passing the arrays and structures to the forward code. Also, the data objects need to coregistered with respect to each other.
176+
177+
The high level FieldTrip functions aim as much as possible to check (and where possible) adjust the units (and coordsys) of the geometries involved, using the available information in the data objects, e.g.:
161178

162-
- the geometrical properties of the volume conduction model
163-
- the conductive properties of the volume conduction model
164-
- the geometrical properties of the sensor description
165-
- the geometrical properties of the source model
166-
- the units of the channel level values (e.g., T, uV or fT/cm)
167-
- the units of of dipole strength
179+
- the geometrical properties of the volume conduction model, sourcemodel, sensor description, e.g.: `headmodel.unit`, `headmodel.coordsys`
180+
- the conductive properties of the volume conduction model (FIXME, is this true? -> safest would be always specify headmodel.cond in S/m)
181+
- the units of the channel level values (e.g., T, uV or fT/cm), `sens.chanunit`
182+
- the units of of dipole strength (FIXME, is this true?)
168183

169-
The forward module functions are written such that they operate correctly if all input data to the functions is specified according to the [International System of Units](https://en.wikipedia.org/wiki/International_System_of_Units), i.e. in meter, Volt, Tesla, Ohm, Ampere, etc. The high-level FieldTrip code or any other code that calls the forward module functions (e.g., EEGLAB) is responsible for data handling and bookkeeping and for converting MATLAB arrays and structures that represent units into SI units prior to passing the arrays and structures to the forward code.
170184

171185
## Related documentation
172186

0 commit comments

Comments
 (0)