Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init(self, dtype):
lon = np.arange(-180, 180, 10, dtype=dtype)
lat = np.arange(-90, 90, 10, dtype=dtype)
lon, lat = np.meshgrid(lon, lat)
data = lon * 0
mesh = pyinterp.RTree(dtype=dtype)
self.assertIsInstance(mesh, pyinterp.RTree)
self.assertEqual(len(mesh), 0)
self.assertFalse(bool(mesh))
mesh.packing(
np.vstack((lon.flatten(), lat.flatten())).T, data.flatten())
self.assertEqual(len(mesh), len(lon.flatten()))
self.assertTrue(bool(mesh))
(x_min, y_min, z_min), (x_max, y_max, z_max) = mesh.bounds()
self.assertEqual(x_min, -180)
self.assertEqual(y_min, -90.0)
self.assertEqual(x_max, 180.0)
self.assertEqual(y_max, 80)
self.assertAlmostEqual(z_min,
0,
delta=1e-6 if dtype == np.float64 else 0.5)
self.assertAlmostEqual(z_max,
def test_init(self):
self.init(dtype=np.float32)
self.init(dtype=np.float64)
with self.assertRaises(ValueError):
self.init(np.int8)
with self.assertRaises(ValueError):
mesh = pyinterp.RTree()
mesh.__setstate__((1, ))
def load_data(self):
ds = xr.load_dataset(self.GRID)
z = ds.mss.T
x, y = np.meshgrid(ds.lon.values, ds.lat.values, indexing='ij')
mesh = pyinterp.RTree()
mesh.packing(
np.vstack((x.flatten(), y.flatten())).T, z.values.flatten())
return mesh
self.assertEqual(y_min, -90.0)
self.assertEqual(x_max, 180.0)
self.assertEqual(y_max, 80)
self.assertAlmostEqual(z_min,
0,
delta=1e-6 if dtype == np.float64 else 0.5)
self.assertAlmostEqual(z_max,
0,
delta=1e-6 if dtype == np.float64 else 0.5)
mesh.clear()
self.assertEqual(len(mesh), 0)
self.assertFalse(bool(mesh))
mesh.insert(
np.vstack((lon.flatten(), lat.flatten())).T, data.flatten())
self.assertEqual(len(mesh), len(lon.flatten()))
self.assertIsInstance(pickle.loads(pickle.dumps(mesh)), pyinterp.RTree)