Utils¶
-
morphopy.neurontree.utils.angle_between(v1, v2)[source]¶ Returns the angle in radians between vectors ‘v1’ and ‘v2’:
>>> angle_between((1, 0, 0), (0, 1, 0)) 1.5707963267948966 >>> angle_between((1, 0, 0), (1, 0, 0)) 0.0 >>> angle_between((1, 0, 0), (-1, 0, 0)) 3.141592653589793
Parameters: - v1 – numpy.array d-dimensional vector
- v2 – numpy.array d-dimensional vector
Returns: theta - float angle btw v1 and v2 in radians
-
morphopy.neurontree.utils.commuteDist(A)[source]¶ Returns the commute distance within a graph given by adjacency matrix A
Parameters: A – adjacency matrix (NxN) Returns: B (NxN) containing the commute distances from each node to each other
-
morphopy.neurontree.utils.computeStat(statType, W, d, maxDist)[source]¶ computes a graph key on (sub)graph given by W
Parameters: - statType – string ‘maxDist’ : maximal distance ‘maxDist_norm’ : normalized maximal distance ‘meanEdgeLength’ : mean edge length ‘meanEdgeLength_norm’ : normalized mean edge length ‘4starMotif’ : 4 star motif ‘branchPoints’ : number of branch points
- W – (KxK) adjacency matrix of graph
- d – (Kx1) shortest path distances of nodes in W
- maxDist – float maximal shortest path distance in graph of which W is a sub-graph of.
Returns: stat: float key calculated according to statType
-
morphopy.neurontree.utils.eulerAnglesToRotationMatrix(theta)[source]¶ Calculates the rotation matrix from given euler angles
Parameters: theta – 3D vector with eulerangles for x,y and z axis Returns: rotation matrix R [3x3]
-
morphopy.neurontree.utils.get_A(x)[source]¶ Returns matrix A. Used for rotation matrix calculation
Parameters: x – 3D numpy.array rotation axis Returns: A - 3x3 numpy.array
-
morphopy.neurontree.utils.get_axis(v1, v2)[source]¶ Returns the axis between two vectors v1 and v2
Parameters: - v1 – numpy.array d-dimensional
- v2 – numpy.array d-dimensional
Returns: axis - numpy.array d-dimensional axis btw v1 and v2
-
morphopy.neurontree.utils.get_rotation_matrix(a, b)[source]¶ Returns the rotation matrix to rotate vector a onto vector b.
Parameters: - a – numpy.array (2 or 3 dimensional)
- b – numpy.array (2 or 3 dimensional)
Returns: R (2x2 or 3x3) rotation matrix to rotate a onto b
-
morphopy.neurontree.utils.get_standardized_swc(swc, scaling=1.0, soma_radius=None, soma_center=True, pca_rot=False)[source]¶ This function collapses all soma points to a single node located at the centroid of the convex hull of the original soma nodes. It can also scale the coordinates, merge nodes into the soma that have a bigger radius than soma_radius and return the xyz coordinates of the swc file in their PCA rotation.
Parameters: - swc – swc file, as pandas.DataFrame.
- scaling – float, (default=1), allows for a uniform scaling of x, y and z
- soma_radius – float (default=None), if set, then all nodes with a radius greater or equal to soma radius are set to be somatic (type=1). In a subsequent step these nodes will be merged to one. Careful! If this radius is set too small this leads to faulty skeletons.
- soma_center – bool (default=True), if True, x,y,z are soma centered.
- pca_rot – bool (default=False), if True, the x,y,z coordinates in the given swc file are rotated into their PCA frame. Then x corresponds to the direction of highest and z to the direction of lowest variance.
Returns: pandas.DataFrame
-
morphopy.neurontree.utils.isRotationMatrix(R)[source]¶ Checks if R is a valid rotation matrix.
Parameters: R – [3x3] rotation matrix Returns: boolean. Returns True when R is a valid rotation matrix, otherwise False.
-
morphopy.neurontree.utils.rotationMatrixToEulerAngles(R)[source]¶ Calculates rotation matrix to euler angles
Parameters: R – rotation matrix [3x3] Returns: vector of euler angles (rotations around x,y and z axis)
-
morphopy.neurontree.utils.shortpathFW(A)[source]¶ Returns matrix B of shortest path distances from each node to each other node in the graph. If the graph is undirected, B will be symmetric. B[:,0] corresponds to all shortest paths from reached from node 0. Algorithm after Floyd and Warshall
Parameters: - A – adjacency matrix of a graph (NxN)
- gpu – default True. If True, calculation is performed on GPU.
Returns: B (NxN) matrix of shortest paths
-
morphopy.neurontree.utils.smooth_gaussian(data, dim, sigma=2)[source]¶ Smooths the given data using a gaussian. This method only works for stacked one or two dimensional data so far! Smoothing in 3D is not implemented.
Parameters: - data – (X,Y,N) numpy.array 1,2 or 3 dimensional.
- dim – int Dimension of the passed data. Used to determine if data is a single image or stacked.
- sigma – int The standard deviation of the smoothing gaussian used.
Returns: Xb: same dimension as the input array. Smoothed data.
-
morphopy.neurontree.utils.sphereFit(spX, spY, spZ)[source]¶ fit a sphere to X,Y, and Z data points returns the radius and center points of the best fit sphere.
Implementation by http://jekel.me/2015/Least-Squares-Sphere-Fit/
Parameters: - spX –
- spY –
- spZ –
Returns: