def test_neighbor_max(): # test ability to find maxima on sphere using neighbors vert_inds = sym_hemisphere(VERTICES) adj_inds = vertinds_to_neighbors(vert_inds, FACES) # test slow and fast routine for func in (argmax_from_adj, dcr.argmax_from_adj): # all equal, no maxima vert_vals = np.zeros((N_VERTICES,)) inds = func(vert_vals, vert_inds, adj_inds) assert_equal(inds.size, 0) # just ome max for max_pos in range(3): vert_vals = np.zeros((N_VERTICES,)) vert_vals[max_pos] = 1 inds = func(vert_vals, vert_inds, adj_inds) assert_array_equal(inds, [max_pos]) # maxima outside hemisphere don't appear for max_pos in range(3,6): vert_vals = np.zeros((N_VERTICES,)) vert_vals[max_pos] = 1 inds = func(vert_vals, vert_inds, adj_inds) assert_equal(inds.size, 0) # use whole mesh, with two maxima w_vert_inds = np.arange(6) w_adj_inds = vertinds_to_neighbors(w_vert_inds, FACES) vert_vals = np.array([1.0, 0, 0, 0, 0, 2]) inds = func(vert_vals, w_vert_inds, w_adj_inds) assert_array_equal(inds, [0, 5])
def test_neighbor_max(): # test ability to find maxima on sphere using neighbors vert_inds = sym_hemisphere(VERTICES) adj_inds = vertinds_to_neighbors(vert_inds, FACES) # test slow and fast routine for func in (argmax_from_adj, dcr.argmax_from_adj): # all equal, no maxima vert_vals = np.zeros((N_VERTICES, )) inds = func(vert_vals, vert_inds, adj_inds) assert_equal(inds.size, 0) # just ome max for max_pos in range(3): vert_vals = np.zeros((N_VERTICES, )) vert_vals[max_pos] = 1 inds = func(vert_vals, vert_inds, adj_inds) assert_array_equal(inds, [max_pos]) # maxima outside hemisphere don't appear for max_pos in range(3, 6): vert_vals = np.zeros((N_VERTICES, )) vert_vals[max_pos] = 1 inds = func(vert_vals, vert_inds, adj_inds) assert_equal(inds.size, 0) # use whole mesh, with two maxima w_vert_inds = np.arange(6) w_adj_inds = vertinds_to_neighbors(w_vert_inds, FACES) vert_vals = np.array([1.0, 0, 0, 0, 0, 2]) inds = func(vert_vals, w_vert_inds, w_adj_inds) assert_array_equal(inds, [0, 5])
def test_vertinds_neighbors(): adj = neighbors(FACES) assert_array_equal(adj, [[1, 2, 3, 4], [0, 2, 4, 5], [0, 1, 3, 5], [0, 2, 4, 5], [0, 1, 3, 5], [1, 2, 3, 4]]) adj = vertinds_to_neighbors(np.arange(6), FACES) assert_array_equal(adj, [[1, 2, 3, 4], [0, 2, 4, 5], [0, 1, 3, 5], [0, 2, 4, 5], [0, 1, 3, 5], [1, 2, 3, 4]]) # subset of inds gives subset of faces adj = vertinds_to_neighbors(np.arange(3), FACES) assert_array_equal(adj, [[1, 2, 3, 4], [0, 2, 4, 5], [0, 1, 3, 5]]) # can be any subset adj = vertinds_to_neighbors(np.arange(3, 6), FACES) assert_array_equal(adj, [[0, 2, 4, 5], [0, 1, 3, 5], [1, 2, 3, 4]]) # just test right size for the real mesh vertices, faces = SPHERE_DATA n_vertices = vertices.shape[0] adj = vertinds_to_neighbors(np.arange(n_vertices), faces) assert_equal(len(adj), n_vertices) assert_equal(len(adj[1]), 6)
def test_performance(): # test this implementation against Frank Yeh implementation vertices, faces = SPHERE_DATA n_vertices = vertices.shape[0] vert_inds = sym_hemisphere(vertices) adj = vertinds_to_neighbors(vert_inds, faces) np.random.seed(42) vert_vals = np.random.uniform(size=(n_vertices,)) maxinds = argmax_from_adj(vert_vals, vert_inds, adj) maxes, pfmaxinds = dcr.peak_finding(vert_vals, faces) assert_array_equal(maxinds, pfmaxinds[::-1])
def test_performance(): # test this implementation against Frank Yeh implementation vertices, faces = SPHERE_DATA n_vertices = vertices.shape[0] vert_inds = sym_hemisphere(vertices) adj = vertinds_to_neighbors(vert_inds, faces) np.random.seed(42) vert_vals = np.random.uniform(size=(n_vertices, )) maxinds = argmax_from_adj(vert_vals, vert_inds, adj) maxes, pfmaxinds = dcr.peak_finding(vert_vals, faces) assert_array_equal(maxinds, pfmaxinds[::-1])
def test_vertinds_neighbors(): adj = neighbors(FACES) assert_array_equal(adj, [[1, 2, 3, 4], [0, 2, 4, 5], [0, 1, 3, 5], [0, 2, 4, 5], [0, 1, 3, 5], [1, 2, 3, 4]]) adj = vertinds_to_neighbors(np.arange(6), FACES) assert_array_equal(adj, [[1, 2, 3, 4], [0, 2, 4, 5], [0, 1, 3, 5], [0, 2, 4, 5], [0, 1, 3, 5], [1, 2, 3, 4]]) # subset of inds gives subset of faces adj = vertinds_to_neighbors(np.arange(3), FACES) assert_array_equal(adj, [[1, 2, 3, 4], [0, 2, 4, 5], [0, 1, 3, 5]]) # can be any subset adj = vertinds_to_neighbors(np.arange(3,6), FACES) assert_array_equal(adj, [[0, 2, 4, 5], [0, 1, 3, 5], [1, 2, 3, 4]]) # just test right size for the real mesh vertices = SPHERE_DATA['vertices'] faces = SPHERE_DATA['faces'] n_vertices = vertices.shape[0] adj = vertinds_to_neighbors(np.arange(n_vertices), faces) assert_equal(len(adj), n_vertices) assert_equal(len(adj[1]), 6)
def new_peaks(odf, faces): # DO NOT USE THIS: IT IS VERY SLOW # use dominant instead np = [] for point, height in enumerate(odf): neighbours = meshes.vertinds_to_neighbors([point], faces) # print point, neighbours if max(odf[neighbours]) <= height: # print point, height, max(odf[neighbours]) np += [point] # adjacent_faces = meshes.vertinds_faceinds([point], faces) """ if max(odf[neighbours]) <= height: np += [point] """ return np