def test_grid3d_interpolator(self):
     """Testing of different interpolation methods"""
     a = self._test(core.Nearest3D(), "tcw_trivariate_nearest")
     b = self._test(core.Bilinear3D(), "tcw_trivariate_bilinear")
     c = self._test(core.InverseDistanceWeighting3D(), "tcw_trivariate_idw")
     self.assertTrue((a - b).std() != 0)
     self.assertTrue((a - c).std() != 0)
     self.assertTrue((b - c).std() != 0)
Beispiel #2
0
def test_grid3d_interpolator():
    """Testing of different interpolation methods"""
    a = run_interpolator(core.Nearest3D(), "tcw_trivariate_nearest")
    b = run_interpolator(core.Bilinear3D(), "tcw_trivariate_bilinear")
    c = run_interpolator(core.InverseDistanceWeighting3D(),
                         "tcw_trivariate_idw")
    assert (a - b).std() != 0
    assert (a - c).std() != 0
    assert (b - c).std() != 0
Beispiel #3
0
    def test_interpolator(self):
        grid = self.load_data()

        x = np.arange(-1, 1, 0.2)
        y = np.arange(-1, 1, 0.2)
        z = np.arange(-1, 1, 0.2)
        u = np.arange(-1, 10, 0.2)

        mx, my, mz, mu = np.meshgrid(x, y, z, u)
        expected = self.f4d(mx, my, mz, mu)

        interpolator = core.Bilinear3D()

        calculated = core.quadrivariate_float64(grid,
                                                mx.flatten(),
                                                my.flatten(),
                                                mz.flatten(),
                                                mu.flatten(),
                                                interpolator,
                                                num_threads=0,
                                                bounds_error=True)
        self.assertTrue(np.all(expected.flatten() == calculated))

        x = np.arange(-1, 1, 0.2)
        y = np.arange(-1, 1, 0.2)
        z = np.arange(-1, 1, 0.2)
        u = np.arange(-1, 10, 0.33333)

        mx, my, mz, mu = np.meshgrid(x, y, z, u)
        expected = self.f4d(mx, my, mz, mu)

        interpolator = core.Bilinear3D()

        calculated = core.quadrivariate_float64(grid,
                                                mx.flatten(),
                                                my.flatten(),
                                                mz.flatten(),
                                                mu.flatten(),
                                                interpolator,
                                                num_threads=0,
                                                bounds_error=False)
        self.assertAlmostEqual(np.nanstd(expected.flatten() - calculated), 0)
Beispiel #4
0
def test_grid3d_bounds_error():
    """Test of the detection on interpolation outside bounds"""
    grid = load_data()
    interpolator = core.Bilinear3D()
    lon = np.arange(-180, 180, 1 / 3.0) + 1 / 3.0
    lat = np.arange(-90, 90 + 1, 1 / 3.0) + 1 / 3.0
    time = 898500 + 3
    x, y, t = np.meshgrid(lon, lat, time, indexing="ij")
    core.trivariate_float64(grid,
                            x.flatten(),
                            y.flatten(),
                            t.flatten(),
                            interpolator,
                            num_threads=0)
    with pytest.raises(ValueError):
        core.trivariate_float64(grid,
                                x.flatten(),
                                y.flatten(),
                                t.flatten(),
                                interpolator,
                                bounds_error=True,
                                num_threads=0)
    def test_interpolator(self):
        grid = self.load_data()

        x = np.arange(-1, 1, 0.2)
        y = np.arange(-1, 1, 0.2)
        z = np.arange(-1, 1, 0.2)
        u = np.arange(-1, 10, 0.2)

        mx, my, mz, mu = np.meshgrid(x, y, z, u)
        expected = self.f4d(mx, my, mz, mu)

        interpolator = core.Bilinear3D()

        calculated = core.quadrivariate_float64(grid,
                                                mx.flatten(),
                                                my.flatten(),
                                                mz.flatten(),
                                                mu.flatten(),
                                                interpolator,
                                                num_threads=0,
                                                bounds_error=True)
        self.assertTrue(np.all(expected.flatten() == calculated))

        x = np.arange(-1, 1, 0.2)
        y = np.arange(-1, 1, 0.2)
        z = np.arange(-1, 1, 0.2)
        u = np.arange(-1, 10, 0.33333)

        mx, my, mz, mu = np.meshgrid(x, y, z, u)
        expected = self.f4d(mx, my, mz, mu)

        interpolator = core.Bilinear3D()

        calculated = core.quadrivariate_float64(grid,
                                                mx.flatten(),
                                                my.flatten(),
                                                mz.flatten(),
                                                mu.flatten(),
                                                interpolator,
                                                num_threads=0,
                                                bounds_error=False)
        self.assertAlmostEqual(np.nanstd(expected.flatten() - calculated), 0)

        other = core.quadrivariate_float64(grid,
                                           mx.flatten(),
                                           my.flatten(),
                                           mz.flatten(),
                                           mu.flatten(),
                                           interpolator,
                                           num_threads=0,
                                           z_method="linear",
                                           u_method="linear",
                                           bounds_error=False)
        self.assertAlmostEqual(np.nanstd(other - calculated), 0)

        other = core.quadrivariate_float64(grid,
                                           mx.flatten(),
                                           my.flatten(),
                                           mz.flatten(),
                                           mu.flatten(),
                                           interpolator,
                                           num_threads=0,
                                           z_method="linear",
                                           u_method="nearest",
                                           bounds_error=False)
        self.assertNotAlmostEqual(np.nanstd(other - calculated), 0)
        with self.assertRaises(ValueError):
            other = core.quadrivariate_float64(grid,
                                               mx.flatten(),
                                               my.flatten(),
                                               mz.flatten(),
                                               mu.flatten(),
                                               interpolator,
                                               num_threads=0,
                                               z_method="LINEAR",
                                               u_method="nearest",
                                               bounds_error=False)
        with self.assertRaises(ValueError):
            other = core.quadrivariate_float64(grid,
                                               mx.flatten(),
                                               my.flatten(),
                                               mz.flatten(),
                                               mu.flatten(),
                                               interpolator,
                                               num_threads=0,
                                               z_method="linear",
                                               u_method="NEAREST",
                                               bounds_error=False)
Beispiel #6
0
def test_interpolator():
    grid = load_data()

    x = np.arange(-1, 1, 0.2)
    y = np.arange(-1, 1, 0.2)
    z = np.arange(-1, 1, 0.2)
    u = np.arange(-1, 10, 0.2)

    mx, my, mz, mu = np.meshgrid(x, y, z, u)
    expected = f4d(mx, my, mz, mu)

    interpolator = core.Bilinear3D()

    calculated = core.quadrivariate_float64(grid,
                                            mx.flatten(),
                                            my.flatten(),
                                            mz.flatten(),
                                            mu.flatten(),
                                            interpolator,
                                            num_threads=0,
                                            bounds_error=True)
    assert np.all(expected.flatten() == calculated)

    x = np.arange(-1, 1, 0.2)
    y = np.arange(-1, 1, 0.2)
    z = np.arange(-1, 1, 0.2)
    u = np.arange(-1, 10, 0.33333)

    mx, my, mz, mu = np.meshgrid(x, y, z, u)
    expected = f4d(mx, my, mz, mu)

    interpolator = core.Bilinear3D()

    calculated = core.quadrivariate_float64(grid,
                                            mx.flatten(),
                                            my.flatten(),
                                            mz.flatten(),
                                            mu.flatten(),
                                            interpolator,
                                            num_threads=0,
                                            bounds_error=False)
    assert np.nanstd(expected.flatten() - calculated) == pytest.approx(0)

    other = core.quadrivariate_float64(grid,
                                       mx.flatten(),
                                       my.flatten(),
                                       mz.flatten(),
                                       mu.flatten(),
                                       interpolator,
                                       num_threads=0,
                                       z_method="linear",
                                       u_method="linear",
                                       bounds_error=False)
    assert np.nanstd(other - calculated) == pytest.approx(0)

    other = core.quadrivariate_float64(grid,
                                       mx.flatten(),
                                       my.flatten(),
                                       mz.flatten(),
                                       mu.flatten(),
                                       interpolator,
                                       num_threads=0,
                                       z_method="linear",
                                       u_method="nearest",
                                       bounds_error=False)
    assert np.nanstd(other - calculated) == pytest.approx(0, abs=1e-1)

    with pytest.raises(ValueError):
        other = core.quadrivariate_float64(grid,
                                           mx.flatten(),
                                           my.flatten(),
                                           mz.flatten(),
                                           None,
                                           interpolator,
                                           num_threads=0,
                                           z_method="linear",
                                           u_method="nearest",
                                           bounds_error=False)

    with pytest.raises(ValueError):
        other = core.quadrivariate_float64(grid,
                                           mx.flatten(),
                                           my.flatten(),
                                           mz.flatten(),
                                           mu.flatten(),
                                           interpolator,
                                           num_threads=0,
                                           z_method="LINEAR",
                                           u_method="nearest",
                                           bounds_error=False)

    with pytest.raises(ValueError):
        other = core.quadrivariate_float64(grid,
                                           mx.flatten(),
                                           my.flatten(),
                                           mz.flatten(),
                                           mu.flatten(),
                                           interpolator,
                                           num_threads=0,
                                           z_method="linear",
                                           u_method="NEAREST",
                                           bounds_error=False)