예제 #1
0
 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)
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]:

예제 #3
0
 def test_read_not_real_file(self):
     idw = IDW()
     with self.assertRaises(IOError):
         idw.read_parameters('not_real_file')
예제 #4
0
 def test_read_not_string(self):
     idw = IDW()
     with self.assertRaises(TypeError):
         idw.read_parameters(5)
예제 #5
0
 def test_read_p(self):
     idw = IDW()
     filename = 'tests/test_datasets/parameters_idw_deform.prm'
     idw.read_parameters(filename)
     assert idw.power == 3
예제 #6
0
 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)
예제 #7
0
 def test_idw_call(self):
     idw = IDW()
     idw.read_parameters('tests/test_datasets/parameters_idw_default.prm')
     idw(self.get_cube_mesh_points())