wonambi.source.linear module
Module to convert from electrode to sources using linear matrices
- class wonambi.source.linear.Linear(surf, chan, threshold=20, exponent=None, std=None)[source]
Bases:
object
Todo
both hemispheres
- wonambi.source.linear.calc_one_vert_gauss(one_vert, xyz=None, std=None)[source]
Calculate how many electrodes influence one vertex, using a Gaussian function.
- Parameters:
one_vert (ndarray) – vector of xyz position of a vertex
xyz (ndarray) – nChan X 3 with the position of all the channels
std (float) – distance in mm of the Gaussian kernel
- Returns:
ndarray – one vector with values for one vertex
- wonambi.source.linear.calc_one_vert_inverse(one_vert, xyz=None, exponent=None)[source]
Calculate how many electrodes influence one vertex, using the inverse function.
- Parameters:
one_vert (ndarray) – vector of xyz position of a vertex
xyz (ndarray) – nChan X 3 with the position of all the channels
exponent (int) – inverse law (1-> direct inverse, 2-> inverse square, 3-> inverse cube)
- Returns:
ndarray – one vector with values for one vertex
- wonambi.source.linear.calc_xyz2surf(surf, xyz, threshold=20, exponent=None, std=None)[source]
Calculate transformation matrix from xyz values to vertices.
- Parameters:
surf (instance of wonambi.attr.Surf) – the surface of only one hemisphere.
xyz (numpy.ndarray) – nChan x 3 matrix, with the locations in x, y, z.
std (float) – distance in mm of the Gaussian kernel
exponent (int) – inverse law (1-> direct inverse, 2-> inverse square, 3-> inverse cube)
threshold (float) – distance in mm for a vertex to pick up electrode activity (if distance is above the threshold, one electrode does not affect a vertex).
- Returns:
numpy.ndarray – nVertices X xyz.shape[0] matrix
Notes
This function is a helper when plotting onto brain surface, by creating a transformation matrix from the values in space (f.e. at each electrode) to the position of the vertices (used to show the brain surface).
There are many ways to move from values to vertices. The crucial parameter is the function at which activity decreases in respect to the distance. You can have an inverse relationship by specifying ‘exponent’. If ‘exponent’ is 2, then the activity will decrease as inverse square of the distance. The function can be a Gaussian. With std, you specify the width of the gaussian kernel in mm. For each vertex, it uses a threshold based on the distance (‘threshold’ value, in mm). Finally, it normalizes the contribution of all the channels to 1, so that the sum of the coefficients for each vertex is 1.
You can also create your own matrix (and skip calc_xyz2surf altogether) and pass it as attribute to the main figure. Because it’s a loop over all the vertices, this function is pretty slow, but if you calculate it once, you can reuse it. We take advantage of multiprocessing, which speeds it up considerably.
- wonambi.source.linear.gauss(x, s)