wonambi.attr.anat module
Module to read and return anatomical information, such as: - surfaces, with class Surf - brains, with class BrainSurf (both hemispheres)
- class wonambi.attr.anat.Brain(freesurfer_dir, surf_type='pial')[source]
Bases:
object
Class that contains the left and right hemispheres.
- Parameters:
freesurfer_dir (str) – subject-specific directory created by freesurfer
surf_type (str) – ‘pial’, ‘smoothwm’, ‘inflated’, ‘white’, or ‘sphere’
- class wonambi.attr.anat.Freesurfer(freesurfer_dir, fs_lut=None)[source]
Bases:
object
Provide class Freesurfer, with the information from freesurfer.
- Parameters:
Notes
It’s necessary that Freesurfer is installed and that the environmental variable ‘FREESURFER_HOME’ is present.
- find_brain_region(abs_pos, parc_type='aparc', max_approx=None, exclude_regions=None)[source]
Find the name of the brain region in which an electrode is located.
- Parameters:
abs_pos (numpy.ndarray) – 3x0 vector with the position of interest.
parc_type (str) – ‘aparc’, ‘aparc.a2009s’, ‘BA’, ‘BA.thresh’, or ‘aparc.DKTatlas40’ ‘aparc.DKTatlas40’ is only for recent freesurfer versions
max_approx (int, optional) – max approximation to define position of the electrode.
exclude_regions (list of str or empty list) – do not report regions if they contain these substrings. None means that it does not exclude any region.
Notes
It determines the possible brain region in which one electrode is present, based on Freesurfer segmentation. You can imagine that sometimes one electrode is not perfectly located within one region, but it’s a few mm away. The parameter “approx” specifies this tolerance where each value is one mm. It keeps on searching in larger and larger spots until it finds at least one region which is not white matter. If there are multiple regions, it returns the region with the most detection. Minimal value is 0, which means only if the electrode is in the precise location.
- If you want to exclude white matter regions with ‘aparc’, use
exclude_regions = (‘White’, ‘WM’, ‘Unknown’)
- and with ‘aparc.a2009s’, use:
exclude_regions = (‘White-Matter’)
- read_brain(surf_type='pial')[source]
Read the surface of both hemispheres.
- Parameters:
surf_type (str) – ‘pial’, ‘smoothwm’, ‘inflated’, ‘white’, or ‘sphere’
- Returns:
instance of Brain – the surfaces of both brain hemispheres
- read_label(hemi, parc_type='aparc')[source]
Read the labels (annotations) for each hemisphere.
- Parameters:
hemi (str) – ‘lh’ or ‘rh’
parc_type (str) – ‘aparc’, ‘aparc.a2009s’, ‘BA’, ‘BA.thresh’, or ‘aparc.DKTatlas40’ ‘aparc.DKTatlas40’ is only for recent freesurfer versions
- Returns:
numpy.ndarray – value at each vertex, indicating the label
numpy.ndarray – RGB + alpha colors for each label
list of str – names of the labels
- read_seg(parc_type='aparc')[source]
Read the MRI segmentation.
- Parameters:
parc_type (str) – ‘aparc’ or ‘aparc.a2009s’
- Returns:
numpy.ndarray – 3d matrix with values
numpy.ndarray – 4x4 affine matrix
- property surface_ras_shift
one for volumes (“RAS”) and one for surfaces (“tkReg”, “tkRAS”, and “Surface RAS”). To get from surface to volume coordinates, add this numbers. To get from volume to surface coordinates, substract this numbers.
- Type:
Freesurfer uses two coordinate systems
- class wonambi.attr.anat.Surf(surf_file)[source]
Bases:
object
Provide class Surf, with the positions and connections of vertices.
- Parameters:
surf_file (str or Path) – freesurfer file containing the surface
- surf_file
freesurfer file containing the surface
- Type:
path to file
- vert
vertices of the mesh
- Type:
numpy.ndarray
- tri
triangulation of the mesh
- Type:
numpy.ndarray
- wonambi.attr.anat.import_freesurfer_LUT(fs_lut=None)[source]
Import Look-up Table with colors and labels for anatomical regions.
It’s necessary that Freesurfer is installed and that the environmental variable ‘FREESURFER_HOME’ is present.
- Parameters:
fs_lut (str or Path) – path to file called FreeSurferColorLUT.txt
- Returns:
idx (list of int) – indices of regions
label (list of str) – names of the brain regions
rgba (numpy.ndarray) – one row is a brain region and the columns are the RGB + alpha colors