Normalized DTM from DTM Raster
Algorithm details: Technical Guide → Raster Smoothing and Normalized DTM
Maps the micro-topography of a DTM: the DTM minus the DTM smoothed by the mean or median of a
circular moving window. Ground higher than its surroundings (hummocks) is positive, ground lower
(hollows) is negative, and a plane, flat or sloping, is 0. It is the continuous surface that
Detect Hummock and Hollow from LiDAR Data writes as CHH_*.tif, made from a DTM
you already have instead of from the point cloud.
The DTM can be one raster, or a folder of DTM GeoTIFFs, such as the per-tile DTMs of Generate DTM from LiDAR Data. The files of a folder are read as one mosaic, so each cell's window reaches across the files' edges into the neighbouring files: the outputs join without seams, with the same values as one run on the merged DTM.
The tool:
- Converts
Min_ws, the window's diameter in metres, to the DTM's map units from its CRS, so a DTM in feet gets the same window. The DTM must be in a projected CRS.Min_wsmust be at least twice the cell size (a window of 3 cells across): 0.5 m on 0.25 m cells. The window is the cells whose centres lie within its radius, a true circle also on cells that aren't square. - For a folder, checks that the files share the CRS, the cell size and the grid (their corners whole cells apart), and warns about files that overlap. Where files overlap, the first file in name order wins: a later file's value is used only where the earlier ones have none.
- Reads the DTM in square tiles of
tile_sizecells, one after another, each with a buffer as wide as the window's radius, so every cell's window lies whole inside it: the tiles join with the same values as smoothing the whole DTM at once. - Smooths each tile by
Smooth_byover the window (cells with no value are left out, and near the DTM's edges the window holds only the cells inside the DTM), in parallel onprocessesthreads (all CPU cores but one by default), subtracts the smoothed DTM from the DTM, and writes the tile into the outputs on the DTM's grid: one output per DTM file, and withmerge_outputalso one merged output. A tile is smoothed once and written into every output it overlaps, so the merged output costs no more smoothing.
| Parameter | Type | Required | Description |
|---|---|---|---|
in_dtm |
raster or folder | Yes | DTM in a projected CRS, for example Merged_TIN_DTM.tif from Generate DTM from LiDAR Data or a GDAL .vrt, or a folder of DTM GeoTIFFs (*.tif) on one grid. In the GUI, ... picks a file and Folder... a folder. The outputs have the DTM's cells. |
out_folder |
directory (output) | Yes | Folder for the outputs. |
Smooth_by |
mean | median |
Yes | How the window smooths the DTM. The default is mean. |
Min_ws |
float | Yes | Diameter of the circular window in metres. The default is 3. |
merge_output |
bool | No | For a folder: true writes one normalized DTM over all the files, named after the folder, as well as the one per file; false (the default) writes only the one per file, on its grid. The values are the same either way. |
tile_size |
int | No | Cells per side of the tiles the DTM is read in. The default is 2000; smaller tiles use less memory. |
| Output | Contents |
|---|---|
ndtm_<DTM name>_<Smooth_by>_<Min_ws>m.tif |
Normalized DTM (m): positive on hummocks, negative in hollows. One per DTM file (<DTM name> is the file's name), and with merge_output also one for the folder (<DTM name> is the folder's name; no DTM file may have that name). |
Files in the DTM folder named ndtm_* (this tool's outputs), Merged_* (the mosaic the LiDAR tools
write next to their tiles, such as Merged_TIN_DTM.tif, which would overlap every tile) or
*.partial.tif (partly written files) are not read as DTMs. So the output folder of Generate DTM
from LiDAR Data can be given as it is, and the outputs can go into the DTM folder itself.
The tool runs in Python (numpy and numba) and needs no R. It reads the next tiles and writes the finished ones while it smooths, and on a machine with many cores it smooths a few tiles at once. It holds about 40 bytes per cell of the tiles in hand, about 0.2 GB for each 2000-cell tile, and at most a quarter of the free memory for a batch. A 2000 × 2000-cell tile with a 3 m window takes about 0.2 s on 0.25 m cells and 0.7 s on 0.1 m cells for the median (20 threads); the mean is faster, and a larger window takes longer, about in proportion to the cells in the circle. Smaller cells cost twice: more cells, and more cells in each window. For a large area at 0.1 m, the time is mostly the number of tiles times this, plus reading the DTM files, which is slower from a network drive. For a folder, the tool first reads every file's grid, with progress.
from beratools.modules.raster2products.ndtm_fr_dtmraster import ndtm_fr_dtmraster
ndtm_fr_dtmraster(in_dtm="dtm/Merged_TIN_DTM.tif", out_folder="ndtm", Smooth_by="median", Min_ws=3.0)
# the DTM tiles of Generate DTM from LiDAR Data: one output per tile, and also one merged output
ndtm_fr_dtmraster(in_dtm="dtm", out_folder="ndtm", Smooth_by="median", Min_ws=3.0)
ndtm_fr_dtmraster(in_dtm="dtm", out_folder="ndtm", Smooth_by="median", Min_ws=3.0, merge_output=True)
The function returns the list of the outputs written, the merged one first.
Command line
bt ndtm_fr_dtmraster # show the parameters
bt ndtm_fr_dtmraster --in_dtm dtm/Merged_TIN_DTM.tif --out_folder <out_dir> --Smooth_by median --Min_ws 3
bt ndtm_fr_dtmraster --in_dtm dtm --out_folder <out_dir> --Smooth_by median --Min_ws 3 --merge_output true