def setup(): t = np.linspace(0, 2 * np.pi, 1000) coast = karta.Line(zip(3 * np.sin(4 * t) * np.cos(5 * t), 2 * np.cos(3 * t)), crs=karta.crs.LonLatWGS84) x = np.linspace(-2, 2, 10) trench = karta.Line(zip(x, 0.1 * x**2 + 3), crs=karta.crs.LonLatWGS84) return coast, trench
def test_profile(self): path = karta.Line([(15.0, 15.0), (1484.0, 1484.0)], crs=karta.crs.Cartesian) pts, z = self.rast.profile(path, resolution=42.426406871192853, method="nearest") expected = self.rast[:, :].diagonal() self.assertEqual(len(pts), 49) self.assertTrue(np.allclose(z, expected))
def test_build(self): np.random.seed(49) geoms = [] for i in range(1000): offset = np.random.rand(1, 2)*5 line = karta.Line(np.random.rand(5, 2)+offset) geoms.append(line) tree = RTree(geoms, maxchildren=25) self.assertEqual(type(tree), RTree) return
def test_search_overlapping(self): np.random.seed(49) geoms = [] for i in range(1000): offset = np.random.rand(1, 2)*5 line = karta.Line(np.random.rand(5, 2)+offset) geoms.append(line) rtree = RTree(geoms, maxchildren=25) corner_geoms = rtree.search_overlapping((4, 4, 6, 6)) self.assertEqual(len(corner_geoms), 143) return
def test_build(self): np.random.seed(49) geoms = [] for i in range(1000): offset = np.random.rand(1, 2) * 5 line = karta.Line(np.random.rand(5, 2) + offset) geoms.append(line) tree = rtree.build_tree(geoms, max_children=25) self.assertEqual(type(tree), rtree.NonLeafNode) self.assertEqual(rtree.depth(tree), 3) self.assertEqual(len(tree.children), 6) return
def test_search(self): np.random.seed(49) geoms = [] for i in range(1000): offset = np.random.rand(1, 2) * 5 line = karta.Line(np.random.rand(5, 2) + offset) geoms.append(line) tree = rtree.build_tree(geoms, 25) corner_geoms = rtree.search(tree, (4, 4, 6, 6)) corner_geoms_exhaustive = [ g for g in geoms if rtree.overlaps(g.bbox, (4, 4, 6, 6)) ] self.assertEqual(len(corner_geoms), len(corner_geoms_exhaustive)) #self.assertEqual(set(corner_geoms), set(corner_geoms_exhaustive)) return
def test_profile(self): path = karta.Line([(15.0, 15.0), (1484.0, 1484.0)], crs=karta.crs.Cartesian) _, z = self.rast.profile(path, resolution=42.426406871192853, method="nearest") expected = self.rast.values.diagonal() self.assertTrue(np.allclose(z, expected)) return