def test_points_mapping(): points = np.array([[0, 0, 0], [10, 10, 10], [1000, 1000, 1000]]) source_space = AnatomicalSpace( "psl", shape=(1000, 1000, 1000), resolution=(1, 1, 1) ) target_space = AnatomicalSpace( "asl", shape=(100, 100, 100), resolution=(10, 10, 10) ) mapped_points = source_space.map_points_to(target_space, points) assert np.allclose( mapped_points, np.array([[100.0, 0.0, 0.0], [99.0, 1.0, 1.0], [0.0, 100.0, 100.0]]), )
def test_point_transform(src_o, tgt_o, src_shape, tgt_shape): # Create an array with descriptive space labels: source_stack = create_label_array(src_o, src_shape) # Create spaces objects: source_space = AnatomicalSpace(src_o, shape=[s * 2 for s in src_shape]) # Test both mapping to AnatomicalSpace obj and origin with decorator: for target_space in [tgt_o, AnatomicalSpace(tgt_o)]: # Define grid of points sampling 4 points per axis: grid_positions = [[1, s - 1, s + 1, s * 2 - 1] for s in src_shape] source_pts = np.array(list(itertools.product(*grid_positions))) # Map points and stack to target space: mapped_pts = source_space.map_points_to(target_space, source_pts) mapped_stack = source_space.map_stack_to(target_space, source_stack) # Check that point coordinates keep the same values: for p_source, p_mapped in zip(source_pts, mapped_pts): p_s, p_m = [tuple(p.astype(np.int)) for p in [p_source, p_mapped]] assert source_stack[p_s] == mapped_stack[p_m]
def test_point_transform_fail(): s = AnatomicalSpace("asl") with pytest.raises(TypeError) as error: s.map_points_to("psl", np.array([[0, 1, 2], [0, 1, 2]])) assert "The source space should have a shape" in str(error)