def principal_direction_extent(tree): '''Calculate the extent of a tree, that is the maximum distance between the projections on the principal directions of the covariance matrix of the x,y,z points of the nodes of the tree. Input: tree : a tree object Returns: extents : the extents for each of the eigenvectors of the cov matrix eigs : eigenvalues of the covariance matrix eigv : respective eigenvectors of the covariance matrix ''' # extract the x,y,z coordinates of all the points in the tree points = np.array([p.value[COLS.X: COLS.R] for p in tree.ipreorder()]) return mm.principal_direction_extent(points)
def is_flat(neurite, tol, method='tolerance'): '''Check if neurite is flat using the given method Args: neurite(Neurite): neurite to operate on tol(float): tolerance method(string): the method of flatness estimation: 'tolerance' returns true if any extent of the tree is smaller than the given tolerance 'ratio' returns true if the ratio of the smallest directions is smaller than tol. e.g. [1,2,3] -> 1/2 < tol Returns: True if neurite is flat ''' ext = principal_direction_extent(neurite.points[:, COLS.XYZ]) assert method in ('tolerance', 'ratio'), "Method must be one of 'tolerance', 'ratio'" if method == 'ratio': sorted_ext = np.sort(ext) return sorted_ext[0] / sorted_ext[1] < float(tol) return any(ext < float(tol))
def is_flat(neurite, tol, method='tolerance'): """Check if neurite is flat using the given method. Args: neurite(Neurite): neurite to operate on tol(float): tolerance method(string): the method of flatness estimation: 'tolerance' returns true if any extent of the tree is smaller than the given tolerance 'ratio' returns true if the ratio of the smallest directions is smaller than tol. e.g. [1,2,3] -> 1/2 < tol Returns: True if neurite is flat """ ext = principal_direction_extent(neurite.points[:, COLS.XYZ]) assert method in ('tolerance', 'ratio'), "Method must be one of 'tolerance', 'ratio'" if method == 'ratio': sorted_ext = np.sort(ext) return sorted_ext[0] / sorted_ext[1] < float(tol) return any(ext < float(tol))
def is_flat(neurite, tol, method='tolerance'): '''Check if neurite is flat using the given method Input: neurite : the neurite tree object tol : tolerance method : the method of flatness estimation. 'tolerance' returns true if any extent of the tree is smaller than the given tolerance 'ratio' returns true if the ratio of the smallest directions is smaller than tol. e.g. [1,2,3] -> 1/2 < tol Returns: True if it is flat ''' ext = principal_direction_extent(neurite.points[:, :3]) if method == 'ratio': sorted_ext = np.sort(ext) return sorted_ext[0] / sorted_ext[1] < float(tol) else: return any(ext < float(tol))
def _pde(neurite): '''Get the PDE of a single neurite''' # Get the X, Y,Z coordinates of the points in each section points = neurite.points[:, :3] return morphmath.principal_direction_extent(points)[direction]
def _pde(neurite): """Get the PDE of a single neurite""" # Get the X, Y,Z coordinates of the points in each section points = neurite.points[:, :3] return morphmath.principal_direction_extent(points)[direction]
def _pde(neurite): '''Get the PDE of a single neurite''' # Get the X, Y,Z coordinates of the points in each section points = neurite.points[:, :3] return mm.principal_direction_extent(points)[direction]