Esempio n. 1
0
    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)
Esempio n. 2
0
    def test_drainage_basins_00(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)

            # Creamos 10 cuencas aleatorias
            ri = np.random.randint(0, fd._dims[0], 10)
            ci = np.random.randint(0, fd._dims[1], 10)
            xi, yi = fd.cell_2_xy(ri, ci)
            # Extract basins
            outlets = np.array((xi, yi)).T
            threshold = int(fd.get_ncells() * 0.05)
            snap_outlets = fd.snap_points(outlets, threshold, kind="channel")
            basins = fd.get_drainage_basins(snap_outlets)
            basins.save(outfolder + "/rnd_snap_basins_{0}".format(file))
Esempio n. 3
0
    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)
Esempio n. 4
0
# -*- coding: utf-8 -*-
"""
Editor de Spyder

Este es un archivo temporal
"""

from topopy import Flow
import numpy as np
import matplotlib.pyplot as pl

fd = Flow("../data/in/small25_fd.tif")

puntos = np.array([[470511.3, 4116528.4, 344], [470740.9, 4116920.4, 36]])

snap = fd.snap_points(puntos, 500)
cuencas = fd.get_drainage_basins(snap)
cuencas.save("../data/out/prueba_cuencas.tif")