Forward model#
This module may be employed to calculate the forward model for the source reconstruction.
- src_rec.fwd_mdl.compute(cort_mdl, coreg, rec_meta_info, bem_model, _mag_factor=1e-07)#
Calculates the forward model according to Mosher et al, 1999.
- 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).
- 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:
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)
rec_meta_info (mne.io.read_info) – MEG scan meta info, obtailable via mne.io.read_info
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).
- Returns:
fwd_sol – Forward model, projecting from sen into src space.
- Return type:
Var_type, shape(meg_ch_cnt, valid_vtx_cnt * 3)
- src_rec.fwd_mdl.restrict(cort_mdl, fwd_sol, coreg)#
Transforms a fwd model into surface orientation (orthogonal to the respective surface cluster; allowing for cortically constrained inverse modeling) and shrinks it 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._get_meg_coil_info(rec_meta_info, coreg)#
Accumulates spatial information on MEG sensor position.
- Parameters:
rec_meta_info (mne.io.read_info) – MEG scan meta info, obtailable via mne.io.read_info
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:
rmags (numpy.ndarray, shape(meg_ch_integration_pt_cnt, 3)) – 3D positions of MEG coil integration points (MEG space).
cosmags (numpy.ndarray, shape(meg_ch_integration_pt_cnt, 3)) – Direction of the MEG coil integration points (MEG space).
rmags_mri (numpy.ndarray, shape(meg_ch_integration_pt_cnt, 3)) – 3D positions of MEG coil integration points (MRI space).
cosmags_mri (numpy.ndarray, shape(meg_ch_integration_pt_cnt, 3)) – Direction of the MEG coil integration points (MRI 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.
meg_ch_cnt (integer) – Number of MEG channels.
- src_rec.fwd_mdl._get_meg_coil_positions(rec_meta_info, meg_to_mri_trans)#
Gets MEG coil spatial information, such as coils’ individual integration points (rmag), their directions (cosmag), and weights for these integration points.
- Parameters:
rec_meta_info (mne.io.read_info) – MEG scan meta info, obtailable via mne.io.read_info
meg_to_mri_trans (numpy.ndarray, shape(4, 4)) – Transformation from MEG to MRI space.
- Returns:
meg_chs – MEG channel specific information.
- Return type:
dict, (‘coil_type’, ‘rmag’, ‘cosmag’, ‘w’, ‘ch_trans’, ‘rmag_mri’, ‘cosmag_mri’)
- src_rec.fwd_mdl._comp_src_sen_contrib(bem_model, rmags_mri, cosmags_mri, ws, meg_ch_indices, meg_ch_cnt, conductivity=(0.3,))#
Calculates the contribution of each current source (BEM normals) towards to each MEG sensor. Based on Mosher, 1999, formula #3 µ/(4*pi)(normals x tau)/norm³ … extended with additional weights for MEG coil direction, MEG coil weight Integration simplified as multiplication with surface area, see “Multiple Interface Brain and Head Models for EEG: A Surface Charge Approach”, Solis and Papandreou-Suppappola
- 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).
rmags_mri (numpy.ndarray, shape(meg_ch_integration_pt_cnt, 3)) – 3D positions of MEG coil integration points (MRI space).
cosmags_mri (numpy.ndarray, shape(meg_ch_integration_pt_cnt, 3)) – Direction of the MEG coil integration points (MRI 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.
meg_ch_cnt (integer) – Number of MEG channels.
- Returns:
src_sen_contrib (numpy.ndarray,)
Contribution of each current source towards each sensor.
- src_rec.fwd_mdl._calc_magnetic_fields(white_vertices_mri, reduced_in_skull_vert, meg_to_mri_r, pre_fwd_solution)#
Computes infinite medium potentials.
- Parameters:
white_vertices_mri (numpy.ndarray, shape(valid_white_vtx_cnt, 3)) – White matter vertices.
reduced_in_skull_vert (numpy.ndarray, shape(reduced_in_skull_vtx_cnt, 3)) – Inner skull model vertices.
meg_to_mri_trans (numpy.ndarray, shape(4, 4)) – Transformatio matrix from the coregistration.
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, rmags, cosmags, ws, meg_ch_indices)#
Adds 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_infos (list of dictionaries, ('coil_type', 'rmag', 'cosmag', 'w', 'ch_trans', 'rmag_mri', 'cosmag_mri')) – MEG recording meta into.
rmags (numpy.ndarray, shape(meg_ch_integration_pt_cnt, 3)) – 3D positions of MEG coil integration points (MEG space).
cosmags (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, rmags, cosmags)#
Calculates the magnetic field at a vortex from all MEG sensors.
- Parameters:
vortex (numpy.ndarray, shape(3,)) – Position of the vortex
rmags (numpy.ndarray, shape(meg_chs_integration_pt_cnt, 3)) – 3D positions of MEG coil integration points (MEG space)
cosmags (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)#
Generatoes 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)#
Identifies 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:
cluster_grp (list, len(n,)) – Transformed surface model.
cluster_indices (list, len(n,)) – Transformed surface model.