Skip to content

Raster2Products API Reference

Tools API

Copyright (C) 2025 Applied Geospatial Research Group.

This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.

Description

Normalized DTM from a DTM raster, or from a folder of DTM rasters: the DTM minus the DTM smoothed by the mean or median of a circular moving window, so hummocks are positive and hollows negative (see beratools.modules.raster2products.algo_raster_smoothing). Pure Python: no R needed.

The files of a folder are read as one mosaic, so the windows reach across the files' edges and the outputs join without seams: one output per file, on its grid, and optionally one merged output.

Mosaic

Mosaic(files, gdal_env=None)

DTM files on one grid (same CRS and cell size, corners on the same grid), read as one raster.

Each file's cells are a rectangle of rows and columns of the grid, counted from the first file's top-left corner. Where files overlap, the first file in name order wins: the value of a later file is used only where the earlier ones have none.

overlaps

overlaps()

Pairs (i, j), i < j, of files whose cells overlap.

read

read(row, col, height, width)

The cells of a window of the grid (float64, NaN for no value, also outside the files).

output_name

output_name(in_dtm, smooth_by, min_ws)

ndtm_m.tif, with Min_ws written as R prints it (3, not 3.0). For a folder, the DTM name is the folder's name.

dtm_files

dtm_files(in_dtm)

The DTM file, or the GeoTIFFs of a folder in name order, leaving out this tool's outputs (ndtm_), Merged_ mosaics and partly written files (*.partial.tif).

sidecars_matter

sidecars_matter(path)

Whether the DTM file reads differently (CRS, grid, no-data value or mask) when GDAL doesn't look for sidecar files next to it.

batch_limits

batch_limits(threads)

Rows and cells a batch of tiles is filled up to on this machine.

ndtm_fr_dtmraster

ndtm_fr_dtmraster(in_dtm, out_folder, Smooth_by='mean', Min_ws=3.0, merge_output=False, tile_size=2000, processes=0, call_mode=CLI, log_level='INFO', **kwargs)

Normalized DTM from a DTM raster, or from a folder of DTM rasters.

Parameters:

Name Type Description Default
in_dtm

DTM raster (GeoTIFF, or a GDAL .vrt of DTM tiles) in a projected CRS, or a folder of DTM GeoTIFFs on one grid (same CRS and cell size), read as one mosaic; where files overlap, the first in name order wins

required
out_folder

folder for the output(s)

required
Smooth_by

'mean' or 'median' of the cells in the window

'mean'
Min_ws

the window's diameter in metres, converted to the DTM's map units

3.0
merge_output

for a folder, also write one merged output, besides the one per file

False
tile_size

cells per side of the square tiles the DTM is processed in; each tile is read with a buffer of the window's radius, so the tiles give the same values as the whole DTM at once

2000
processes

threads that smooth each tile (0: all CPU cores but one)

0

Returns:

Name Type Description

The list of the paths of the outputs written, ndtm_m.tif in

out_folder

one per DTM file, on its grid, and with merge_output first one for the folder

(named after it). Each tile is smoothed once and written into every output it overlaps.

Algorithms

Copyright (C) 2025 Applied Geospatial Research Group.

This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.

Description

Smoothing a raster by the mean or median of a circular moving window, and the normalized raster (the raster minus the smoothed raster). smooth_raster smooths any one-band raster the same way as smooth_raster in r_scripts_collection.r (used by the hummock/hollow tool).

Cells with no value (NaN) are left out of the window, and so are cells beyond the array's edges: near an edge the window holds only the real neighbours. Cells with no value stay NaN. The loops run in parallel on numba's threads (see numba.set_num_threads). smooth_rasters smooths several rasters (tiles) in one parallel loop over all their rows, so a batch of tiles keeps many threads busy; it runs one parallel loop at a time, so it works with any numba threading layer.

smooth_raster

smooth_raster(values, kernel, smooth_by)

A raster's values (a 2-D array, NaN for no value; e.g. a DTM) smoothed by the mean or median of the cells of kernel (a boolean array of odd size each way, see circle_kernel) around each cell.

normalized_raster

normalized_raster(x, kernel, smooth_by)

The raster minus the smoothed raster: hummocks positive, hollows negative, a plane 0.