mvpure_py.utils#

mvpure_py.utils.algebra#

Functions for computing algebraic expressions.

mvpure_py.utils.algebra.get_pinv_RN_eigenvals(R: ndarray, N: ndarray)[source]#

mvpure_py.utils.translation#

Operations on mne.Forward, mne.SourceSpaces and mapping between vertices and leadfield indices.

mvpure_py.utils.translation.map_vertices_to_fsaverage(locs, hemi: list[str] | str, surf: str = 'white')[source]#

Map vertices from subject-specific surface to fsaverage coordinates for one or both hemispheres. This function wraps _map_vertices_to_fsaverage_for_hemi and allows mapping vertices for either a single hemisphere (‘lh’ or ‘rh’) or both hemispheres simultaneously.

Parameters:
  • locs (mvpure_py.Localized) – mvpure_py.Localized object to map vertices from. After mapping, each vertex in the specified hemisphere(s) will have a new key "morphed_to_fs" storing the corresponding fsaverage vertex index.

  • hemi (list[str] | str) – Which hemisphere to map.

  • surf (str (Default: 'white')) – Surface which coordinates use during mapping.

Raises:

ValueError – If hemi is not one of [‘lh’, ‘rh’, ‘both’].

mvpure_py.utils.translation.subset_forward(old_fwd: Forward, localized, vertices: list[list[int]] | list[int] = None, hemi: str = 'both') Forward[source]#

Subset old_fwd (mne.Forward) so that it contains information only for certain vertices.

Parameters:
  • old_fwd (mne.Forward) – mne.Forward to get subset from

  • localized (mvpure_py.Localized) – mvpure_py.Localized object containing information about localized sources.

  • vertices (list[list[int]] | list[int]) – list of vertices indices to include in mne.Forward subset.

  • hemi (str) – hemisphere(s) containing the dipoles that are expected to be present in mne.Forward subset

Returns:

mne.Forward

Return type:

subset of mne.Forward for given vertices

mvpure_py.utils.translation.transform_leadfield_indices_to_vertices(lf_idx, src: SourceSpaces, hemi: str = 'both', include_mapping: bool = True)[source]#

Transform leadfield 1-axis indices into vertices number using mne.SourceSpaces

Parameters:
  • lf_idx (iterable) – Iterable with leadfield (column) indices

  • src (mne.SourceSpace) – source space from forward with corresponding leadfield

  • hemi (str (Default to "both")) – vertices from which hemisphere should be returned. Options are: ‘lh’, ‘rh’ and ‘both’.

  • include_mapping (bool) – If True, return also the indices in the original leadfield. (Useful to know which columns were used).

Returns:

vertices – markings of vertices which correspond to leadfield matrices

Return type:

list | tuple(list, list)

mvpure_py.utils.translation.transform_vertices_to_leadfield_indices(vertices: list[int] | list[list[int]], src: SourceSpaces, hemi: str, include_mapping: bool = False)[source]#

Transform vertex numbers (from mne.SourceSpace) to leadfield 1-axis indices.

Parameters:
  • vertices (list[int] | list[list[int]]) – Either a flat list of vertex numbers or [lh_vertices, rh_vertices] when hemi=’both’.

  • src (mne.SourceSpace) – Source space from forward with corresponding leadfield.

  • hemi ({'lh', 'rh', 'both'})

  • include_mapping (bool) – If True, also return mapping dicts {vertex -> lf_index} for each hemisphere.

Returns:

  • lf_idx (np.ndarray) – Leadfield column indices.

  • OR (when include_mapping=True) – (lf_idx_array, lh_vert_to_lf, rh_vert_to_lf)

mvpure_py.utils.translation.vertices_to_coordinates(vertices: list[list[int]], src: SourceSpaces)[source]#

Convert vertex indices to 3D coordinates using mne.SourceSpace.

Parameters:
  • vertices (list[list[int]]) – List of vertices for which coordinates are being obtained. First list needs to contain vertices from the left hemisphere, and second list from the right hemisphere.

  • src (mne.SourceSpace) – Source space to use.