vrt.derive()

Derive bands from rasters or VRTs with a GDAL pixel function.

Usage

Source

vrt.derive(
    sources,
    function,
    *,
    dtype="float32",
    nodata=math.nan,
    description="",
    band=None
)

Parameters

sources: str | Path | UPath | VRT | Sequence[str | Path | UPath | VRT]

One input, or several on an identical grid. A VRT is nested whole, so the function sees its mosaicked pixels.

function: PixelFunction

Function applied to the sources. propagateNoData is set to "true" unless its arguments already set it, so a nodata input gives a nodata output.

dtype: str = "float32"

NumPy dtype name of the derived bands.

nodata: float | None = math.nan

NODATA of the derived bands.

description: str = ""

Description of every derived band.

band: int | None = None
1-based band read from each input. With several inputs it defaults to 1; with one input, it derives only that band instead of every band.

Returns

VRT
With one input, a derived band per input band; with several, one derived band. Each source carries its input’s NODATA, and transfer_type defaults to dtype.

Raises

ValueError
If nodata does not fit in dtype, sources is empty, the grids differ (use warp first), band is out of range, or an input band is complex or has a scale or offset.