Skip to main content

Module quantize

Module quantize 

Source
Available on crate feature encoder only.
Expand description

Xue v1 quantization codebooks — the port of xuebuild/quantize.py.

A codebook is built from the quantization.<profile> block of a variable’s registry entry, exactly as the metadata writes it, and hands the block back verbatim for the metadata (Codebook::metadata), so a store’s attributes.xue is the document’s block byte for byte. The port of codebook_from_metadata in xuebuild/quantize.py, refusals included.

A code is a byte unless the codebook’s nodata code is above 255: a series codebook (the registry’s seriesQuantization) holds sixteen-bit codes, quantized by LinearCodebook::quantize_wide. Which width a block may take is for its reader to say (a profile’s codebook is bytes, Registry), so the parse here accepts any code from 0 to 65535, as codebook_from_metadata does.

All rounding is round-half-up: round(x) = floor(x + 0.5). Every rounded quantity here is non-negative, so this equals round-half-away-from-zero. Round-half-even (Rust’s f64::round_ties_even, and the IEEE 754 default) must not be used; it changes codes for values landing exactly on a half step.

Structs§

Codebook
One profile’s codebook for one variable: the arithmetic, and the block it was read from.
LinearCodebook
Linear codebook, uint8 unless its nodata code needs sixteen bits. Not temperature-specific: it quantizes any linear field; the wind components reuse it with a symmetric m/s range.
PrecipitationCodebook
Logarithmic (log1p) codebook: sparse, long-tailed fields keep their light-rain resolution. Not precipitation-specific either: it quantizes any one-sided field whose interesting range spans orders of magnitude — the aerosol optical depth, the particulate matter concentrations and a river’s discharge reuse it with their own trace, scale and maximum.

Enums§

Book