GeoZL

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.

One row of an int16 elevation tile, 412 415 -32768 418 421 423, through a GeoZL graph in six steps. The nodata step moves the hole to a mask and fills the gap with 415. The planar step leaves 412 3 0 3 3 2. The zigzag step makes it 824 6 0 6 6 4. The transpose step splits it into a low byte lane 56 6 0 6 6 4 and a high byte lane 3 0 0 0 0 0. The entropy step codes each stream, and the frame stores them with the graph.
6 / 6
Each step is reversible. The last step compresses the small numbers and zeros.

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.

GeoZL codecs arranged by graph stage: split, quantize, predict, map and code. Fused codecs span several stages, and PFOR or lanes endings also decode on the GPU.
The first two slots are optional. Codecs marked gpu also decode on the GPU.

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.

codecCTidwhat it does
delta_w0x72D701residual against the west neighbour
delta_n0x72D702residual against the north neighbour
planar0x72D703predicts each pixel from W + N - NW
deinterleave0x72D704separates a two-lane interleaved stream
med0x72D705median edge detector predictor
average0x72D706floor average of the west and north neighbours
wp_static0x72D707weighted predictor with its weights in the frame
nodata0x72D70Cmissing samples to a validity mask, holes filled
pfor0x72D70Dbit packs blocks of 256 and patches overflows
planar_zigzag0x72D70Fplanar residuals and Zigzag in one pass
planar_zigzag_pfor0x72D710planar, Zigzag and PFOR as one codec
med_zigzag0x72D711MED residuals and Zigzag in one pass
planar_zigzag_lanes0x72D712planar and Zigzag, then PivCo or PFOR per byte lane
lanes0x72D713byte lanes encoded independently with PivCo or PFOR
quant_linear0x72D781absolute bound, LINEAR:MAX_ERROR=V
quant_log0x72D782relative bound, LOG:MAX_ERROR=P%
quant_sqrt0x72D783noise-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.