Encoder pipeline (`xuebuild/`)
The reference encoder (architecture.md): fetch exact
records → GDAL extract → crop, convert units → quantize → Zarr store
(zstd per inner chunk) → manifest → pointer. The .xue (temporal residuals
→ zstd → container) is written beside the store only when asked for, from
the same codes. Per-source
behaviour is in sources.md.
Registries
sources.py (SourceSpec) — one row per source: data location, time
axis as (last_hour, step) segments ending at horizon_hours (the
--hours default), cycle_hours, inputs, published bundles, grid, ladder,
fetch concurrency. Adding a model starts here; the native encoder reads
rust/xue/registry.json, and the shell’s mirror is FORECAST_MODELS in
web/src/data/manifest.ts.
variables.py — one entry per variable in GRIB2 terms (triple, surface,
label, unit) plus matching hints (.idx phrase, ECMWF param,
ecmwf_alternate_params for fields spelled differently along the axis) and
every rule the encoders apply to it, named out of the closed sets of
rules.py (docs/registry.md): conversion (the unit
rule: which spellings a record may carry and the arithmetic to the
published unit), gdal_rules (how its record is told apart among a GRIB’s
bands; derived from the identity by default_gdal_rules unless set),
predictor (delta / raw), decimation (sample / peak) and
companions (poster; video names the retired H.264 companion, which
no encoder builds). Nothing in the encoders selects behaviour
by a variable’s id: a new quantity sets the fields that differ from the
defaults and the rest follows. It feeds both record matching and the v3
parameter block; it assigns no container id.
- Another centre’s record matches a variable through
grib2_aliases(another triple, same surface) orgrib2_alternates(aRecordAlternate: surface, value, statistical process, GDAL unit). Both encoders match by GRIB2 header index and by GDAL band metadata (gdal_rules, evaluated ingdal.pyandinspect.rs); aliases are never written. - An ensemble product (templates 4.2/4.12 derived, 4.6/4.10 percentile,
4.5/4.9 probability) is accepted by a
template-ensemblerule alone, which compares the record’s statistic with the rule’sensembleblock; every other rule refuses those templates, so a deterministic source never picks up an ensemble record by its triple. A statistic of its own (a quartile, a spread, a probability) is a variable carrying anensembleblock (grib2_ensemble); a shared id read as an ensemble’s centre (tmp2mas the median) gets the block from the source (SourceSpec.ensembles,metadata.py), so GFS’stmp2mstays without one. GDAL converts nothing in a derived record that is not a mean and writes a label ([spread], …) in place of the unit (gdal.DERIVED_UNIT_LABELS, mirrored ininspect.rs): its values are in the parameter’s GRIB unit, read as the variable’sgdal_unit. - Input-only entries are read, never published: ECMWF
tp, sfluxprate_aveand the totals read asapcp(intoprate),dirpw,spfh<level>, and GFS’scrain/cfrzr/cicep/csnow(intoptype,derive.derive_ptype). - A source’s precipitation input becomes
prateone of four ways, by the flag it sets (derive.precipitation_mode, mirrored inconvert.rs): a run total differenced (accumulated_precipitation), a window’s mean de-averaged (averaged_precipitation), an interval’s total divided by its length (interval_precipitation), or a window’s total differenced within the window (windowed_precipitation, WOOF-NAM’s twelve hours). The two window shapes share a frame’s raw plane with its successor only inside one window. A run total is first put on one packing lattice (derive.align_packing_steps): a GRIB encoder at a fixed bit count doubles its step once the field’s range crosses a power of two (ECMWFtppast 0.5 m), and differencing across that frame would otherwise paint one fine step of rounding over every dry cell. - Isobaric families come from one table of twenty-one levels (
catuses only 300/250/200,isobaric_family_levels);isobaric_variable(id)returns(family, level).
bundles.py (BundleSpec) — every bundle that is more than the scalar
of the variable of the same id: a vector’s two members, a composite’s
members and producer, a volume’s levels, and a derivation (kind, inputs,
level_hpa) for the bundles the converter computes. The converter resolves
a bundle’s inputs and algorithm off the entry; the per-kind views
(VECTOR_BUNDLES, DERIVED_VECTORS, COMPOSITE_BUNDLES, VOLUME_BUNDLES,
DERIVED_SCALARS) are for readers that walk one kind.
registry.py — serialises the four tables as the registry document
(xue registry), the one description the native encoder reads; the
committed snapshot rust/xue/registry.json is held to the tables by
tests/test_registry.py.
Registration is not publication
SourceSpec.bundle_scalar_ids / bundle_vector_ids list what a source
ships, and a listed bundle ships only when its inputs were fetched:
- vectors (
wind10m,wind<level>, …): every input inbundles.vector_input_ids; - derived scalars (a
BundleSpecwith aderivation:theta-e, Bolton 1980 in a fixed operation order the native side must repeat;clear-air-turbulence, Ellrod TI1 projected onto EDR with the source’scat_calibration, the one derivation that reads neighbours, so_extract_planeshands it the uncropped planes and the crop is cut afterwards;precipitation-type) and derived vectors (vapour-flux:qflux= q·V/g;wave-vector:wave,windwave,swell= a height along its direction of travel in wind convention,(-h sin θ, -h cos θ)). Thepratebundle’sprecipitation-ratederivation takes whichever of its inputs the source lists, by the source’s precipitation flags (derive.precipitation_mode).
sources.COLUMN_STORE_SOURCES names the sources that ship a column store;
for each, sources.py sets SourceSpec.column_arrays (default (), a
fetch-only field: not in the registry document) with
columnarrays.column_arrays, as ColumnArraySpec(id, members), members being
(bundle id, variable id) pairs taken from the published bundle ids by
registry identity; levels come from each variable’s fixed surface. The store is cut by
build-columns from the codes already published, not from the GRIB, so
enabling a source changes no map bundle (publishing:
Column store).
Overlapping sources publish in GFS order so a model switch keeps the layer.
A variable empty at the analysis (optional_at_analysis) is listed by
discover.analysis_optional_ids (mirrored in convert.rs) and starts at
the first step. A variable a source writes only from some hour on
(SourceSpec.variable_first_hours: CMA-GEPS’s 24-hour probabilities, from
F024) is listed there too and starts at that hour: earlier frames are
neither asked for it (fetch.py, assemble.py) nor read, and a build
whose hours end before it leaves the bundle out with a warning. A variable
a source writes only every so many hours (SourceSpec.variable_step_hours:
ECMWF’s 24-hour probabilities, every 12 h from F024 on a 3/6-hourly run) is
asked of and required at the frames on that cadence alone
(SourceSpec.carries_input), never keys the run’s axis
(discover.cadenced_input), and its bundles take a time_<id> axis thinned
to those hours (discover.store_dimensions, binconvert._variable_offsets).
SourceSpec.interval_precipitation_pairs derives further rates from
totals exactly as interval_precipitation derives prate from apcp
(the precipitation quartiles).
Companion files and fill values
SourceSpec.companion_files: a second file family of the cycle (GFSgfswave.*, ECMWFwaveand the ensemble productsep, one object for the whole cycle). Its records are appended after the primary ones, so a frame stays one GRIB, and a run is complete only when they are up. A family is fetched in the packing it is published in: WAVEWATCH III is JPEG 2000, which the wheel’s GDAL reads through the OpenJPEGscripts/build-gdal-minimal.shlinks.VariableSpec.fill_values: GDAL nodata becomes the codebook bottom before unit conversion, in both encoders. The format has no bitmap.
Registry snapshots
rust/xue/registry.json is the whole registry document and
web/src/data/registry.ts the shell’s trimmed copy, both held to the tables by
tests/test_registry.py (regenerate with xue registry --output rust/xue/registry.json --shell web/src/data/registry.ts and say so in the
commit). Widening a source’s inputs means recutting its crop fixture
(gfs.*.crop.grib2 with the same run and -srcwin; the two-frame
ecmwf.* / aifs.* pairs) and regenerating the snapshots
(testing.md).
Modules
fetch.py→idx.py/grib2.py: byte-range fetches of exact GRIB records, one.idx+ range set per family. Which code fetches a source is itsSourceSpec.feed, looked up infeeds.py(sources.md, “Feeds”). A source whosepackingisccsds(ECMWF open data, ICON-EU, ARPEGE) orjpeg2000(CMA GRAPES GEPS) is repacked togrid_simplewithgrib_setat fetch time.The conversion, one Python module per module of
rust/xue/src/encode/, each mirrored by its namesake there:binconvert.py(convert.rs):convert_binas a run of named stages, plane extraction, units and fill, quantization, the container and the store writes;discover.py(discover.rs): which bundles a source publishes and their inputs, the frames of a run and the records each must carry (discover_series,discover_records), the store dimensions;grid.py(grid.rs):GridInfo,grid_info, the snaps,crop_grid;derive.py(derive.rs): the derived vectors and scalars and the precipitation-rate arithmetic;ladder.py(ladder.rs),metadata.py(metadata.rs),poster.py(poster.rs),report.py(report.rs): the resolution ladder, the bundle metadata, the first-frame poster, the build report and the manifest.
Rules mirrored in
rust/xue/src/encode/:- a global grid snaps to
360 / width(WAVEWATCH III’s last longitude is off, and wave bundles must share the pgrb2 grid;grid.rs); - ladder
SourceSpec.variant_factors((2,)default,(2, 4)on satellites and the 0.1° IFS grids): every f-th row and column of the codes, tile divided by f (ladder.py:variant_tier,variant_grid,bundle_tile);variantsare in ascending factor order and nothing keys on the suffix; - the chunk predictor and the ladder’s decimation are the variable’s
predictoranddecimation.
gdal.py(mirrored byinspect.rs):gdalinfoin,SourceFrames out. A band is a variable’s record when any of itsgdal_rulesaccepts it (one evaluator per rule name); the unit is checked by the variable’sconversion(rules.expression, the arithmetic alone, which the header index and the gdalinfo pass compare for identity).quantize.py/temporal.py/binformat.py: codebooks, modulo-256 residual prediction, the container writer and the bundle metadata validator (BundleMetadata, which the store writers and readers apply too). Nothing inxuebuilddecodes a container: a build that writes one reads it back through the wheel’sxue.Bundleand decodes every plane before reporting it.manifest.py: manifest and pointer, both validated on write.observation.py(mirrored byobservation.rs): NetCDF series into the sameSourceFramelist the GRIB path yields, plus aPlaneSource.showcase.py: cases → cropped bundles →showcase.json(showcase/README.md).title/summarycarry all thirteen locales (showcase.LOCALES, held toweb/src/ui/i18n/i18n.tsbytests/fixtures/locales.json). A case is a forecast (run+hours), a local-file observation (dataset, underXUE_OBSERVATION_ROOT) or a fetched window (run= first hour); a window the archive cannot fill is refused.showcase refreshrewrites a sidecar without a rebuild. A fetched case is built bylocalrun.build_local_runplus a catalog row.zarrstore.py: the store writers and NumPy readers. A run’s map stores are shared (zarr-profile.md, profile 2):convert_binwrites each bundle’s arrays and the coordinates its dimension names call for intobundles[.<tier>].zarr(write_bundle_arrays, concurrently), then the part over the build’s bundles (write_part,zarr.part.<first bundle>.json) and, unlesspartial, the group document from it (finalize_store), whose CRC-32 every entry naming the store carries. The dimension names arediscover.store_dimensions, a function of the source registry alone (time_<bundle id>for an analysis-optional scalar, including one with a first hour, or a static field,latitude_<family>/longitude_<family>off the primary grid), so a subset build writes the objects a whole build does. Series stores stay one-bundle (profile 1,write_store); the readers open both profiles, a shared one by bundle id (bundle_metadata). Every writer takes its codes from aCodesSource, the planes the build holds in memory; no store is derived from a finished.xue. The one exception to “in memory” is a series store’s widened variables (seriesQuantization,binconvert.series_widened_ids):_quantize_filequantizes each of them a second time, from the same float plane, under its sixteen-bit series codebook, and writes the codes straight into a per-variable spool file (_SeriesSpool, anp.memmapin a scratch directory under the work root, frame-major on the run axis); the series writer reads it back a block row at a time, and each spool file is removed once its store is written. Holding a whole run’s sixteen-bit codes beside its byte codes would add twice the byte codes’ memory for a handful of variables.assemble.py:publish.ymlfans a run out:bundle-groupspacks bundles into at mostmax_jobsjobs of similar cost; each job runsbuild-bin --bundles …(partial=True) intodata/raw/partial/<group>/and writesmanifest.part.<group>.jsonand each shared store’s part (never uploaded, no STAC); finalize runsassemble-run(each bundle once, core set required), which merges the parts into the manifest and each store’s group document and stamps its CRC-32 on every entry naming it, and writes the pointer. A top-up of a live cycle builds only missing bundles (--base-manifestagainstmake live-manifest,--base-storesagainstmake live-store-groups), rewriting the group documents under a new?v=;forcerebuilds all.tests/test_assemble.pyholds split and top-up builds byte-identical to a whole one, store and group documents included, so nothing cross-variable may enter a bundle’s arrays or its manifest entry: the group document is the one object several bundles share, and it is a merge of per-bundle parts. A merge onto a base keeps the base’scolumnsonly when no rebuilt bundle is a member of the column store and the source still lists columns; otherwise it drops it and thecolumnsjob builds it anew.columnbuild.py,columns.py,columnarrays.py(build-columns,column-inputs,columns-missing; the column store, run by thecolumnsjob after finalize):column-inputs --manifest Fprints the run-relative objectsbuild-columnsreads, so the job downloads only those;build-columns --model M --run Rcutscolumns.zarrfrom them and rewrites the manifest, pointer and Item;columns-missing --model M --base-manifest Fprintstruewhen the live run lacks its store, which is howresolveretries a failed job. The store is written by one of two implementations that must agree byte for byte: the Python reference (columns.py) and the native writer in the wheel (xue.write_columns), picked byXUE_ENCODERlike the map stores; the self-check, manifest, pointer and Item steps are Python for both.assemble-run --columns FILEtakes the descriptor ({run, stores, columns}) thecolumnsjob leaves and sets itscolumnsas the manifest’s, beating the one a top-up keeps from its base, only when it was cut for this run against the group documents just assembled and validates; otherwise (also for a source with no column arrays) it warns and the run has none, and the report carriescolumnsNotAttached.
Local and archived runs
build-local (localrun.py, make run-local) rebuilds one archived cycle
for local use, such as a backtest, and uploads nothing:
--runis aYYYYMMDDHHcycle;latestis refused, since the live cycle isbuild-bin’s.--hoursdefaults to the source’s whole axis,--bbox W,S,E,N(write it--bbox=…when west is negative) to the whole domain, and--bundlesto every bundle the source publishes. Only those bundles’ inputs are fetched.- The output,
data/local/<model>.<run>/, is the manifest and the shared Zarr storebundles.zarrholding every bundle, plus<bundle>.series.zarrfor the source’sseries_bundle_ids(--no-seriesdrops them) and the posters the manifest names. There is no.xue, reduced-resolution variant, live pointer or STAC. - Raw GRIB goes to
data/raw/local/<model>.<run>/, apart from the livedata/raw/<model>.<run>/, for the same reason the showcase and the fanned-out jobs keep their own: a narrowed record set must never pass for a full fetch of the run. Delete it once the run is encoded when replaying many cycles. - The encoder follows
XUE_ENCODERas everywhere else. The installedxuepywheel can lagsources.pyandvariables.pyby a release, so a bundle registered since the last release builds only withXUE_ENCODER=python.