Ejemplo n.º 1
0
 def test_calc_abc(self):
     # No np.nan inputs
     pt_1, pt_2, pt_3, pt_4 = self.pts_irregular
     res = bil._calc_abc(pt_1, pt_2, pt_3, pt_4, 0.0, 0.0)
     self.assertFalse(np.isnan(res[0]))
     self.assertFalse(np.isnan(res[1]))
     self.assertFalse(np.isnan(res[2]))
     # np.nan input -> np.nan output
     res = bil._calc_abc(np.array([[np.nan, np.nan]]),
                         pt_2, pt_3, pt_4, 0.0, 0.0)
     self.assertTrue(np.isnan(res[0]))
     self.assertTrue(np.isnan(res[1]))
     self.assertTrue(np.isnan(res[2]))
Ejemplo n.º 2
0
 def test_calc_abc(self):
     # No np.nan inputs
     pt_1, pt_2, pt_3, pt_4 = self.pts_irregular
     res = bil._calc_abc(pt_1, pt_2, pt_3, pt_4, 0.0, 0.0)
     self.assertFalse(np.isnan(res[0]))
     self.assertFalse(np.isnan(res[1]))
     self.assertFalse(np.isnan(res[2]))
     # np.nan input -> np.nan output
     res = bil._calc_abc(np.array([[np.nan, np.nan]]), pt_2, pt_3, pt_4,
                         0.0, 0.0)
     self.assertTrue(np.isnan(res[0]))
     self.assertTrue(np.isnan(res[1]))
     self.assertTrue(np.isnan(res[2]))
Ejemplo n.º 3
0
    def test_calc_abc(self):
        """Test calculation of quadratic coefficients."""
        from pyresample.bilinear import _calc_abc

        # No np.nan inputs
        pt_1, pt_2, pt_3, pt_4 = self.pts_irregular
        res = _calc_abc(pt_1, pt_2, pt_3, pt_4, 0.0, 0.0)
        self.assertFalse(np.isnan(res[0]))
        self.assertFalse(np.isnan(res[1]))
        self.assertFalse(np.isnan(res[2]))
        # np.nan input -> np.nan output
        res = _calc_abc(np.array([[np.nan, np.nan]]), pt_2, pt_3, pt_4, 0.0,
                        0.0)
        self.assertTrue(np.isnan(res[0]))
        self.assertTrue(np.isnan(res[1]))
        self.assertTrue(np.isnan(res[2]))
Ejemplo n.º 4
0
 def test_solve_quadratic(self):
     res = bil._solve_quadratic(1, 0, 0)
     self.assertEqual(res[0], 0.0)
     res = bil._solve_quadratic(1, 2, 1)
     self.assertTrue(np.isnan(res[0]))
     res = bil._solve_quadratic(1, 2, 1, min_val=-2.)
     self.assertEqual(res[0], -1.0)
     # Test that small adjustments work
     pt_1, pt_2, pt_3, pt_4 = self.pts_vert_parallel
     pt_1 = self.pts_vert_parallel[0].copy()
     pt_1[0][0] += 1e-7
     res = bil._calc_abc(pt_1, pt_2, pt_3, pt_4, 0.0, 0.0)
     res = bil._solve_quadratic(res[0], res[1], res[2])
     self.assertAlmostEqual(res[0], 0.5, 5)
     res = bil._calc_abc(pt_1, pt_3, pt_2, pt_4, 0.0, 0.0)
     res = bil._solve_quadratic(res[0], res[1], res[2])
     self.assertAlmostEqual(res[0], 0.5, 5)
Ejemplo n.º 5
0
 def test_solve_quadratic(self):
     res = bil._solve_quadratic(1, 0, 0)
     self.assertEqual(res[0], 0.0)
     res = bil._solve_quadratic(1, 2, 1)
     self.assertTrue(np.isnan(res[0]))
     res = bil._solve_quadratic(1, 2, 1, min_val=-2.)
     self.assertEqual(res[0], -1.0)
     # Test that small adjustments work
     pt_1, pt_2, pt_3, pt_4 = self.pts_vert_parallel
     pt_1 = self.pts_vert_parallel[0].copy()
     pt_1[0][0] += 1e-7
     res = bil._calc_abc(pt_1, pt_2, pt_3, pt_4, 0.0, 0.0)
     res = bil._solve_quadratic(res[0], res[1], res[2])
     self.assertAlmostEqual(res[0], 0.5, 5)
     res = bil._calc_abc(pt_1, pt_3, pt_2, pt_4, 0.0, 0.0)
     res = bil._solve_quadratic(res[0], res[1], res[2])
     self.assertAlmostEqual(res[0], 0.5, 5)
Ejemplo n.º 6
0
    def test_solve_quadratic(self):
        """Test solving quadratic equation."""
        from pyresample.bilinear import (_solve_quadratic, _calc_abc)

        res = _solve_quadratic(1, 0, 0)
        self.assertEqual(res[0], 0.0)
        res = _solve_quadratic(1, 2, 1)
        self.assertTrue(np.isnan(res[0]))
        res = _solve_quadratic(1, 2, 1, min_val=-2.)
        self.assertEqual(res[0], -1.0)
        # Test that small adjustments work
        pt_1, pt_2, pt_3, pt_4 = self.pts_vert_parallel
        pt_1 = self.pts_vert_parallel[0].copy()
        pt_1[0][0] += 1e-7
        res = _calc_abc(pt_1, pt_2, pt_3, pt_4, 0.0, 0.0)
        res = _solve_quadratic(res[0], res[1], res[2])
        self.assertAlmostEqual(res[0], 0.5, 5)
        res = _calc_abc(pt_1, pt_3, pt_2, pt_4, 0.0, 0.0)
        res = _solve_quadratic(res[0], res[1], res[2])
        self.assertAlmostEqual(res[0], 0.5, 5)
Ejemplo n.º 7
0
    def test_solve_quadratic(self):
        """Test solving quadratic equation."""
        import dask.array as da
        from pyresample.bilinear import (_solve_quadratic, _calc_abc)

        res = _solve_quadratic(1, 0, 0)
        self.assertEqual(res, 0.0)
        res = _solve_quadratic(1, 2, 1)
        self.assertTrue(np.isnan(res))
        res = _solve_quadratic(1, 2, 1, min_val=-2.)
        self.assertEqual(res, -1.0)
        # Test that small adjustments work
        pt_1, pt_2, pt_3, pt_4 = self.pts_vert_parallel
        pt_1 = self.pts_vert_parallel[0].compute()
        pt_1[0][0] += 1e-7
        pt_1 = da.from_array(pt_1)
        corner_points = (pt_1, pt_2, pt_3, pt_4)
        res = _calc_abc(corner_points, 0.0, 0.0)
        res = _solve_quadratic(res[0], res[1], res[2]).compute()
        self.assertAlmostEqual(res[0], 0.5, 5)
        corner_points = (pt_1, pt_3, pt_2, pt_4)
        res = _calc_abc(corner_points, 0.0, 0.0)
        res = _solve_quadratic(res[0], res[1], res[2]).compute()
        self.assertAlmostEqual(res[0], 0.5, 5)