hydro¶
Depression filling, D8, flow accumulation, slope and the compound topographic index.
quakecascade.hydro
¶
Terrain hydrology on a NumPy DEM grid: depression filling, D8, flow accumulation, CTI.
These kernels feed the Zhu et al. (2015) liquefaction model in
quakecascade.liquefaction, which needs a compound topographic index
(CTI) computed on ~1 km cells. Grids are 2-D float arrays, row 0 at the top
(north), NaN for nodata; the cell size is given in metres.
Ported from the PlanX engine/hydro.py (same author). The D8 pass is
vectorised over the eight neighbours with the same arithmetic and the same
fixed tie-break order; filling and accumulation keep the original queue
algorithms.
HYDRO1K_FLAT_TAN_SLOPE
module-attribute
¶
tan(slope) HYDRO1k substitutes where the slope is zero (USGS HYDRO1k
README, Sec. 3.2.5): "smaller than the smallest slope obtainable from a
1000 m data set with a 1 m vertical resolution".
D8_NEIGHBORS
module-attribute
¶
The eight D8 neighbours as (row offset, column offset, distance in cells, direction code), in the fixed order the tie-break depends on: E, SE, S, SW, W, NW, N, NE (ESRI/Jenson & Domingue 1988 power-of-two coding).
D8_OFFSETS
module-attribute
¶
Direction code -> (row offset, column offset).
fill_depressions
¶
Fill closed depressions by priority flood (Wang & Liu 2006).
Every cell is raised to the lowest spill elevation on a path to the grid edge, with 8-connectivity; interior nodata cells are not outlets. The result has flats where pits were; no epsilon gradient is imposed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dem
|
(rows, cols) array_like
|
Elevations; |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The filled DEM. |
References
Wang, L. & Liu, H. (2006). An efficient method for identifying and filling surface depressions in digital elevation models for hydrologic analysis and modelling. IJGIS 20(2), 193-213. doi:10.1080/13658810500433453
d8_steepest
¶
D8 steepest-descent direction and the gradient behind it, in one pass.
For each cell the neighbour with the largest drop / distance (distance
1 or sqrt(2) cells) is chosen; ties go to the first in D8_NEIGHBORS
order. A cell with no strictly lower finite neighbour (pit, flat, or
nodata edge) gets code 0 and gradient 0.0. Nodata cells get code 0 and
gradient 0.0 as well.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dem
|
(rows, cols) array_like
|
Elevations in metres; |
required |
cell_size_m
|
float
|
Cell width in metres. It scales the gradient only; the direction grid does not depend on it (O'Callaghan & Mark 1984). |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
dirs |
ndarray of uint8
|
D8 codes (1, 2, 4, ..., 128; 0 for no outflow). |
gradient |
ndarray of float
|
Steepest-descent gradient, rise over run (m/m). |
flow_accumulation
¶
D8 flow accumulation in cells (each cell counts itself), by Kahn's topological order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dirs
|
(rows, cols) array_like of int
|
D8 codes from |
required |
Returns:
| Type | Description |
|---|---|
ndarray of float
|
Number of cells draining through each cell, including itself. |
slope
¶
D8 steepest-descent gradient in m/m (rise over run).
The same quantity cti uses, so a slope fed to
quakecascade.liquefaction.vs30_from_slope agrees with the wetness
index. This is not a 3x3 Horn (1981) fit; on rough terrain the two differ.
Nodata cells return NaN.
cti
¶
Compound topographic index (wetness index), on the scale Zhu et al. (2015) need.
with a the specific catchment area (upstream area A w^2 per unit
contour width w, A the D8 flow accumulation in cells including the
cell itself) and tan(beta) the D8 steepest-descent gradient.
convention="hydro1k" (default) reproduces the USGS HYDRO1k layer that
the Zhu et al. (2015) liquefaction model was fitted on (USGS gfail
zhu_2015.ini reads it): CTI = ln((FA + 1) / tan(slope)) with
FA counted in 1-km cells (ISLSCP II HYDRO1k guide, Eq. 1) and
tan(slope) = 0.001 where the slope is zero (HYDRO1k README,
Sec. 3.2.5). For any cell size this is a in kilometres
(A * w / 1000, equal to FA + 1 at 1 km) with tan(beta)
floored at HYDRO1K_FLAT_TAN_SLOPE, so no cell is flatter than the
calibration data could be. Every cell with data gets a finite index.
convention="metres" is the textbook form (Beven & Kirkby 1979) with
a in metres and no floor: +inf on cells without a downslope
neighbour, and ln(1000) = 6.91 above the HYDRO1k scale elsewhere. Do
not feed it to Zhu et al. (2015): at Zhu's CTI coefficient (0.355) the
offset adds 2.45 to the logit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dem
|
(rows, cols) array_like
|
Elevations in metres; |
required |
cell_size_m
|
float
|
Cell width in metres. A DEM described in feet raises CTI by
|
required |
fill
|
bool
|
Fill depressions ( |
False
|
convention
|
('hydro1k', 'metres')
|
See above. |
"hydro1k"
|
Returns:
| Name | Type | Description |
|---|---|---|
cti |
ndarray of float
|
|
gradient |
ndarray of float
|
The D8 gradient (m/m) before any floor; |
References
Beven, K. J. & Kirkby, M. J. (1979). A physically based, variable contributing area model of basin hydrology. Hydrological Sciences Bulletin 24(1), 43-69. doi:10.1080/02626667909491834
U.S. Geological Survey. HYDRO1k Elevation Derivative Database, README, Sec. 3.2.3 and 3.2.5; ISLSCP II HYDRO1k Elevation-derived Products, Eq. 1. doi:10.3334/ORNLDAAC/1007