How to use pyinterp - 10 common examples

To help you get started, we’ve selected a few pyinterp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CNES / pangeo-pyinterp / tests / test_cartesian.py View on Github external
def test_nearest(self):
        self._test(core.cartesian.Nearest3D(), "mss_cartesian_nearest3d")
github CNES / pangeo-pyinterp / tests / core / test_trivariate.py View on Github external
def test_grid3d_init(self):
        """Test construction and accessors of the object"""
        grid = self.load_data()
        self.assertIsInstance(grid.x, core.Axis)
        self.assertIsInstance(grid.y, core.Axis)
        self.assertIsInstance(grid.z, core.Axis)
        self.assertIsInstance(grid.array, np.ndarray)
github CNES / pangeo-pyinterp / tests / core / test_trivariate.py View on Github external
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)
github CNES / pangeo-pyinterp / tests / test_binning.py View on Github external
def init(self, dtype):
        ds = xr.load_dataset(self.GRID)

        x_axis = pyinterp.Axis(np.arange(-180, 180, 5), is_circle=True)
        y_axis = pyinterp.Axis(np.arange(-90, 95, 5))
        binning = pyinterp.Binning2D(x_axis,
                                     y_axis,
                                     pyinterp.geodetic.System(),
                                     dtype=dtype)
        self.assertEqual(x_axis, binning.x)
        self.assertEqual(y_axis, binning.y)
        self.assertIsInstance(str(binning), str)

        lon, lat = np.meshgrid(ds.lon, ds.lat)
        binning.push(lon, lat, ds.mss, simple=True)
        simple_mean = binning.variable('mean')
        self.assertIsInstance(simple_mean, np.ndarray)

        binning.clear()
        binning.push(lon, lat, ds.mss, simple=False)
        linear_mean = binning.variable('mean')
github CNES / pangeo-pyinterp / tests / test_interpolator.py View on Github external
def test(self):
        grid = pyinterp.backends.xarray.Grid3D(xr.load_dataset(self.GRID).tcw,
                                               increasing_axes=True)

        self.assertIsInstance(grid, pyinterp.backends.xarray.Grid3D)
        self.assertIsInstance(grid, pyinterp.Grid3D)
        other = pickle.loads(pickle.dumps(grid))
        self.assertIsInstance(other, pyinterp.backends.xarray.Grid3D)
        self.assertIsInstance(grid, pyinterp.Grid3D)

        self.assertIsInstance(grid.x, pyinterp.Axis)
        self.assertIsInstance(grid.y, pyinterp.Axis)
        self.assertIsInstance(grid.z, pyinterp.Axis)
        self.assertIsInstance(grid.array, np.ndarray)

        lon = np.arange(-180, 180, 1) + 1 / 3.0
        lat = np.arange(-90, 90, 1) + 1 / 3.0
        time = np.array([datetime.datetime(2002, 7, 2, 15, 0)],
                        grid.time_unit())
        x, y, t = np.meshgrid(lon, lat, time, indexing="ij")

        z = grid.trivariate(
            collections.OrderedDict(longitude=x.flatten(),
                                    latitude=y.flatten(),
                                    time=t.flatten()))
        self.assertIsInstance(z, np.ndarray)

        z = grid.bicubic(
            collections.OrderedDict(longitude=x.flatten()[1:2],
github CNES / pangeo-pyinterp / tests / test_binning.py View on Github external
def init(self, dtype):
        ds = xr.load_dataset(self.GRID)

        x_axis = pyinterp.Axis(np.arange(-180, 180, 5), is_circle=True)
        y_axis = pyinterp.Axis(np.arange(-90, 95, 5))
        binning = pyinterp.Binning2D(x_axis,
                                     y_axis,
                                     pyinterp.geodetic.System(),
                                     dtype=dtype)
        self.assertEqual(x_axis, binning.x)
        self.assertEqual(y_axis, binning.y)
        self.assertIsInstance(str(binning), str)

        lon, lat = np.meshgrid(ds.lon, ds.lat)
        binning.push(lon, lat, ds.mss, simple=True)
        simple_mean = binning.variable('mean')
        self.assertIsInstance(simple_mean, np.ndarray)

        binning.clear()
        binning.push(lon, lat, ds.mss, simple=False)
github CNES / pangeo-pyinterp / tests / core / test_trivariate.py View on Github external
def _test(self, interpolator, filename):
        """Testing an interpolation method."""
        grid = self.load_data()
        lon = np.arange(-180, 180, 1 / 3.0) + 1 / 3.0
        lat = np.arange(-90, 90, 1 / 3.0) + 1 / 3.0
        time = 898500 + 3
        x, y, t = np.meshgrid(lon, lat, time, indexing="ij")
        z0 = core.trivariate_float64(grid,
                                     x.flatten(),
                                     y.flatten(),
                                     t.flatten(),
                                     interpolator,
                                     num_threads=0)
        z1 = core.trivariate_float64(grid,
                                     x.flatten(),
                                     y.flatten(),
                                     t.flatten(),
                                     interpolator,
                                     num_threads=1)
        shape = (len(lon), len(lat))
        z0 = np.ma.fix_invalid(z0)
        z1 = np.ma.fix_invalid(z1)
        self.assertTrue(np.all(z1 == z0))
        if HAVE_PLT:
            plot(x.reshape(shape), y.reshape(shape), z0.reshape(shape),
                 filename)
        return z0
github CNES / pangeo-pyinterp / tests / core / test_trivariate.py View on Github external
def _test(self, interpolator, filename):
        """Testing an interpolation method."""
        grid = self.load_data()
        lon = np.arange(-180, 180, 1 / 3.0) + 1 / 3.0
        lat = np.arange(-90, 90, 1 / 3.0) + 1 / 3.0
        time = 898500 + 3
        x, y, t = np.meshgrid(lon, lat, time, indexing="ij")
        z0 = core.trivariate_float64(grid,
                                     x.flatten(),
                                     y.flatten(),
                                     t.flatten(),
                                     interpolator,
                                     num_threads=0)
        z1 = core.trivariate_float64(grid,
                                     x.flatten(),
                                     y.flatten(),
                                     t.flatten(),
                                     interpolator,
                                     num_threads=1)
        shape = (len(lon), len(lat))
        z0 = np.ma.fix_invalid(z0)
        z1 = np.ma.fix_invalid(z1)
        self.assertTrue(np.all(z1 == z0))
        if HAVE_PLT:
github CNES / pangeo-pyinterp / tests / core / test_geodetic.py View on Github external
def test_box2d_init(self):
        """Test construction and accessors of the object"""
        min_corner = core.geodetic.Point2D(0, 1)
        max_corner = core.geodetic.Point2D(2, 3)

        box = core.geodetic.Box2D(min_corner, max_corner)
        self.assertEqual(str(box), "((0, 1), (2, 3))")
        self.assertEqual(box.min_corner.lon, 0)
        self.assertEqual(box.min_corner.lat, 1)
        self.assertEqual(box.max_corner.lon, 2)
        self.assertEqual(box.max_corner.lat, 3)

        self.assertTrue(box.covered_by(min_corner))
        self.assertTrue(box.covered_by(max_corner))
        self.assertTrue(box.covered_by(core.geodetic.Point2D(1, 2)))
        self.assertFalse(box.covered_by(core.geodetic.Point2D(0, 0)))

        flags = box.covered_by([1, 0], [2, 0])
        self.assertTrue(np.all(flags == [1, 0]))

        box.min_corner, box.max_corner = max_corner, min_corner
        self.assertEqual(box.min_corner.lon, 2)
        self.assertEqual(box.min_corner.lat, 3)
        self.assertEqual(box.max_corner.lon, 0)
        self.assertEqual(box.max_corner.lat, 1)
github CNES / pangeo-pyinterp / tests / core / test_geodetic.py View on Github external
def test_box2d_init(self):
        """Test construction and accessors of the object"""
        min_corner = core.geodetic.Point2D(0, 1)
        max_corner = core.geodetic.Point2D(2, 3)

        box = core.geodetic.Box2D(min_corner, max_corner)
        self.assertEqual(str(box), "((0, 1), (2, 3))")
        self.assertEqual(box.min_corner.lon, 0)
        self.assertEqual(box.min_corner.lat, 1)
        self.assertEqual(box.max_corner.lon, 2)
        self.assertEqual(box.max_corner.lat, 3)

        self.assertTrue(box.covered_by(min_corner))
        self.assertTrue(box.covered_by(max_corner))
        self.assertTrue(box.covered_by(core.geodetic.Point2D(1, 2)))
        self.assertFalse(box.covered_by(core.geodetic.Point2D(0, 0)))

        flags = box.covered_by([1, 0], [2, 0])
        self.assertTrue(np.all(flags == [1, 0]))

        box.min_corner, box.max_corner = max_corner, min_corner
        self.assertEqual(box.min_corner.lon, 2)
        self.assertEqual(box.min_corner.lat, 3)
        self.assertEqual(box.max_corner.lon, 0)
        self.assertEqual(box.max_corner.lat, 1)