How to use the pyinterp.backends.xarray.Grid2D function in pyinterp

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_interpolator.py View on Github external
def test_bicubic(self):
        grid = pyinterp.backends.xarray.Grid2D(xr.load_dataset(self.GRID).mss)

        lon = np.arange(-180, 180, 1) + 1 / 3.0
        lat = np.arange(-90, 90, 1) + 1 / 3.0
        x, y = np.meshgrid(lon, lat, indexing="ij")

        z = grid.bicubic(
            collections.OrderedDict(lon=x.flatten(), lat=y.flatten()))
        self.assertIsInstance(z, np.ndarray)

        for fitting_model in [
                'linear', 'polynomial', 'c_spline', 'c_spline_periodic',
                'akima', 'akima_periodic', 'steffen'
        ]:
            other = grid.bicubic(collections.OrderedDict(lon=x.flatten(),
                                                         lat=y.flatten()),
                                 fitting_model=fitting_model)
github CNES / pangeo-pyinterp / tests / test_interpolator.py View on Github external
def test_biavariate(self):
        grid = pyinterp.backends.xarray.Grid2D(xr.load_dataset(self.GRID).mss)

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

        self.assertIsInstance(grid.x, pyinterp.Axis)
        self.assertIsInstance(grid.y, 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
        x, y = np.meshgrid(lon, lat, indexing="ij")

        z = grid.bivariate(
github CNES / pangeo-pyinterp / tests / test_interpolator.py View on Github external
z = grid.bivariate(
            collections.OrderedDict(lon=x.flatten(), lat=y.flatten()))
        self.assertIsInstance(z, np.ndarray)

        z = grid.bivariate(collections.OrderedDict(lon=x.flatten(),
                                                   lat=y.flatten()),
                           interpolator="nearest")
        self.assertIsInstance(z, np.ndarray)

        z = grid.bivariate(collections.OrderedDict(lon=x.flatten(),
                                                   lat=y.flatten()),
                           interpolator="inverse_distance_weighting")
        self.assertIsInstance(z, np.ndarray)

        grid = pyinterp.backends.xarray.Grid2D(xr.load_dataset(self.GRID).mss,
                                               geodetic=False)

        self.assertIsInstance(grid, pyinterp.backends.xarray.Grid2D)
        w = grid.bivariate(collections.OrderedDict(lon=x.flatten(),
                                                   lat=y.flatten()),
                           interpolator="inverse_distance_weighting")
        self.assertNotEqual(
            np.ma.fix_invalid(z).mean(),
            np.ma.fix_invalid(w).mean())

        with self.assertRaises(ValueError):
            grid.bivariate(collections.OrderedDict(lon=x.flatten(),
                                                   lat=y.flatten()),
                           bounds_error=True)

        lon = pyinterp.Axis(np.linspace(0, 360, 100), is_circle=True)