def test_sample_locations(): # check positions of samples on toy example, with an affine != identity # flat horizontal mesh mesh = flat_mesh(5, 7) affine = np.diagflat([10, 20, 30, 1]) inv_affine = np.linalg.inv(affine) # transform vertices to world space vertices = np.asarray( resampling.coord_transform(*mesh[0].T, affine=affine)).T # compute by hand the true offsets in voxel space # (transformed by affine^-1) ball_offsets = surface._load_uniform_ball_cloud(10) ball_offsets = np.asarray( resampling.coord_transform(*ball_offsets.T, affine=inv_affine)).T line_offsets = np.zeros((10, 3)) line_offsets[:, 2] = np.linspace(1, -1, 10) line_offsets = np.asarray( resampling.coord_transform(*line_offsets.T, affine=inv_affine)).T # check we get the same locations for kind, offsets in [('line', line_offsets), ('ball', ball_offsets)]: locations = surface._sample_locations( [vertices, mesh[1]], affine, 1., kind=kind, n_points=10) true_locations = np.asarray([vertex + offsets for vertex in mesh[0]]) assert_array_equal(locations.shape, true_locations.shape) assert_array_almost_equal(true_locations, locations) pytest.raises(ValueError, surface._sample_locations, mesh, affine, 1., kind='bad_kind')
def test_sample_locations(): # check positions of samples on toy example, with an affine != identity # flat horizontal mesh mesh = flat_mesh(5, 7) affine = np.diagflat([10, 20, 30, 1]) inv_affine = np.linalg.inv(affine) # transform vertices to world space vertices = np.asarray( resampling.coord_transform(*mesh[0].T, affine=affine)).T # compute by hand the true offsets in voxel space # (transformed by affine^-1) ball_offsets = surface._load_uniform_ball_cloud(10) ball_offsets = np.asarray( resampling.coord_transform(*ball_offsets.T, affine=inv_affine)).T line_offsets = np.zeros((10, 3)) line_offsets[:, 2] = np.linspace(-1, 1, 10) line_offsets = np.asarray( resampling.coord_transform(*line_offsets.T, affine=inv_affine)).T # check we get the same locations for kind, offsets in [('line', line_offsets), ('ball', ball_offsets)]: locations = surface._sample_locations( [vertices, mesh[1]], affine, 1., kind=kind, n_points=10) true_locations = np.asarray([vertex + offsets for vertex in mesh[0]]) assert_array_equal(locations.shape, true_locations.shape) assert_array_almost_equal(true_locations, locations) assert_raises(ValueError, surface._sample_locations, mesh, affine, 1., kind='bad_kind')
def test_sample_locations_depth(depth, n_points): mesh = flat_mesh(5, 7) radius = 8. locations = surface._sample_locations( mesh, np.eye(4), radius, n_points=n_points, depth=depth) offsets = np.asarray([[0., 0., - z * radius] for z in depth]) expected = np.asarray([vertex + offsets for vertex in mesh[0]]) assert np.allclose(locations, expected)