def is_flat(tree, tol, method='tolerance'): '''Check if neurite is flat using the given method Input tree : the 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(tree) if method == 'ratio': sorted_ext = np.sort(ext) return sorted_ext[0] / sorted_ext[1] < float(tol) else: return any(ext < float(tol))
def test_principal_direction_extent(): points = np.array([[-10., 0., 0.], [-9., 0., 0.], [9., 0., 0.], [10., 0., 0.]]) tree = Tree(np.array([points[0][0], points[0][1], points[0][2], 1., 0., 0.])) tree.add_child(Tree(np.array([points[1][0], points[1][1], points[1][2], 1., 0., 0.]))) tree.children[0].add_child(Tree(np.array([points[2][0], points[2][1], points[2][2], 1., 0., 0.]))) tree.children[0].add_child(Tree(np.array([points[3][0], points[3][1], points[3][2], 1., 0., 0.]))) extent = mtr.principal_direction_extent(tree) nt.assert_true(np.allclose(extent, [20., 0., 0.]))