How to use the pyinterp.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_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(
            collections.OrderedDict(lon=x.flatten(), lat=y.flatten()))
        self.assertIsInstance(z, np.ndarray)
github CNES / pangeo-pyinterp / tests / test_interpolator.py View on Github external
x_axis = pyinterp.Axis(np.linspace(-180, 179, 360), is_circle=True)
        y_axis = pyinterp.Axis(np.linspace(-90, 90, 181), is_circle=False)
        z_axis = pyinterp.Axis(np.linspace(0, 10, 10), is_circle=False)
        matrix, _ = np.meshgrid(x_axis[:], y_axis[:])
        grid = pyinterp.Grid2D(x_axis, y_axis, matrix.T)

        self.assertIsInstance(grid, pyinterp.Grid2D)
        with self.assertRaises(ValueError):
            pyinterp.bicubic(grid, x.flatten(), y.flatten(), fitting_model='_')
        with self.assertRaises(ValueError):
            pyinterp.bicubic(grid, x.flatten(), y.flatten(), boundary='_')
        grid = pyinterp.Grid2D(x_axis.flip(inplace=False), y_axis, matrix.T)
        with self.assertRaises(ValueError):
            pyinterp.bicubic(grid, x.flatten(), y.flatten())

        grid = pyinterp.Grid2D(x_axis, y_axis.flip(), matrix.T)
        with self.assertRaises(ValueError):
            pyinterp.bicubic(grid, x.flatten(), y.flatten())

        matrix, _, _ = np.meshgrid(x_axis[:], y_axis[:], z_axis[:])
        grid = pyinterp.Grid3D(x_axis, y_axis, z_axis,
                               matrix.transpose(1, 0, 2))
        with self.assertRaises(ValueError):
            pyinterp.bicubic(grid, x.flatten(), y.flatten())
github CNES / pangeo-pyinterp / tests / test_interpolator.py View on Github external
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)
        lat = pyinterp.Axis(np.linspace(-80, 80, 50), is_circle=False)
        array, _ = np.meshgrid(lon[:], lat[:])

        with self.assertRaises(ValueError):
            pyinterp.Grid2D(lon, lat, array)

        grid = pyinterp.Grid2D(lon, lat, array.T)

        self.assertIsInstance(grid, pyinterp.Grid2D)
        self.assertIsInstance(str(grid), str)

        with self.assertRaises(ValueError):
            pyinterp.Grid2D(lon, lat, array, increasing_axes='_')
github CNES / pangeo-pyinterp / tests / test_grid.py View on Github external
def test_core_class_suffix(self):
        lon = pyinterp.Axis(np.arange(0, 360, 1), is_circle=True)
        lat = pyinterp.Axis(np.arange(-80, 80, 1), is_circle=False)
        for dtype in [
                "float64", "float32", "int64", "uint64", "int32", "uint32",
                "int16", "uint16", "int8", "uint8"
        ]:
            matrix, _ = np.meshgrid(lon[:], lat[:])
            self.assertIsInstance(
                pyinterp.Grid2D(lon, lat,
                                matrix.T.astype(dtype=getattr(np, dtype))),
                pyinterp.Grid2D)

        with self.assertRaises(ValueError):
            pyinterp.Grid2D(lon, lat, matrix.astype(np.complex))
github CNES / pangeo-pyinterp / tests / test_fill.py View on Github external
data[np.isnan(data)] = 0
        filled0[np.isnan(filled0)] = 0
        filled1[np.isnan(filled1)] = 0
        filled2[np.isnan(filled2)] = 0
        self.assertEqual((filled0 - filled1).mean(), 0)
        self.assertEqual(np.ma.fix_invalid(grid.array - filled1).mean(), 0)
        self.assertNotEqual((data - filled1).mean(), 0)
        self.assertNotEqual((filled2 - filled1).mean(), 0)

        with self.assertRaises(ValueError):
            pyinterp.fill.gauss_seidel(grid, '_')

        x_axis = pyinterp.Axis(np.linspace(-180, 180, 10), is_circle=True)
        y_axis = pyinterp.Axis(np.linspace(-90, 90, 10), is_circle=False)
        data = np.random.rand(len(x_axis), len(y_axis))
        grid = pyinterp.Grid2D(x_axis, y_axis, data)
        _, filled0 = pyinterp.fill.gauss_seidel(grid, num_threads=0)
        self.assertIsInstance(filled0, np.ndarray)
github CNES / pangeo-pyinterp / tests / test_interpolator.py View on Github external
bounds_error=True)

        lon = pyinterp.Axis(np.linspace(0, 360, 100), is_circle=True)
        lat = pyinterp.Axis(np.linspace(-80, 80, 50), is_circle=False)
        array, _ = np.meshgrid(lon[:], lat[:])

        with self.assertRaises(ValueError):
            pyinterp.Grid2D(lon, lat, array)

        grid = pyinterp.Grid2D(lon, lat, array.T)

        self.assertIsInstance(grid, pyinterp.Grid2D)
        self.assertIsInstance(str(grid), str)

        with self.assertRaises(ValueError):
            pyinterp.Grid2D(lon, lat, array, increasing_axes='_')
github CNES / pangeo-pyinterp / tests / test_interpolator.py View on Github external
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)
        lat = pyinterp.Axis(np.linspace(-80, 80, 50), is_circle=False)
        array, _ = np.meshgrid(lon[:], lat[:])

        with self.assertRaises(ValueError):
            pyinterp.Grid2D(lon, lat, array)

        grid = pyinterp.Grid2D(lon, lat, array.T)

        self.assertIsInstance(grid, pyinterp.Grid2D)
        self.assertIsInstance(str(grid), str)

        with self.assertRaises(ValueError):
            pyinterp.Grid2D(lon, lat, array, increasing_axes='_')
github CNES / pangeo-pyinterp / tests / test_grid.py View on Github external
def test_core_variate_interpolator(self):
        lon = pyinterp.Axis(np.arange(0, 360, 1), is_circle=True)
        lat = pyinterp.Axis(np.arange(-80, 80, 1), is_circle=False)
        matrix, _ = np.meshgrid(lon[:], lat[:])

        grid = pyinterp.Grid2D(lon, lat, matrix.T)

        with self.assertRaises(TypeError):
            pyinterp.grid._core_variate_interpolator(None, "_")

        with self.assertRaises(ValueError):
            pyinterp.grid._core_variate_interpolator(grid, '_')