Ejemplo n.º 1
0
 def test_flow_properties_02(self):
     # Testing an empty Flow object
     dem = DEM()
     fd = Flow()
     computed = (fd.get_size(), fd.get_dims(), fd.get_ncells(), fd.get_projection(), fd.get_cellsize(), fd.get_geotransform())
     expected = (dem.get_size(), dem.get_dims(), dem.get_ncells(), dem.get_projection(), dem.get_cellsize(), dem.get_geotransform())
     self.assertEqual(computed, expected)    
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
 def test_flow_properties_01(self):
     files = ["small", "small25", "morocco", "tunez", "jebja30"]
     for file in files:
         dem = DEM(infolder + "/{0}.tif".format(file))
         fd = Flow(infolder +  "/{0}_fd.tif".format(file))
         computed = (fd.get_size(), fd.get_dims(), fd.get_ncells(), fd.get_projection(), fd.get_cellsize(), fd.get_geotransform())
         expected = (dem.get_size(), dem.get_dims(), dem.get_ncells(), dem.get_projection(), dem.get_cellsize(), dem.get_geotransform())
         self.assertEqual(computed, expected)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
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))
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 def test_create_load(self):
     dem_files = ['tunez', 'tunez2', 'small25']
     for filename in dem_files:
         fd = Flow("data/fd_{0}.tif".format(filename))
         st = Network(fd, 1000)
         computed = [
             st.get_dims(),
             st.get_size(),
             st.get_ncells(),
             st.get_cellsize(),
             st.get_geotransform(),
             st.get_projection()
         ]
         expected = [
             fd.get_dims(),
             fd.get_size(),
             fd.get_ncells(),
             fd.get_cellsize(),
             fd.get_geotransform(),
             fd.get_projection()
         ]
         self.assertTrue(computed, expected)
Ejemplo n.º 9
0
    def test_stream_poi_01(self):
        files = ["small25", "morocco", "tunez", "jebja30"]
        for file in files:
            flw_path = infolder + "/{0}_fd.tif".format(file)
            dem_path = infolder + "/{0}.tif".format(file)
            net_path = infolder + "/{0}_network.net".format(file)
            dem = DEM(dem_path)
            fd = Flow(flw_path)
            thr = int(fd.get_ncells() * 0.01)

            # Creamos objeto network
            net = Network(dem, fd, thr)
            net.save(net_path)

            # Cargamos objeto network guardado
            net2 = Network(net_path)

            # Comparamos propiedades,
            prop_net = [
                net._size, net._dims, net._geot, net._cellsize, net._ncells,
                net._proj
            ]
            prop_net2 = [
                net2._size, net2._dims, net2._geot, net2._cellsize,
                net2._ncells, net2._proj
            ]
            self.assertEqual(prop_net, prop_net2)

            # Comparamos los datos
            arr1 = np.array(
                (net._ix, net._ixc, net._ax, net._dx, net._zx, net._chi,
                 net._slp, net._ksn, net._r2slp, net._r2ksn, net._dd))
            arr2 = np.array(
                (net2._ix, net2._ixc, net2._ax, net2._dx, net2._zx, net2._chi,
                 net2._slp, net2._ksn, net2._r2slp, net2._r2ksn, net2._dd))
            res = np.array_equal(arr1, arr2)
            self.assertEqual(res, True)
Ejemplo n.º 10
0
# -*- coding: utf-8 -*-
"""
Editor de Spyder

Este es un archivo temporal
"""

from topopy import DEM, Flow, Network

infolder = "data/in"
outfolder = "data/out"

files = ["small25", "morocco", "tunez", "jebja30"]
for file in files:
    flw_path = infolder +  "/{0}_fd.tif".format(file)
    dem_path = infolder +  "/{0}.tif".format(file)
    dem = DEM(dem_path)
    fd = Flow(flw_path)
    thr = int(fd.get_ncells() * 0.001)
    # Simplemente probamos que no hay fallos al crear el objeto net
    net = Network(dem, fd, thr)
    net.save(infolder + "/{0}_network.net".format(file))