def test_sym_hemisphere(): assert_raises(ValueError, sym_hemisphere, VERTICES, 'k') assert_raises(ValueError, sym_hemisphere, VERTICES, '%z') for hem in ('x', 'y', 'z', '-x', '-y', '-z'): vert_inds = sym_hemisphere(VERTICES, hem) assert_equal(vert_inds.shape, (3, )) verts = VERTICES[vert_inds] # there are no symmetrical points remanining in vertices for vert in verts: assert_false(np.any(np.all(vert * -1 == verts))) # Test the sphere mesh data vertices, _ = SPHERE_DATA n_vertices = vertices.shape[0] vert_inds = sym_hemisphere(vertices) assert_array_equal(vert_inds, np.arange(n_vertices / 2))
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_sym_hemisphere(): assert_raises(ValueError, sym_hemisphere, VERTICES, 'k') assert_raises(ValueError, sym_hemisphere, VERTICES, '%z') for hem in ('x', 'y', 'z', '-x', '-y', '-z'): vert_inds = sym_hemisphere(VERTICES, hem) assert_equal(vert_inds.shape, (3,)) verts = VERTICES[vert_inds] # there are no symmetrical points remanining in vertices for vert in verts: assert_false(np.any(np.all( vert * -1 == verts))) # Test the sphere mesh data vertices, _ = SPHERE_DATA n_vertices = vertices.shape[0] vert_inds = sym_hemisphere(vertices) assert_array_equal(vert_inds, np.arange(n_vertices / 2))
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])