Ejemplo n.º 1
0
 def test_tutorial(self):
     """Ensure the tutorial will work."""
     pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
     tris = (0, 1, 3, 1, 2, 3)
     interper = InterpLinear(pts, tris)
     val = interper.interpolate_to_point((2, 1, 0))
     self.assertEqual(0.5, val)
Ejemplo n.º 2
0
 def test_tri_containing_pt(self):
     """Getting tri containing point."""
     pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
     tris = (0, 1, 3, 1, 2, 3)
     interper = InterpLinear(pts, tris)
     ret = interper.triangle_containing_point((5, 5, 2))
     self.assertEqual(0, ret)
Ejemplo n.º 3
0
 def test_intperp_to_pts(self):
     """Interpolate to multiple points."""
     pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
     tris = (0, 1, 3, 1, 2, 3)
     interp_ = InterpLinear(pts, tris)
     ret = interp_.interpolate_to_points(((2, 1, 0), (5, 10, 2.5)))
     self.assertIsInstance(ret, tuple)
     self.assertEqual((0.5, 2.5), ret)
Ejemplo n.º 4
0
    def test_tri_envelops_containing_pt(self):
        """Getting tri containing point."""
        import numpy as np
        pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
        tris = (0, 1, 3, 1, 2, 3)

        interper = InterpLinear(pts, tris)
        ret = interper.triangle_envelopes_containing_point((5, 5, 2))
        np.testing.assert_array_equal(np.array([0, 3], np.int32), ret)
Ejemplo n.º 5
0
 def test_intperp_to_pts_numpy(self):
     """Interpolate to multiple points."""
     import numpy as np
     pts = np.array([(0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3)])
     tris = np.array([0, 1, 3, 1, 2, 3])
     interp_ = InterpLinear(pts, tris)
     ret = interp_.interpolate_to_points(np.array([(2, 1, 0), (5, 10, 2.5)]))
     self.assertIsInstance(ret, np.ndarray)
     np.testing.assert_array_equal(np.array([0.5, 2.5]), ret)
Ejemplo n.º 6
0
 def test_set_use_clough_tocher(self):
     """Test set_use_clough_tocher."""
     interper = self.interp_linear_obj
     observer = MockObserver()
     pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
     tris = (0, 1, 3, 1, 2, 3)
     interper = InterpLinear(pts, tris)
     interper.set_use_clough_tocher(True, observer)
     val = interper.interpolate_to_point((2, 1, 0))
     self.assertAlmostEqual(0.2574999928474426, val, places=9)
Ejemplo n.º 7
0
    def test_set_triangle_activity(self):
        """Setting tri activity."""
        pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
        tris = (0, 1, 3, 1, 2, 3)
        interper = InterpLinear(pts, tris)
        act1 = (True, False)
        interper.triangle_activity = act1

        act2 = (1, 1)
        interper.triangle_activity = act2
Ejemplo n.º 8
0
    def test_set_pt_activity(self):
        """Setting point activity."""
        pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
        tris = (0, 1, 3, 1, 2, 3)
        interper = InterpLinear(pts, tris)
        act1 = (True, False, False, True)
        interper.point_activity = act1

        act2 = (0, 1, 0, 1)
        interper.point_activity = act2
Ejemplo n.º 9
0
    def test_set_use_nat_neigh(self):
        """Test set_use_nat_neigh."""
        observer = MockObserver()
        pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
        tris = (0, 1, 3, 1, 2, 3)
        interper = InterpLinear(pts, tris)

        nodal_func = "constant"
        nodal_func_opts = "nearest_points"
        n_nearest = 12
        blend_weights = False
        interper.set_use_natural_neighbor(True, nodal_func, nodal_func_opts, n_nearest, blend_weights, observer)

        val = interper.interpolate_to_point((2, 1, 0))
        self.assertAlmostEqual(0.4600000, val, places=7)
    def test_constructor(self):
        """Test the PolyInput constructor."""
        outside_poly = ((1, 2, 0), (5, 2, 0), (5, 9, 0), (1, 9, 0))
        inside_polys = (((3, 3, 0), (2.5, 4, 0), (2, 3, 0)),
                        ((4, 8, 0), (3, 7, 0), (2, 8, 0)))
        poly_corners = (0, 1, 2, 3)
        bias = 3.14159
        pts = ((1, 0, 0), (10, 0, 0), (10, 10, 0))
        size_func = InterpLinear(pts)
        elev_func = InterpIdw(pts)

        pi = PolyInput(outside_polygon=outside_poly,
                       inside_polygons=inside_polys,
                       bias=bias,
                       size_function=size_func,
                       polygon_corners=poly_corners,
                       elevation_function=elev_func)
        self.assertIsInstance(pi, PolyInput)
        self.assert_arrays_equal(outside_poly, pi.outside_polygon)
        self.assert_inside_polys_equal(inside_polys, pi.inside_polygons)
        self.assertEqual(bias, pi.bias)
        # self.assertEqual(size_func.to_string(), pi.size_function.to_string())
        # self.assertEqual(elev_func.to_string(), pi.elevation_function.to_string())
        self.assertEqual(-1, pi.constant_size_bias)
        self.assertEqual(-1, pi.constant_size_function)
        self.assertEqual(False, pi.remove_internal_four_triangle_points)
Ejemplo n.º 11
0
    def test_interp_weights(self):
        """Test interp_weights."""
        import numpy as np
        pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
        tris = (0, 1, 3, 1, 2, 3)
        interper = InterpLinear(pts, tris)

        pt_inside, idxs, wts = interper.interpolate_weights((5, 5, 2))
        self.assertTrue(pt_inside)
        np.testing.assert_array_equal(np.array([0, 1, 3], np.int32), idxs)
        np.testing.assert_array_equal(np.array([0, 0.5, 0.5]), wts)

        pt_inside, idxs, wts = interper.interpolate_weights((-10, -10, -10))
        self.assertFalse(pt_inside)
        np.testing.assert_array_equal(np.array([], np.int32), idxs)
        np.testing.assert_array_equal(np.array([]), wts)
    def test_properties(self):
        """Test the PolyInput properties."""
        out_poly = ((0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0))
        pi = PolyInput(out_poly)
        outside_poly = ((1, 2, 0), (5, 2, 0), (5, 9, 0), (1, 9, 0))
        inside_polys = (((3, 3, 0), (2.5, 4, 0), (2, 3, 0)),
                        ((4, 8, 0), (3, 7, 0), (2, 8, 0)))
        poly_corners = (0, 1, 2, 3)
        pts = ((1, 2, 3), (4, 5, 6), (0, 5, 7))
        size_func = InterpLinear(pts)
        elev_func = InterpIdw(pts)
        seed_points = ((3, 3, 0), (4, 3, 0), (4, 8, 0), (3, 8, 0))
        relaxation_method = "spring_relaxation"

        self.assertEqual(4, len(pi.outside_polygon))
        pi.outside_polygon = outside_poly
        self.assert_arrays_equal(outside_poly, pi.outside_polygon)

        self.assertEqual(0, len(pi.inside_polygons))
        pi.inside_polygons = inside_polys
        self.assert_inside_polys_equal(inside_polys, pi.inside_polygons)

        self.assertEqual(0, len(pi.polygon_corners))
        pi.polygon_corners = poly_corners
        self.assert_arrays_equal(poly_corners, pi.polygon_corners)

        self.assertEqual(1.0, pi.bias)
        pi.bias = 0.3
        self.assertEqual(0.3, pi.bias)

        self.assertEqual(None, pi.size_function)
        pi.size_function = size_func
        # self.assertEqual(str(size_func), str(pi.size_function))

        self.assertEqual(None, pi.elevation_function)
        pi.elevation_function = elev_func
        # self.assertEqual(elev_func.to_string(), pi.elevation_function.to_string())

        self.assertEqual(-1, pi.constant_size_bias)
        pi.constant_size_bias = 4.0
        self.assertEqual(4.0, pi.constant_size_bias)

        self.assertEqual(-1, pi.constant_size_function)
        pi.constant_size_function = 1.2
        self.assertEqual(1.2, pi.constant_size_function)

        self.assertEqual(False, pi.remove_internal_four_triangle_points)
        pi.remove_internal_four_triangle_points = True
        self.assertEqual(True, pi.remove_internal_four_triangle_points)

        self.assertEqual(0, len(pi.seed_points))
        pi.seed_points = seed_points
        self.assert_arrays_equal(seed_points, pi.seed_points)

        self.assertEqual("", pi.relaxation_method)
        pi.relaxation_method = relaxation_method
        self.assertEqual(relaxation_method, pi.relaxation_method)
Ejemplo n.º 13
0
 def test_set_pts_tris(self):
     """Set base points."""
     # Test that the a proper call does not throw
     pts = ((0, 0, 0), (1, 1, 0), (1, 0, 0))
     tris = (0, 2, 1)
     interper = InterpLinear(pts, tris)
     base_string = '<InterpLinear - Point Count: 3, Triangle Count: 1>'
     rstr = repr(interper)
     self.assertEqual(base_string, rstr)
Ejemplo n.º 14
0
    def test_get_tris(self):
        """Getting interp object points."""
        import numpy as np
        pts = np.array([(0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3)])
        tris = np.array([0, 1, 3, 1, 2, 3])
        interper = InterpLinear(pts, tris)

        ret = interper.triangles
        np.testing.assert_array_equal(tris, ret)
Ejemplo n.º 15
0
    def test_set_pts_tris_numpy(self):
        """Set base points."""
        import numpy as np

        # Test that the a proper call does not throw
        pts = np.array([(0, 0, 0), (1, 1, 0), (1, 0, 0)])
        tris = np.array([0, 2, 1])
        base_string = '<InterpLinear - Point Count: 3, Triangle Count: 1>'
        interper = InterpLinear(pts, tris)
        rstr = repr(interper)
        self.assertEqual(base_string, rstr)
Ejemplo n.º 16
0
 def test_set_size_func_01(self):
     """Test setting the size function."""
     r = PolyRedistributePoints()
     pts = ((0, 0, 0), (1, 1, 0), (0, 1, 0))
     sf = InterpLinear(pts)
     r.set_size_func(sf)