How to use the pyinterp.Axis 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_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 / test_fill.py View on Github external
first_guess='zero',
                                                num_threads=0)
        data = np.copy(grid.array)
        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
self.assertNotEqual((z - other).mean(), 0)

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

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

        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())
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_grid.py View on Github external
def test__core_function_suffix(self):
        with self.assertRaises(TypeError):
            pyinterp.interface._core_function_suffix(1)

        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[:])
        self.assertEqual(
            pyinterp.interface._core_function_suffix(
                pyinterp.core.Grid2DFloat64(lon, lat, matrix.T)), "float64")
        self.assertEqual(
            pyinterp.interface._core_function_suffix(
                pyinterp.core.Grid2DFloat32(lon, lat, matrix.T)), "float32")
github CNES / pangeo-pyinterp / tests / test_interpolator.py View on Github external
fitting_model=fitting_model)
            self.assertNotEqual((z - other).mean(), 0)

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

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

        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())
github CNES / pangeo-pyinterp / tests / test_interpolator.py View on Github external
lat=y.flatten()),
                                 fitting_model=fitting_model)
            self.assertNotEqual((z - other).mean(), 0)

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

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

        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):
github CNES / pangeo-pyinterp / tests / test_fill.py View on Github external
num_threads=0)
        data = np.copy(grid.array)
        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)