def test_snap_poi_02(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 # Obtenemos lista con Flow Accumulations cells fac = fd.get_flow_accumulation(nodata=False, asgrid=False) ch_cells = np.where(fac.ravel() >= thr)[0] # Hacemos snap a celdas de canal snap_pp = fd.snap_points(puntos, thr, kind="channel") row, col = fd.xy_2_cell(snap_pp[:, 0], snap_pp[:, 1]) inds = fd.cell_2_ind(row, col) # Comprobamos que punto esta entre los POI for ind in inds: res = ind in ch_cells self.assertEqual(res, 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)
# 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]), (input_points[n, 0], input_points[n, 1])) out_p = snap_points(fd, input_points, 500, kind, remove_duplicates=True)