How to use the pyinterp.core.geodetic 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_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]))
github CNES / pangeo-pyinterp / tests / core / test_geodetic.py View on Github external
def test_pickle(self):
        """Serialization tests"""
        min_corner = core.geodetic.Point2D(0, 1)
        max_corner = core.geodetic.Point2D(2, 3)
        a = core.geodetic.Box2D(min_corner, max_corner)
        b = pickle.loads(pickle.dumps(a))
        self.assertEqual(a.min_corner.lon, b.min_corner.lon)
        self.assertEqual(a.min_corner.lat, b.min_corner.lat)
        self.assertEqual(a.max_corner.lon, b.max_corner.lon)
        self.assertEqual(a.max_corner.lat, b.max_corner.lat)
github CNES / pangeo-pyinterp / tests / core / test_rtree.py View on Github external
with netCDF4.Dataset(cls.GRID) as ds:
            z = ds.variables['mss'][:].T
            z[z.mask] = float("nan")
            x = ds.variables['lon'][:]
            y = ds.variables['lat'][:]
            # Since insertion is slower, the data are sub-sampled to avoid
            # the test being too long.
            if not packing:
                x = x[::5]
                y = y[::5]
                z = z[::5, ::5]
            x = x.astype("float32")
            y = y.astype("float32")
            z = z.astype("float32")
            x, y = np.meshgrid(x, y, indexing='ij')
            mesh = core.RTree3DFloat32(core.geodetic.System())
            if packing:
                mesh.packing(
                    np.vstack((x.flatten(), y.flatten())).T, z.data.flatten())
            else:
                mesh.insert(
                    np.vstack((x.flatten(), y.flatten())).T, z.data.flatten())
            return mesh
github CNES / pangeo-pyinterp / tests / core / test_geodetic.py View on Github external
def test_system_operators(self):
        """Test operators"""
        wgs84 = core.geodetic.System()
        # https://en.wikipedia.org/wiki/Geodetic_Reference_System_1980
        grs80 = core.geodetic.System(6378137, 1 / 298.257222101)
        self.assertAlmostEqual(grs80.semi_major_axis, 6378137)
        self.assertAlmostEqual(grs80.flattening, 1 / 298.257222101)
        self.assertEqual(wgs84, wgs84)
        self.assertNotEqual(wgs84, grs80)
github CNES / pangeo-pyinterp / tests / core / test_geodetic.py View on Github external
def test_system_wgs84(self):
        """Checking expected WGS-84 properties"""
        wgs84 = core.geodetic.System()
        # https://fr.wikipedia.org/wiki/WGS_84
        # https://en.wikipedia.org/wiki/Geodetic_datum
        # http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf
        self.assertAlmostEqual(wgs84.semi_major_axis, 6378137)
        self.assertAlmostEqual(wgs84.flattening, 1 / 298.257223563)
        self.assertAlmostEqual(wgs84.semi_minor_axis(),
                               6356752.314245179497563967)
        self.assertAlmostEqual(math.sqrt(wgs84.first_eccentricity_squared()),
                               0.081819190842622,
                               delta=1e-15)
        self.assertAlmostEqual(math.sqrt(wgs84.second_eccentricity_squared()),
                               8.2094437949696 * 1e-2,
                               delta=1e-15)
        self.assertAlmostEqual(wgs84.equatorial_circumference() * 1e-3,
                               40075.017,
                               delta=1e-3)