示例#1
0
    def test_fill_05(self):
        dem = DEM(infolder + "/tunez.tif")
        fill = dem.fill_sinks().read_array().astype("int16")

        mfill = sio.loadmat(infolder + '/mlab_files/fill_tunez.mat')['fill']
        mfill = mfill.astype("int16")
        # Matlab files contain "nan" in the nodata positions
        nodatapos = dem.get_nodata_pos()
        mfill[nodatapos] = dem.get_nodata()

        computed = np.array_equal(fill, mfill)
        self.assertEqual(computed, True)
示例#2
0
    def test_fill_01(self):
        arr = np.array([[49, 36, 29, 29], [32, 19, 17, 20], [19, 18, 31, 39],
                        [19, 29, 42, 51]])
        dem = DEM()
        dem.set_array(arr)
        fill = dem.fill_sinks()
        computed = fill.read_array().tolist()
        arr = np.array([[49, 36, 29, 29], [32, 19, 19, 20], [19, 19, 31, 39],
                        [19, 29, 42, 51]])
        expected = arr.tolist()

        self.assertEqual(computed, expected)
示例#3
0
    def test_fill_03(self):
        arr = np.array([[49, 36, 29, 29], [32, 17, 12, 20], [19, 17, 19, 39],
                        [19, 29, 42, -99]])
        dem = DEM()
        dem.set_nodata(-99)
        dem.set_array(arr)
        fill = dem.fill_sinks()
        computed = fill.read_array(False).tolist()
        arr = np.array([[49, 36, 29, 29], [32, 19, 19, 20], [19, 19, 19, 39],
                        [19, 29, 42, -99]])

        expected = arr.tolist()

        self.assertEqual(computed, expected)
示例#4
0
    def test_identify_flats_02(self):
        # Create a DEM object and make fill
        dem = DEM(infolder + "/small25.tif")
        fill = dem.fill_sinks()

        # Identify flats and sills and load arrays
        flats, sills = fill.identify_flats(nodata=False)
        flats = flats.read_array()
        sills = sills.read_array()

        # Load matlab flats and sills
        m_flats = sio.loadmat(infolder +
                              "/mlab_files/flats_small25.mat")['flats']
        m_sills = sio.loadmat(infolder +
                              "/mlab_files/sills_small25.mat")['sills']

        # Compare
        computed = (np.array_equal(m_flats,
                                   flats), np.array_equal(m_sills, sills))
        self.assertEqual(computed, (True, True))
示例#5
0
import time
# Add to the path code folder and data folder
sys.path.append("../../")
from topopy import DEM
from skimage import graph

start = time.time()

# Get DEM and fill sinks
dem = DEM("../data/tunez2.tif")
dims = dem._array.shape
ncells = dem._array.size

time_lap = time.time()
# 01 Fill sinks
fill = dem.fill_sinks()
topodiff = fill.read_array() - dem.read_array()
topodiff = topodiff.astype(np.float32)
dem = fill
print("Sinks filled -- {0:.3f} seconds".format(time.time() - time_lap))

time_lap = time.time()
# 02 Get flats and sills
flats, sills = dem.identify_flats(False)
print("Flats identified -- {0:.3f} seconds".format(time.time() - time_lap))

time_lap = time.time()
# 03 Create auxiliar topography for 'carve' option
tweight = 2
carvemin = 0.1
struct = np.ones((3, 3), dtype="int8")