Ejemplo n.º 1
0
 def test_interp_to_pts(self):
     """Interpolate to multiple points."""
     pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
     interp = InterpIdw(pts)
     ret = interp.interpolate_to_points(
         np.array([(2.0, 1.0, 0.0), (5.0, 10.0, 2.5)]))
     np.testing.assert_array_almost_equal((0.02681550197303295, 2.5), ret)
Ejemplo n.º 2
0
 def test_interp_to_pts_numpy(self):
     """Interpolate to multiple points."""
     pts = np.array([(0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3)])
     interp = InterpIdw(pts)
     ret = interp.interpolate_to_points(
         np.array(((2.0, 1.0, 0.0), (5.0, 10.0, 2.5))))
     self.assertIsInstance(ret, np.ndarray)
     np.testing.assert_array_equal(np.array([0.02681550197303295, 2.5]),
                                   ret)
Ejemplo n.º 3
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)
        interp = InterpIdw(pts, tris)
        act1 = (True, False, False, True)
        interp.point_activity = act1

        act2 = (0, 1, 0, 1)
        interp.point_activity = act2
Ejemplo n.º 4
0
    def test_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)
        interp = InterpIdw(pts, tris)
        act1 = (True, False)
        interp.triangle_activity = act1

        act2 = (1, 1)
        interp.triangle_activity = act2
Ejemplo n.º 5
0
    def test_set_trunc(self):
        """Test set_trunc."""
        t_min = 7.11
        t_max = 11.7

        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 = InterpIdw(pts, tris)

        interp.set_truncation(t_max, t_min)
        self.assertEquals(t_min, interp.truncate_min)
        self.assertEquals(t_max, interp.truncate_max)
    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.º 7
0
    def test_get_pts(self):
        """Getting interp object points."""
        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 = InterpIdw(pts, tris)

        ret = interp.points
        np.testing.assert_array_equal(pts, ret)
    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.º 9
0
    def test_interpolate_weights(self):
        """Test interpolate_weights."""
        pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
        tris = (0, 1, 3, 1, 2, 3)
        interp = InterpIdw(pts, tris)

        idxs, wts = interp.interpolate_weights((5, 5, 2))
        np.testing.assert_array_equal(np.array([0, 1, 2, 3], np.int32), idxs)
        np.testing.assert_array_equal(np.array([0.25, 0.25, 0.25, 0.25]), wts)

        idxs, wts = interp.interpolate_weights((10, 10, 0))
        np.testing.assert_array_equal(np.array([2], np.int32), idxs)
        np.testing.assert_array_equal(np.array([1.]), wts)

        idxs, wts = interp.interpolate_weights((-10, -10, -10))
        np.testing.assert_array_equal(np.array([0, 1, 2, 3], np.int32), idxs)
        np.testing.assert_array_almost_equal(np.array(
            [0.876919, 0.06154, 0.0, 0.06154]),
                                             wts,
                                             decimal=5)
Ejemplo n.º 10
0
    def test_tutorial(self):
        """Ensure the tutorial will work."""
        pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
        tris = ()
        tris2 = (0, 1, 3, 1, 2, 3)

        interp = InterpIdw(pts, tris)
        val = interp.interpolate_to_point((5, 5, 0))
        self.assertEqual(1.5, val)

        interp = InterpIdw(pts, tris2)
        val2 = interp.interpolate_to_point((5, 5, 0))
        self.assertEqual(1.5, val2)
Ejemplo n.º 11
0
 def setUp(self):
     """Set up for each test case."""
     pts = ((1, 2, 3), (1, 2, 3), (1, 2, 3))
     self.interp_idw_obj = InterpIdw(pts)
Ejemplo n.º 12
0
    def test_set_nodal_function(self):
        """Setting nodal function."""
        observer = MockObserver()
        typeerror = "SetNodalFunction(): incompatible function arguments."

        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 = InterpIdw(pts, tris)

        # No Argument
        interp.set_nodal_function()

        # None Args for each argument
        with self.assertRaises(ValueError) as context:
            interp.set_nodal_function(None, 1, True, observer)
        err = context.exception
        func_type_error = '"nodal_function_type" must be one of {}, not None'.format(
            ", ".join(InterpIdw.nodal_function_types))
        self.assertIn(func_type_error, str(err))
        with self.assertRaises(TypeError) as context:
            interp.set_nodal_function("constant", None, True, observer)
        err = context.exception
        self.assertIn(typeerror, str(err))

        # Bad Args
        with self.assertRaises(ValueError) as context:
            interp.set_nodal_function(1, 1, True, observer)
        err = context.exception
        func_type_error = '"nodal_function_type" must be one of {}, not 1'.format(
            ", ".join(InterpIdw.nodal_function_types))
        self.assertIn(func_type_error, str(err))
        with self.assertRaises(ValueError) as context:
            interp.set_nodal_function("abc", 1, True, observer)
        err = context.exception
        err_str = '"nodal_function_type" must be one of {}, not abc'.format(
            ", ".join(InterpIdw.nodal_function_types))
        self.assertIn(err_str, str(err))
        with self.assertRaises(TypeError) as context:
            interp.set_nodal_function("constant", "1234", True, observer)
        err = context.exception
        self.assertIn(typeerror, str(err))
        with self.assertRaises(TypeError) as context:
            interp.set_nodal_function("constant", 1.4, True, observer)
        err = context.exception
        self.assertIn(typeerror, str(err))
        with self.assertRaises(ValueError) as context:
            interp.set_nodal_function("constant", 1, True, 1)
        err_str = "observer must be of type xmscore.misc.Observer"
        err = context.exception
        self.assertIn(err_str, str(err))
        with self.assertRaises(ValueError) as context:
            interp.set_nodal_function("constant", 1, True, "abcd")
        err = context.exception
        self.assertIn(err_str, str(err))

        # Good Args
        base = str(interp)
        interp.set_nodal_function("constant", 7, True, observer)
        self.assertEqual(base, str(interp))

        interp.set_nodal_function("gradient_plane", 9, True, observer)
        # TODO: Removed to_string checks. Need another way to test this

        interp.set_nodal_function("quadratic", 11, True, observer)
Ejemplo n.º 13
0
    def test_set_observer(self):
        """Test set_observer."""
        observer1 = MockObserver("Obs1")
        observer2 = MockObserver("Obs2")

        pts = ((0, 0, 0), (10, 0, 1), (10, 10, 2), (0, 10, 3))
        tris = (0, 1, 3, 1, 2, 3)
        interp = InterpIdw(pts, tris)

        # Non-Observer Type
        with self.assertRaises(TypeError) as context:
            interp.set_observer("xyz")
        err = context.exception
        self.assertIn("SetObserver(): incompatible function arguments.",
                      str(err))

        interp.set_observer(observer1)
        interp.interpolate_to_points(np.random.rand(100000, 3) + 5)
        self.assertGreater(observer1.status['percent_complete'], 0.0)
        self.assertGreater(observer1.status['elapsed_seconds'], 0.0)

        interp.set_observer(observer2)
        interp.interpolate_to_points(np.random.rand(100000, 3) + 5)
        self.assertGreater(observer2.status['percent_complete'], 0.0)
        self.assertGreater(observer2.status['elapsed_seconds'], 0.0)
Ejemplo n.º 14
0
 def test_set_size_func_02(self):
     """Test setting the size function."""
     r = PolyRedistributePoints()
     pts = ((0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0))
     sf = InterpIdw(pts)
     r.set_size_func(sf)