def test_stream_poi_01(self): # Test 10 random basins files = ["small25", "tunez", "jebja30"] for file in files: flw_path = infolder + "/{0}_fd.tif".format(file) fd = Flow(flw_path) thr = int(fd.get_ncells() * 0.0025) for kind in ["heads", "confluences", "outlets"]: poi = fd.get_stream_poi(thr, kind, "XY") spoi = np.loadtxt(infolder + "/{0}_{1}.txt".format(file, kind), delimiter=";", skiprows=1) compare = np.array_equal(poi, spoi) self.assertEqual(compare, True)
def test_stream_poi_02(self): dem_files = ['tunez.tif', 'small25.tif', "jebja30.tif"] for file in dem_files: dem = DEM(infolder + "/" + file) fd = Flow(dem) thr = int(fd.get_ncells() * 0.01) net = Network(fd, dem, thr) out01 = fd.get_stream_poi(thr, "confluences", "CELL") out02 = net.get_stream_poi("confluences", "CELL") computed = np.array_equal(out01, out02) print(file) self.assertEqual(computed, True)
def test_snap_poi_01(self): # Test 10 random basins files = ["small25", "morocco", "tunez", "jebja30"] for file in files: flw_path = infolder + "/{0}_fd.tif".format(file) fd = Flow(flw_path) thr = int(fd.get_ncells() * 0.01) # Obtenemos 20 puntos aleatorios x1, x2, y1, y2 = fd.get_extent() xi = (x2 - x1) * np.random.random(25) + x1 yi = (y2 - y1) * np.random.random(25) + y1 puntos = np.array((xi, yi)).T # Hacemos snap a los stream poi for kind in ["heads", "confluences", "outlets"]: poi = fd.get_stream_poi(thr, kind, "XY") snap_pp = fd.snap_points(puntos, thr, kind) # Comprobamos que punto esta entre los POI for row in snap_pp: res = row in poi self.assertEqual(res, True)
axis=1) else: out_p = poi[pos] # Remove duplicates if remove_duplicates: idx = np.unique(out_p[:, -1], return_index=True)[1] out_p = out_p[idx, :-1] return out_p kind = "confluences" fd = Flow("../data/in/small25_fd.tif") poi = fd.get_stream_poi(500, kind, "XY") # Generate 10 random points xmin, xmax, ymin, ymax = fd.get_extent() np.random.seed(1234) rnd_x = (xmax - xmin) * np.random.random(10) + xmin rnd_y = (ymax - ymin) * np.random.random(10) + ymin plt.scatter(rnd_x, rnd_y, c="r", s=10) plt.scatter(poi[:, 0], poi[:, 1], c="b", marker="s", s=20) input_points = np.array((rnd_x, rnd_y, np.arange(0, 1000, 100))).T for n in range(10): plt.annotate(str(input_points[n, 2]),