How to use the pyinterp.core 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 / 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_cartesian.py View on Github external
def _load_data(cls):
        with netCDF4.Dataset(cls.GRID) as ds:
            z = ds.variables['tcw'][:].T
            z[z.mask] = float("nan")
            return core.cartesian.Trivariate(
                core.Axis(ds.variables['longitude'][:], is_circle=True),
                core.Axis(ds.variables['latitude'][:]),
                core.Axis(ds.variables['time'][:]), z.data)
github CNES / pangeo-pyinterp / tests / core / test_binning.py View on Github external
def test_binning2d_acessors(self):
        x_axis = core.Axis(np.linspace(-180, 180, 10), is_circle=True)
        y_axis = core.Axis(np.linspace(-90, 90, 10))

        binning = core.Binning2DFloat64(x_axis, y_axis)
        self.assertIsInstance(binning.x, core.Axis)
        self.assertIsInstance(binning.y, core.Axis)
        # The class must return a reference on the axes provided during
        # construction
        self.assertEqual(id(x_axis), id(binning.x))
        self.assertEqual(id(y_axis), id(binning.y))

        binning.clear()
        count = binning.count()
        self.assertIsInstance(count, np.ndarray)
        self.assertEqual(count.size, len(x_axis) * len(y_axis))
        self.assertEqual(count.mean(), 0)
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 / core / test_trivariate.py View on Github external
def test_trivariate_bicubic(self):
        """Testing of the bicubic interpolation"""
        grid = self.load_data()
        lon = np.arange(-180, 180, 1 / 3.0) + 1 / 3.0
        lat = np.arange(-80, 80, 1 / 3.0) + 1 / 3.0
        time = 898524 + 3
        x, y, t = np.meshgrid(lon, lat, time, indexing='ij')
        z0 = core.bicubic_float64(grid,
                                  x.flatten(),
                                  y.flatten(),
                                  t.flatten(),
                                  fitting_model=core.FittingModel.Akima,
                                  bounds_error=True,
                                  num_threads=0)
        z1 = core.bicubic_float64(grid,
                                  x.flatten(),
                                  y.flatten(),
                                  t.flatten(),
                                  fitting_model=core.FittingModel.Akima,
                                  bounds_error=True,
                                  num_threads=1)
        shape = (len(lon), len(lat))
        z0 = np.ma.fix_invalid(z0)
        z1 = np.ma.fix_invalid(z1)
github CNES / pangeo-pyinterp / tests / test_fill.py View on Github external
def _load(cls, cube=False):
        ds = netCDF4.Dataset(cls.GRID)
        x_axis = pyinterp.core.Axis(ds.variables["lon"][::5], is_circle=True)
        y_axis = pyinterp.core.Axis(ds.variables["lat"][::5])
        mss = ds.variables["mss"][::5, ::5].T
        mss[mss.mask] = float("nan")
        if cube:
            z_axis = pyinterp.core.Axis(np.arange(2))
            mss = np.stack([mss.data] * len(z_axis)).transpose(1, 2, 0)
            return pyinterp.grid.Grid3D(x_axis, y_axis, z_axis, mss)
        return pyinterp.grid.Grid2D(x_axis, y_axis, mss.data)
github CNES / pangeo-pyinterp / tests / core / test_trivariate.py View on Github external
def test_trivariate_bicubic(self):
        """Testing of the bicubic interpolation"""
        grid = self.load_data()
        lon = np.arange(-180, 180, 1 / 3.0) + 1 / 3.0
        lat = np.arange(-80, 80, 1 / 3.0) + 1 / 3.0
        time = 898524 + 3
        x, y, t = np.meshgrid(lon, lat, time, indexing='ij')
        z0 = core.bicubic_float64(grid,
                                  x.flatten(),
                                  y.flatten(),
                                  t.flatten(),
                                  fitting_model=core.FittingModel.Akima,
                                  bounds_error=True,
                                  num_threads=0)
        z1 = core.bicubic_float64(grid,
                                  x.flatten(),
                                  y.flatten(),
                                  t.flatten(),
                                  fitting_model=core.FittingModel.Akima,
                                  bounds_error=True,
                                  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),
                 "tcw_bicubic.png")