def test_write_parameters_filename_default(self): params = IDW() outfilename = 'parameters_rbf.prm' outfilename_expected = 'tests/test_datasets/parameters_idw_default.prm' params.write_parameters(outfilename) self.assertTrue(filecmp.cmp(outfilename, outfilename_expected)) os.remove(outfilename)
def test_read_deformed(self): params = IDW() filename = 'tests/test_datasets/parameters_idw_deform.prm' def_vertices = np.array([[0., 0., 0.], [0., 0., 1.], [0., 1., 0.], [1., 0., 0.], [0., 1., 1.], [1., 0., 1.], [1., 1., 0.], [1.5, 1.6, 1.7]]) params.read_parameters(filename) np.testing.assert_equal(params.deformed_control_points, def_vertices)
def test_idw_perform_deform(self): params = IDWParameters() expected_stretch = [1.19541593, 1.36081491, 1.42095073] params.read_parameters('tests/test_datasets/parameters_idw_deform.prm') idw = IDW(params, self.get_cube_mesh_points()) idw.perform() np.testing.assert_array_almost_equal(idw.modified_mesh_points[-3], expected_stretch)
def __init__(self, original_control_points=None, deformed_control_points=None, power=2, u_knots_to_add=0, v_knots_to_add=0, t_knots_to_add=0, tolerance=1e-4): OriginalIDW.__init__(self, original_control_points=original_control_points, deformed_control_points=deformed_control_points, power=power) CADDeformation.__init__(self, u_knots_to_add=u_knots_to_add, v_knots_to_add=v_knots_to_add, t_knots_to_add=t_knots_to_add, tolerance=tolerance)
def test_idw_perform(self): params = IDWParameters() params.read_parameters( 'tests/test_datasets/parameters_idw_default.prm') IDW(params, self.get_cube_mesh_points()).perform()
get_ipython().run_line_magic('matplotlib', 'inline') import numpy as np import matplotlib.pyplot as plt from pygem import IDW # We need to set the deformation parameters: we can set manually, by editing the `IDW` attributes, or we can read them by parsing a file. We remark that it is possible to save the parameters (for example, after set them manually) to a file in order to edit this for the future deformations. # In[2]: parameters_file = '../tests/test_datasets/parameters_idw_cube.prm' idw = IDW() idw.read_parameters(filename=parameters_file) # The following is the parameters file for this particular case. The Inverse Distance Weighting section describes the power parameter (see the documentation of the [IDW](http://mathlab.github.io/PyGeM/idw.html) class for more details). As control points we consider the 8 vertices of the cube (the first one is not exactly the vertex), and we move 3 of them. In the Control points section there are all the coordinates of the control points. # In[3]: get_ipython().run_line_magic('cat', "'../tests/test_datasets/parameters_idw_cube.prm'") # Here we create a $10 \times 10 \times 10$ lattice to mimic a cube. # In[4]:
def test_print(self): idw = IDW() print(idw)
def test_read_not_string(self): idw = IDW() with self.assertRaises(TypeError): idw.read_parameters(5)
def test_read_not_real_file(self): idw = IDW() with self.assertRaises(IOError): idw.read_parameters('not_real_file')
def test_idw(self): idw = IDW()
def test_read_p(self): idw = IDW() filename = 'tests/test_datasets/parameters_idw_deform.prm' idw.read_parameters(filename) assert idw.power == 3
def test_write_not_string(self): params = IDW() with self.assertRaises(TypeError): params.write_parameters(5)
def test_idw_call(self): idw = IDW() idw.read_parameters('tests/test_datasets/parameters_idw_default.prm') idw(self.get_cube_mesh_points())
def test_class_members_default_deformed_points(self): idw = IDW() cube_vertices = np.array([[0., 0., 0.], [0., 0., 1.], [0., 1., 0.], [1., 0., 0.], [0., 1., 1.], [1., 0., 1.], [1., 1., 0.], [1., 1., 1.]]) np.testing.assert_equal(idw.deformed_control_points, cube_vertices)
def test_class_members_default_p(self): idw = IDW() assert idw.power == 2
def test_idw_perform_deform(self): idw = IDW() expected_stretch = [1.19541593, 1.36081491, 1.42095073] idw.read_parameters('tests/test_datasets/parameters_idw_deform.prm') new_pts = idw(self.get_cube_mesh_points()) np.testing.assert_array_almost_equal(new_pts[-3], expected_stretch)