def test_incorrect_input_1(self): """Different shapes.""" f_x = np.zeros((3, 4)) f_y = np.zeros((2, 4)) with pytest.raises(ValueError): DisplacementField.from_transform(f_x, f_y)
def test_incorrect_input_2(self): """Additional dimensions.""" f_x = np.zeros((2, 2, 4)) f_y = np.zeros((2, 2, 4)) with pytest.raises(ValueError): DisplacementField.from_transform(f_x, f_y)
def get_transform(p, dataset_id, ds_f=1): """Get transformation given a fixed coronal section. Parameters ---------- p : int Coronal slice coordinate in microns. dataset_id : int Id of the section dataset. Used to determine the 3D matrix. ds_f : int, optional Downsampling factor. If set to 1 no downsampling takes place. Note that if `ds_f` = 25, then we obtain the shape (320, 456). Returns ------- df : DisplacementField Displacement field of shape (8000 // `ds_f`, 11400 // `ds_f`, ?) representing reference -> moved transformation. """ output_shape = (8000 // ds_f, 11400 // ds_f) y, x = np.indices(output_shape) grid = np.stack((x.ravel(), y.ravel())).T i_list = list(grid[:, 1] * ds_f) r_list = list(grid[:, 0] * ds_f) output_grid = np.empty_like(grid) x_list, y_list, _, _ = pir_to_xy_local_coronal(p, i_list, r_list, dataset_id=dataset_id) output_grid[:, 1] = y_list output_grid[:, 0] = x_list df = DisplacementField.from_transform( output_grid[:, 0].reshape(output_shape), output_grid[:, 1].reshape(output_shape)) return df
def test_equivalent(self): """Make sure that transform and displacement constructors are equivalent.""" random_state = 10 shape = (3, 4) np.random.seed(random_state) delta_x = np.random.randint(10, size=shape) delta_y = np.random.randint(10, size=shape) df = DisplacementField(delta_x, delta_y) df_new = DisplacementField.from_transform(*df.transformation) atol = 1e-4 assert np.allclose(df.delta_x, df_new.delta_x, atol=atol) assert np.allclose(df.delta_y, df_new.delta_y, atol=atol)