pack_minmax

Helper function to define packed data exports by min / max values

Description

This function can be used to define packed exports in write_ncdf and write_tif. It will generate scale and offset values with maximum precision (unless simplify=TRUE).

Usage

pack_minmax(type = "int16", min, max, simplify = FALSE)

Arguments

Argument Description
type target data type of packed values (one of “uint8”, “uint16”, “uint32”, “int16”, or “int32”)
min numeric; minimum value(s) of original values, will be packed to the 2nd lowest value of the target data type
max numeric; maximum value(s) in original scale, will be packed to the highest value of the target data type
simplify logical; round resulting scale and offset to power of 10 values

Details

Nodata values will be mapped to the lowest value of the target data type.

Arguments min and max must have length 1 or length equal to the number of bands of the data cube to be exported. In the former case, the same values are used for all bands of the exported target cube, whereas the latter case allows to use different ranges for different bands.

Note

Using simplify=TRUE will round scale values to the next smaller power of 10.

Examples

ndvi_packing = pack_minmax(type="int16", min=-1, max=1)
ndvi_packing
$type
[1] "int16"

$offset
[1] 0

$scale
[1] 3.051851e-05

$nodata
[1] -32768