Esempio n. 1
0
 def test_save(self):
     dem = Grid(infolder + "/small25.tif")
     dem.save(outfolder + "/a_dummy_dem.tif")
     dem2 = Grid(outfolder + "/a_dummy_dem.tif")
     expected = dem.get_value([20, 30, 40, 50], [20, 30, 40, 50])
     computed = dem2.get_value([20, 30, 40, 50], [20, 30, 40, 50])
     self.assertEqual(np.array_equal(computed, expected), True)
Esempio n. 2
0
 def test_save_02(self):
     # Testing nodata with value of Zero
     dem = Grid()
     np.random.seed(1)
     arr = np.random.randint(0, 100, (25, 25))
     arr[np.where(arr%5==0)] = 0
     dem.set_array(arr)
     dem.set_nodata(0)
     dem.save(outfolder + "/a_dummy_dem2.tif")
     # Open with gdal
     raster = gdal.Open(outfolder + "/a_dummy_dem2.tif")
     banda = raster.GetRasterBand(1)
     nodata = banda.GetNoDataValue()
     self.assertEqual(nodata, 0)
Esempio n. 3
0
outgrid._size = (ncol, nrow)
outgrid._dims = (nrow, ncol)
geot = net._geot
ULx = geot[0] + geot[1] * c1
ULy = geot[3] + geot[5] * r1
outgrid._geot = (ULx, geot[1], 0.0, ULy, 0.0, geot[5])
outgrid._cellsize = geot[1]
outgrid._proj = net._proj
outgrid._ncells = basin_cl.size
outgrid._nodata = 0
outgrid._array = basin_cl
outgrid._tipo = str(basin.dtype)

fd.get_drainage_basins(net.snap_points(outlet)).save(outfolder +
                                                     "/basin_orig.tif")
outgrid.save(outfolder + "/basin_test.tif")

# GET ONLY POINTS INSIDE BASIN
basin = basin.astype(np.bool).ravel()
I = basin[net._ix]

ix = net._ix[I]
ixc = net._ixc[I]

# Get grid channel cells
w = np.zeros(net._ncells, dtype=np.int8)
w[ix] = 1
w[ixc] = 1
w = w.reshape(net._dims)

plt.imshow(w)