moczarr.surfaces
Percentile-surface materialization + the resolution ladder (issue #21).
The gridlook feeder: the ratified viewer posture (englacial/zagg#265,
espg/gridlook#1) is that the browser never decodes digest bytes — dense
materialization happens hub-side, and percentile surfaces carry a
quantile DIMENSION so the viewer's existing dimension slider drives
bare-earth↔canopy browsing with zero frontend changes. This module is that
hub-side step, plus the ladder metadata the gridlook#10 order picker
enumerates (declared orders, materialized orders, per-order resolution).
Two surfaces:
- :func:
quantile_surface/ :func:open_surface— evaluate a stored t-digest field into a dense(quantile, cells)float array over one level's cells, themortoncoordinate carried, the caller's fill (default NaN) where a cell holds no digest. Exact/dense fields (a count choropleth) ride along un-evaluated viacarry=, or alone viafield=None. Strata-aware: a sequence of digest fields is merged per cell before evaluation (one deterministic concatenate-and-sort — the lossless t-digest union, no re-compression), so ah_tdigest_signal/h_tdigest_noisestore answers per-stratum or merged-total surfaces by argument — and by argument ONLY: the sort key is(mean, weight), so naming the strata the other way round is the same surface even when they share a centroid mean. - :func:
read_ladder— the picker contract: one typed record per level of :func:moczarr.level.pyramid_levels' table, extended with the per-order ground resolution (mortie.order2res) and a probedmaterializedanswer (overview presence via :func:moczarr.pyramid.read_pyramid, column presence via the §4.6 columns' owngroupsmaps — declared ≠ materialized is the live-store failure mode the picker must not trip on).
The t-digest algebra is moczarr's own (:mod:moczarr.tdigest, pure numpy;
issue #64 — no reader function needs zagg, whose kernels are the PARITY arm
only, under the demoted moczarr[zagg] extra), and evaluation honours
the standing trap: every digest — merged concatenation or single stored
cell — is ordered by (mean, weight) before the kernel sees it, because
the interp-based kernel assumes mean order AND its cumulative-weight walk
is sensitive to the order of centroids that share a mean. Native surfaces
only (the
englacial/zagg#550 ruling): no moczarr.dggs, no xdggs, no decode=.
Ladder
dataclass
A store's resolution ladder, typed — the gridlook#10 picker contract.
levels is the whole declared table, finest first; the two
projections answer the picker's questions directly: declared — every
addressable cell order — and materialized — the subset with stamped
artifacts today (an order declared but not materialized never becomes a
catalog entry). Per-order resolution rides each :class:LadderLevel.
Source code in src/moczarr/surfaces.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
declared
property
Every declared cell order, finest first.
materialized
property
The declared cell orders with stamped artifacts today (probed).
LadderLevel
dataclass
One resolution level of the picker's ladder (:func:read_ladder).
Attributes:
| Name | Type | Description |
|---|---|---|
cell_order |
int
|
The level's resolution — the cell order a reader picks
(:func: |
order |
int
|
The hive-tree node order whose artifact carries the level. |
artifact |
str
|
|
resolution_km |
float
|
Approximate ground scale of one cell at |
materialized |
bool or None
|
Whether the level has stamped artifacts on disk today: |
presence |
OrderPresence or None
|
The probe counts behind |
Source code in src/moczarr/surfaces.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
open_surface(store_root, cell_order, field, *, quantiles=DEFAULT_QUANTILES, fill=np.nan, carry=(), name=None, product=None, manifest=None, aoi=None, window=None, all_time=False, anonymous=False, fabricate_cell_ids='auto', index_kind='moc', concurrency=32, xr_kwargs=None, store=None, **store_kwargs)
Open one level and materialize its surface — the one-call feeder.
:func:moczarr.level.open_level then :func:quantile_surface, with
open_level's whole signature threaded through verbatim (defaults
unchanged): aoi scopes rows exactly as the level model does (an
out-of-coverage AOI yields the schema-correct EMPTY surface,
(len(quantiles), 0)), window follows the D23 dialect (required
on a windowed store, refused on an unwindowed one, the reserved
all-time token refused everywhere), all_time reads a windowed
store's §4.5 cross-window folds (overview levels only),
fabricate_cell_ids governs whether the surface carries a
cell_ids coordinate at all, index_kind selects the level's
index (and with it how aoi cuts rows), and xr_kwargs reaches
xr.open_zarr — the knob that governs the read, which is the wall at
viewer scales. None — with the arm's own warning — when the level
is declared but unmaterialized, exactly as open_level answers.
Surface arguments (quantiles/fill/carry/name, field
string / sequence / None) follow :func:quantile_surface.
Source code in src/moczarr/surfaces.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
quantile_surface(ds, field, quantiles=DEFAULT_QUANTILES, *, fill=np.nan, carry=(), name=None)
One level's digest field, dense: a (quantile, cells) Dataset.
Takes any Dataset of the issue-#37 level model (:func:moczarr.level.
open_level, :func:moczarr.open.open_hive, :func:moczarr.pyramid.
open_overview_order, :func:moczarr.level.open_column_order — the
shape is the model's one law) and evaluates field's stored
t-digests per cell at quantiles, returning a NEW dense Dataset:
fieldas a float64(quantile, cells)variable —quantilea real dimension with the requested values as its coordinate, so the output opens in vanilla xarray and a viewer's dimension slider drives it directly;- the
morton(andcell_ids, when present) coordinate carried as PLAIN arrays — materialization is dense by design, laziness ends here; fill(default NaN) where a cell holds no digest (an absent/empty vlen cell, or every stratum empty);carrynames dense (exact-class) variables copied verbatim onto thecellsaxis — a count choropleth needs no evaluation. One name, a sequence of them, or any iterable (consumed once, likefield: a bare string is ONE name, never its characters);- the level's
morton_hive/zagg_level/zagg_objectsattrs carried forward, plus :data:SURFACE_ATTRon the evaluated variable recordingfields/quantiles/fill— the last as a number, or as the quoted token name ("NaN"/"Infinity"/"-Infinity") when it is not finite, so the writtenzarr.jsonstays strict JSON for a browser reader (:func:_json_fill).
field is one digest variable name, a sequence of them (the strata
arm: the cells' centroid sets are merged by the lossless
concatenate-and-sort union before evaluation — the merged TOTAL of
("h_tdigest_signal", "h_tdigest_noise"), identical to the flipped
pair's, ties included; per-stratum surfaces are
one call per field), or None with a non-empty carry (the
dense-only arm: no evaluation, no quantile dimension). The default
merged name is the fields' common prefix (h_tdigest); name=
overrides. Evaluation calls :func:moczarr.tdigest.quantile_from_tdigest
per cell — the values are exactly that kernel's, per cell, by
construction (the issue #21 acceptance), and that kernel is pinned
value-exact against zagg's by the parity gate (issue #64).
Source code in src/moczarr/surfaces.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
read_ladder(store_root, *, product=None, manifest=None, window=None, probe=True, anonymous=False, concurrency=32, store=None, **store_kwargs)
A store's resolution ladder as one typed record — the picker feeder.
The gridlook#10 Phase-3 contract in one call: declared orders (the
level table, both grammars — a declared-off pyramid is the one-level
ladder), materialized orders (probed: which declared levels have
stamped artifacts on disk today — declared ≠ materialized is the
live-store failure mode a picker must not trip on), and per-order
resolution (mortie.order2res at each cell order). Mostly a
projection of :func:moczarr.level.pyramid_levels +
:func:moczarr.pyramid.read_pyramid, typed per the
:class:~moczarr.pyramid.PyramidInfo posture.
materialized per artifact kind: overview levels take
:func:moczarr.pyramid.read_pyramid's D4 existence probe (stamped >
0 — existence, not readability, its documented split) — except where
a /2 node declares SEVERAL cell orders, whose rungs read None:
the node's object carries a scalar zagg_overview.cell_order, so at
most one of those rungs is backed and a node-existence count cannot say
which; column levels
are probed from the §4.6 columns' own groups maps (one batched GET
per candidate leaf, shared across the column levels — see
:func:_leaf_presence), since the manifest MAY lag the fleet there.
The source level is True by definition on an unwindowed store
(the leaves ARE the store) and is PROBED on a windowed one whenever a
window is named: those leaves are per window ({shard}_{window}.zarr
— D23) and exist only for the windows that were swept, so a
syntactically valid label that was never swept must read False, not
True. It rides the same batched leaf-tier read as the columns, so
the extra honesty costs no extra round trip when a column level is
probed too — and on a windowed store with no column levels it is the
one leaf-tier batch the ladder pays (probe=False opts out
entirely). The probe never raises: a malformed or mis-stamped column is
warned about and counted as not carrying, so one bad object cannot take
the picker's whole catalog entry — the source and overview rungs
included — down with it. None marks unknown: probe=False
(declaration only — one manifest GET, no coverage or stamp reads, so a
windowed store's source rung reads unknown rather than guessing at a
named window), an unusable root coverage, or the grouped-tree overview
refusal — :attr:Ladder.materialized lists True levels only, so an
unknown level never masquerades as materialized.
window follows the shared seam: probing a windowed
(morton-hive/2) store requires window=... (its artifacts are
per window — D23), an unwindowed store refuses the argument, and the
reserved all-time token is refused everywhere. The windowed store's
§4.5 all-time fold tier is NOT probed here (its levels are the same
cell orders; open them with all_time=True). product re-roots on
a D19 multi-product subtree; manifest/store thread an
already-read manifest and handle, per the issue-#5 posture.
Source code in src/moczarr/surfaces.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | |