Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)