Ejemplo n.º 1
0
# TODO: Major todo's
# - self.mask should be a raster
# - grid.clip_to should be able to take a raster (use _input_handler)

current_dir = os.path.dirname(os.path.realpath(__file__))
data_dir = os.path.abspath(os.path.join(current_dir, '../data'))
dir_path = os.path.join(data_dir, 'dir.asc')
dem_path = os.path.join(data_dir, 'dem.tif')
roi_path = os.path.join(data_dir, 'roi.tif')
eff_path = os.path.join(data_dir, 'eff.tif')
dinf_eff_path = os.path.join(data_dir, 'dinf_eff.tif')

# Initialize grid
grid = Grid()
crs = pyproj.Proj('epsg:4326', preserve_units=True)
grid.read_ascii(dir_path, 'dir', dtype=np.uint8, crs=crs)
grid.read_raster(dem_path, 'dem')
grid.read_raster(roi_path, 'roi')
grid.read_raster(eff_path, 'eff')
grid.read_raster(dinf_eff_path, 'dinf_eff')
# set nodata to 1
# why is that not working with grid.view() in test_accumulation?
#grid.eff[grid.eff==grid.eff.nodata] = 1
#grid.dinf_eff[grid.dinf_eff==grid.dinf_eff.nodata] = 1

# Initialize parameters
dirmap = (64, 128, 1, 2, 4, 8, 16, 32)
acc_in_frame = 76499
acc_in_frame_eff = 76498  # max value with efficiency
acc_in_frame_eff1 = 19125.5  # accumulation for raster cell with acc_in_frame with transport efficiency
cells_in_catch = 11422
Ejemplo n.º 2
0
import os
import numpy as np
from pysheds.grid import Grid

current_dir = os.path.dirname(os.path.realpath(__file__))
data_dir = os.path.abspath(os.path.join(current_dir, '../data'))
data_path = os.path.join(data_dir, 'dir.asc')

# Initialize grid
grid = Grid()
grid.read_ascii(data_path, 'dir', dtype=np.uint8)
# Initialize parameters
dirmap = (64,  128,  1,   2,    4,   8,    16,  32)
acc_in_frame = 77259
cells_in_catch = 11422
catch_shape = (159, 169)
max_distance = 208

# TODO: Need to test dtypes of different constructor methods

def test_dtype():
    assert(grid.dir.dtype == np.uint8)

def test_catchment():
    # Specify pour point
    x, y = -97.2937, 32.7371
    # Delineate the catchment
    grid.catchment(x, y, dirmap=dirmap, out_name='catch',
                recursionlimit=15000, xytype='label')
    assert(np.count_nonzero(grid.catch) == cells_in_catch)