GeoZL codecs
- GeoZL 0.34.0, 17 codecs, BSD-3-Clause licence.
zstd and Deflate on their own treat a raster as a line of bytes. They do not use pixel neighbours, the −32768 no-data value, or the slowly changing high byte of a 16-bit elevation. Blosc gets part of the way with byte shuffle and bitshuffle, which group the high bytes together, but it still knows nothing of neighbours in two dimensions or of no-data. GeoZL supplies OpenZL with small codecs for these raster properties. OpenZL combines them as graphs of codecs.
The figure follows one row of an elevation tile through a graph. Use the buttons or arrow keys to follow each codec.
Each frame stores its graph as a decode recipe. A reader looks up the codecs by CTid. A shipped CTid is never renumbered or reused.
Graphs can vary between frames. A DEM and a land cover map can use different graphs. They can also vary by band, season or location, including ocean, mountain and city tiles. Frames for a training loop can use a GPU recipe.
A recipe names the graph in data-flow order. The graph line builds the graph shown above.
import numpy as np
import geozl
y, x = np.mgrid[0:256, 0:256]
tile = (1000 + 3 * x + 2 * y).astype(np.int16)
tile[:16, :16] = -32768 # a corner of missing samples
g = geozl.graph(tile, "planar>zigzag>transpose>entropy", nodata=-32768)
frame = geozl.compress(tile, graph=g)
out = geozl.decompress(frame).view(tile.dtype).reshape(tile.shape)
assert np.array_equal(out, tile)
library(geozl)
tile <- outer(0:255, 0:255, function(x, y) 1000 + 3 * x + 2 * y)
tile[1:16, 1:16] <- -32768 # a corner of missing samples
g <- geozl_graph(tile, "planar>zigzag>transpose>entropy", nodata = -32768,
dtype = "int16")
frame <- geozl_compress(tile, g)
out <- geozl_decompress(frame, "int16", dim = dim(tile))
stopifnot(all(out == tile))
using GeoZL
tile = [Int16(1000 + 3x + 2y) for x in 0:255, y in 0:255]
tile[1:16, 1:16] .= -32768 # a corner of missing samples
g = GeoZL.graph(tile, "planar>zigzag>transpose>entropy"; nodata = -32768)
frame = GeoZL.compress(tile, g)
out = GeoZL.decompress(Int16, frame, size(tile))
@assert out == tile
nodata= adds the first step, and error= would add a quantizer right after it. The frame stores neither dtype nor shape, so keep both beside it. Python's decompress returns bytes to view and reshape, and R and Julia take the type and dimensions as arguments. profile tries candidate recipes on a tile and ranks them.
All GeoZL codecs fit into this chain. The map places all seventeen codecs beside the OpenZL codecs they work with.
The four codec families are on separate pages. Predictors turn samples into small residuals. Stream codecs split and pack. Fused codecs run a common chain in one pass, and planar>zigzag in the picture above is really one of them. Quantizers trade a bounded error for smaller numbers. Each codec ends with its CTid, its header and the call that builds it.
Every codec, with its CTid and a link to its section. The numbers live in geozl/ctids.h, which also records the retired ones.
| codec | CTid | what it does |
|---|---|---|
delta_w | 0x72D701 | residual against the west neighbour |
delta_n | 0x72D702 | residual against the north neighbour |
planar | 0x72D703 | predicts each pixel from W + N - NW |
deinterleave | 0x72D704 | separates a two-lane interleaved stream |
med | 0x72D705 | median edge detector predictor |
average | 0x72D706 | floor average of the west and north neighbours |
wp_static | 0x72D707 | weighted predictor with its weights in the frame |
nodata | 0x72D70C | missing samples to a validity mask, holes filled |
pfor | 0x72D70D | bit packs blocks of 256 and patches overflows |
planar_zigzag | 0x72D70F | planar residuals and Zigzag in one pass |
planar_zigzag_pfor | 0x72D710 | planar, Zigzag and PFOR as one codec |
med_zigzag | 0x72D711 | MED residuals and Zigzag in one pass |
planar_zigzag_lanes | 0x72D712 | planar and Zigzag, then PivCo or PFOR per byte lane |
lanes | 0x72D713 | byte lanes encoded independently with PivCo or PFOR |
quant_linear | 0x72D781 | absolute bound, LINEAR:MAX_ERROR=V |
quant_log | 0x72D782 | relative bound, LOG:MAX_ERROR=P% |
quant_sqrt | 0x72D783 | noise-scaled bound, SQRT:MAX_ERROR=VN |
Two algorithm pages follow the families. PFOR and PivCo are the coders behind the GPU recipes, explained from the block format up.
The optimization pages come last, as a series in four parts that tells how the decoders got fast. Fast on one core covers SIMD on a CPU. What a GPU wants explains which formats a GPU can decode and what that cost, Bytes to tensors follows a batch into GPU memory, and One source, many GPUs shows how one Slang source becomes the kernels for each backend.
The API section documents the calls in every language.