Forward model#
This module may be employed to calculate the forward model for the source reconstruction.
- src_rec.fwd_mdl.compute(bem_mdl, cort_mdl, coreg, signal_type, rec_info=None, _mag_factor=1e-07, conductivity=None)#
Calculate the forward model according to Mosher et al, 1999.
- Parameters:
bem_mdl (finnpy.src_rec.bem_mdl.BEM_mdl) –
Container class, populed with the following items:
- vertnumpy.ndarray, shape(scaled_vtx_cnt, 3)
Remaining Vertices of a skin/skull model vertices.
- facesnumpy.ndarray, shape(scaled_face_cnt, 3)
Remaining Vertices of a skin/skull model faces.
- faces_normalnumpy.ndarray, shape(scaled_face_cnt, 3)
Normals of the individual remaining inner skull faces.
- faces_areanumpy.ndarray, shape(scaled_face_cnt)
Surface area of the remaining faces.
- bem_solutionnumpy.ndarray, shape(scaled_vtx_cnt, scaled_vtx_cnt)
BEM solution (preliminary step for the calculation of the forward model).
cort_mdl (finnpy.src_rec.cort_mdl.Cort_mdl) –
Container populated with the following items:
- lh_vertnumpy.ndarray, shape(lh_vtx_cnt, 3)
White matter surface model vertices (left hemisphere).
- lh_facesnumpy.ndarray, shape(lh_face_cnt, 3)
White matter surface model faces (left hemisphere).
- rh_vertnumpy.ndarray, shape(rh_vtx_cnt, 3)
White matter surface model vertices (right hemisphere).
- rh_facesnumpy.ndarray, shape(rh_face_cnt, 3)
White matter surface model faces (right hemisphere).
- lh_sphere_vertnumpy.ndarray, shape(lh_sphere_vtx_cnt, 3)
Spherical freesurfer head model vertices (left hemisphere).
- rh_sphere_vertnumpy.ndarray, shape(rh_sphere_vtx_cnt, 3)
Spherical freesurfer head model vertices (right hemisphere).
coreg (finnpy.src_rec.coreg.Coreg) –
Container class, populed with the following items:
- Used in EEG:
- closest_pts_nasnumpy.ndarray, shape(3, )
Closest points to the nas on the MRI.
- closest_pts_lpanumpy.ndarray, shape(3, )
Closest points to the lpa on the MRI.
- closest_pts_rpanumpy.ndarray, shape(3, )
Closest points to the rpa on the MRI.
- closest_pts_eegnumpy.ndarray, shape(eeg_ch_cnt, )
Closest points to the eeg positions on the MRI.
- Used in MEG:
- rotorsnumpy.ndarray, shape(9,)
Sequence of rotors defining rotation (3), translation (3) and scaling (3).
- mri_to_meeg_trsnumpy.ndarray, shape(4, 4)
Full affine transformation matrix (MRI -> MEEG)
- mri_to_meeg_trnumpy.ndarray, shape(4, 4)
Rigid affine transformation matrix (MRI -> MEEG)
- mri_to_meeg_rsnumpy.ndarray, shape(4, 4)
Rotation & scaling only affine transformation matrix (MRI -> MEEG)
- mri_to_meeg_rnumpy.ndarray, shape(4, 4)
Rotation only affine transformation matrix (MRI -> MEEG)
- meeg_to_mri_trsnumpy.ndarray, shape(4, 4)
Full affine transformation matrix (MEEG -> MRI)
- meeg_to_mri_trnumpy.ndarray, shape(4, 4)
Rigid affine transformation matrix (MEEG -> MRI)
- meeg_to_mri_rsnumpy.ndarray, shape(4, 4)
Rotation & scaling only affine transformation matrix (MEEG -> MRI)
- meeg_to_mri_rnumpy.ndarray, shape(4, 4)
Rotation only affine transformation matrix (MEEG -> MRI)
signal_type (string) – Either ‘EEG’ or ‘MEG’.
rec_info (string if signal_type == "MEG" else tuple(string, list(string))) – If MEG, path to the fif.file If EEG, tuple of EEG setup name (either 1010 or 1020) and a list of valid eeg channel names.
_mag_factor (float) – MEG scaling factor.
conductivity (np.ndarray, shape(3, ) or shape(1, ) or None) – Conductivity values for the individual surfaces. If None, defaults to (.3) for MEG and (.3, .006, .3) for EEG.
- Returns:
fwd_sol – Forward model, projecting from sen into src space.
- Return type:
Var_type, shape(meeg_ch_cnt, valid_vtx_cnt * 3)
- src_rec.fwd_mdl.restrict(cort_mdl, fwd_sol, coreg)#
Transform a fwd model into surface orientation and shrinks it.
From orthogonal to the respective surface cluster, allowing for cortically constrained inverse modeling. Shrinking is achieved by making closeby channels project to the same destination. This is different from a ‘default’ 3D transformation.
- Parameters:
cort_mdl (finnpy.src_rec.cort_mdl.Cort_mdl) –
Container populated with the following items:
- lh_vertnumpy.ndarray, shape(lh_vtx_cnt, 3)
White matter surface model vertices (left hemisphere).
- lh_facesnumpy.ndarray, shape(lh_face_cnt, 3)
White matter surface model faces (left hemisphere).
- lh_valid_vertnumpy.ndarray, shape(lh_vtx_cnt,)
Valid flags for white matter surface model vertices (left hemisphere).
- rh_vertnumpy.ndarray, shape(rh_vtx_cnt, 3)
White matter surface model vertices (right hemisphere).
- rh_facesnumpy.ndarray, shape(rh_face_cnt, 3)
White matter surface model faces (right hemisphere).
- lh_valid_vertnumpy.ndarray, shape(rh_vtx_cnt,)
Valid flags for white matter surface model vertices (right hemisphere).
- octa_model_vertnumpy.ndarray, shape(octa_mdl_vtx_cnt, 3)
Octamodel vertices (left hemisphere).
- octa_model_facesnumpy.ndarray, shape(octa_mdl_face_cnt, 3)
Octamodel faces (right hemisphere).
fwd_sol (numpy.ndarray, shape(meg_ch_cnt, valid_vtx_cnt * 3)) – Forward solution with default orientation.
coreg (finnpy.src_rec.coreg.Coreg) –
Container class, populed with the following items:
rotors : numpy.ndarray, shape(9,) Sequence of rotors defining rotation (3), translation (3) and scaling (3).
mri_to_meg_trs : numpy.ndarray, shape(4, 4) Full affine transformation matrix (MRI -> MEG) mri_to_meg_tr : numpy.ndarray, shape(4, 4) Rigid affine transformation matrix (MRI -> MEG) mri_to_meg_rs : numpy.ndarray, shape(4, 4) Rotation & scaling only affine transformation matrix (MRI -> MEG) mri_to_meg_r : numpy.ndarray, shape(4, 4) Rotation only affine transformation matrix (MRI -> MEG)
meg_to_mri_trs : numpy.ndarray, shape(4, 4) Full affine transformation matrix (MEG -> MRI) meg_to_mri_tr : numpy.ndarray, shape(4, 4) Rigid affine transformation matrix (MEG -> MRI) meg_to_mri_rs : numpy.ndarray, shape(4, 4) Rotation & scaling only affine transformation matrix (MEG -> MRI) meg_to_mri_r : numpy.ndarray, shape(4, 4) Rotation only affine transformation matrix (MEG -> MRI)
- Returns:
fwd_sol * rot – Transformed surface model.
- Return type:
numpy.ndarray, shape(meg_ch_cnt, valid_vtx_cnt)
- src_rec.fwd_mdl._calc_magnetic_fields(white_vertices_mri, all_bem_verts, meg_to_mri_r, pre_fwd_solution)#
Compute infinite medium potentials.
- Parameters:
white_vertices_mri (numpy.ndarray, shape(valid_white_vtx_cnt, 3)) – White matter vertices.
all_bem_verts (numpy.ndarray, shape(bem_vtx_cnt, 3)) – Inner skull model vertices.
meg_to_mri_r (numpy.ndarray, shape(4, 4)) – Transformatio matrix from the coregistration, rotation only.
pre_fwd_solution (numpy.ndarray, shape(meg_ch_cnt, reduced_in_skull_vtx_cnt)) – Fwd solution precursor.
- Returns:
fwd_sol – Forward solution with infinite medium potentials.
- Return type:
numpy.ndarray, shape(valid_white_vtx_cnt * 3, meg_ch_cnt)
- src_rec.fwd_mdl._add_current_distribution(fwd_sol, white_vertices, meg_ch_cnt, sen_locs, sen_dirs, ws, meg_ch_indices)#
Add current distribution to the MEG forward solution.
- Parameters:
fwd_sol (numpy.ndarray, shape(number_of_valid_vertices * 3, meg_ch_cnt)) – Previously calcualted (preliminary) forward solution.
white_vertices (numpy.ndarray, shape(number_of_valid_vertices, 3)) – Valid white matter vertices.
meg_ch_cnt (int) – Number of MEG channels.
sen_locs (numpy.ndarray, shape(meg_ch_integration_pt_cnt, 3)) – 3D positions of MEG coil integration points (MEG space).
sen_dirs (numpy.ndarray, shape(meg_ch_integration_pt_cnt, 3)) – Direction of the MEG coil integration points (MEG space).
ws (Var_type, shape(meg_ch_integration_pt_cnt,)) – Weights for MEG coil integration points.
meg_ch_indices (Var_type, shape(meg_ch_integration_pt_cnt,)) – Indices of MEG channels.
- Returns:
fwd_sol – Forward solution with current distribution.
- Return type:
numpy.ndarray, shape(number_of_valid_vertices * 3, meg_ch_cnt)
- src_rec.fwd_mdl._calc_bem_fields(vortex, sen_locs, sen_dirs)#
Calculate the magnetic field at a vortex from all MEG sensors.
- Parameters:
vortex (numpy.ndarray, shape(3,)) – Position of the vortex
sen_locs (numpy.ndarray, shape(meg_chs_integration_pt_cnt, 3)) – 3D positions of MEG coil integration points (MEG space)
sen_dirs (numpy.ndarray, shape(meg_chs_integration_pt_cnt, 3)) – Direction of the MEG coil integration points (MEG space)
- Returns:
fields – The magnetic field of all MEG sensors at a vortex.
- Return type:
numpy.ndarray, shape(1, 3, meg_chs_integration_pt_cnt)
- src_rec.fwd_mdl._calc_acc_hem_normals(white_vert, white_faces)#
Generate vertex normals from accumulated face normals.
See https://en.wikipedia.org/wiki/Vertex_normal.
- Parameters:
white_vert (numpy.ndarray, shape(vert_cnt, 3)) – MRI model vertices.
white_faces (numpy.ndarray, shape(face_cnt, 3)) – MRI model faces.
- Returns:
acc_normals – Array of surface normals for the input faces/vertices.
- Return type:
numpy.ndarray, shape(vert_cnt, 3)
- src_rec.fwd_mdl._find_vertex_clusters(white_vert, valid_vert, white_faces)#
Identify which input vertices (white_vert) are presented by which valid vortex.
- Parameters:
white_vert (numpy.ndarray, shape(lh_vert_cnt, 3)) – MRI model vertices.
valid_vert (numpy.ndarray, shape(lh_vert_cnt,)) – Valid/supporting vertices.
white_faces (numpy.ndarray, shape(lh_face_cnt, 3)) – MRI model faces.
- Returns:
result –
- cluster_grplist, len(n,)
Transformed surface model.
- cluster_indiceslist, len(n,)
Transformed surface model.
- Return type:
tuple of (list, list)