moczarr.level
One resolution level of a pyramid store as ONE xarray Dataset (issue #37).
The per-order data model the #37 thread ruled ("one dataset per order" —
espg, 2026-08-05): whatever artifact kind materializes a resolution — the
source leaves at native order, a §4.6 leaf column's coarser groups, or a
§4.1 overview artifact at an ancestor node — a reader gets the SAME
in-memory shape, one :class:xarray.Dataset per cell order:
- dims: the 1-D
cellsaxis, nested-ascending in packed-word order; - coords:
morton— the packeduint64cell words at this level's cell order, the native coordinate (identity is morton, never lat/lon; geometry stays derivable via mortie), lazy under the defaultindex_kind="moc"(:class:moczarr.moc_index.MortonMocIndex) — plus the fabricated NESTEDcell_idsview; - data variables: dense fields as their stored dtypes; ragged digest
fields ride as their ENCODED
zagg-ragged/1vlen-bytes variables (dtypeobject) on the samecellsaxis, the §1.2raggedattrs block verbatim on the variable — decode is :func:moczarr.ragged.parse_ragged_attrs+ :func:moczarr.ragged.decode_cellon pulled values, or the store-addressed :func:moczarr.ragged.read_ragged. Eager decode into padded dense tensors is rejected (it breaks laziness and invents a fill the spec does not have), and dropping ragged fields is rejected too (the level would stop being the store's level); - attrs:
morton_hive(the level summary —cell_orderis THIS level's resolution,shard_orderthe artifact node order) andzagg_objects(the per-artifact roster: each entry carries the object's own provenance block verbatim —zagg_overviewfor overview artifacts,zagg_columnfor columns — so fold regime,merges_from_raw,source_children, and stampeddemotionsrecords all ride along without re-keying). The roster is STRUCTURAL — recorded for every stamped object before any AOI filtering — on the source and overview arms; on the §4.6 column arm it is QUERY-SCOPED, a named exception :func:open_column_orderdocuments.
The three artifact kinds keep their existing openers — open_hive for
the native order, :func:moczarr.pyramid.open_overview_order for ancestor
artifacts — and this module adds the missing third
(:func:open_column_order: one Dataset per column-carried resolution,
assembled across the covered leaves' §4.6 columns) plus the resolution
table (:func:pyramid_levels) that says which opener owns which cell
order. On top of the per-level block sits the espg/moczarr#36b multi-order
ASSEMBLY, :func:open_pyramid: one xarray.DataTree whose groups are
the store's resolution levels — each group the per-level Dataset — with
the normalized declaration record on the root.
Native surfaces only (the englacial/zagg#550 ruling): nothing in this
module touches moczarr.dggs or xdggs, and the new entry points expose
no decode=.
level_demotions(ds)
Every stamped demotions record of one level, node-attributed.
Pre-spec, forward-tolerant, surfaced verbatim. The demotions
key is NOT in the normative store contract: zagg's byte-level grammar
is docs/specification.md plus the conformance fixtures (zagg#340),
and this key lives only in the open, waiting PR englacial/zagg#557
(the packed-class guard rail, zagg#518 — one record per
(field, reason), e.g. {"field": "composition", "class":
"packed", "reason": "divisor-missing", ...}). So this function makes
NO claim about the record shape and validates nothing: it reads the
key where the PR says the sweep writes it — the affected overview
artifact's zagg_overview attrs, which ride VERBATIM in this model's
zagg_objects roster — flattens the records across the level's
artifacts, and extends each with the carrying object's node and
window. Unknown record keys pass through untouched, and absence
everywhere is the clean answer [] (a pre-#518 writer's attrs are
byte-identical to a clean store's, so absence is never evidence the
rail stayed quiet). If #557's shape moves before it lands, this
docstring and tests/test_level.py's hand-written record are the
two places to update; when it lands with a spec section and a fixture,
the test re-pins on writer bytes.
Read from zagg_overview ONLY. §4.6 leaf columns are written by the
leaf worker, which runs no fold, and #557's instrumented sites are all
sweep-side, so a zagg_column block has no producer for this key —
reading one would be speculation dressed as a surface.
Takes an :func:open_level /
:func:moczarr.pyramid.open_overview_order /
:func:open_column_order result — or a DataTree node wrapping one; a
column level's answer is [] by construction.
Source code in src/moczarr/level.py
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 | |
open_column_order(store_root, manifest, order, *, aoi=None, window=None, anonymous=False, fabricate_cell_ids='auto', index_kind='moc', concurrency=32, xr_kwargs=None, store=None, _envelope=None, **store_kwargs)
Open one column-carried resolution of a product as a Dataset, or None.
The §4.6 tier of the #37 per-level model: order is a CELL order in
[shard_order, cell_order) — a declared leaf resolution
(pyramid_declaration(...)["leaf_cells"]), a within-footprint ladder
rung, or the node-order member order == shard_order (the leaves'
whole-footprint aggregates: one cell per leaf) — and the returned
dataset assembles that resolution group across every covered leaf's
column, concatenated along cells in ascending packed-word order.
The shape contract is :mod:moczarr.level's: the same dims / morton
coordinate / attrs as :func:moczarr.open.open_hive returns for the
native order, with dense fields dense and ragged digests as their
encoded vlen variables (the ragged attrs block riding verbatim).
Which resolutions a given column actually holds is the column's own
groups map (the manifest MAY lag what the fleet wrote — §4.6), so
membership is checked per column and a stamped column without this
group contributes nothing, silently: the level then UNDER-COVERS those
leaves' footprints, visible as absent spans of the morton domain
(the same posture as a cascade's source_children.missing — absent
is never evidence of empty). Leaves with no stamped column at all are
skipped the same way (D4: absence of a stamp IS the answer; §4.6 makes
torn-worker and never-declared indistinguishable here and neither an
error). Per-object classification follows :func:_column_entry's two
severities, and each admitted column's zagg_column block rides
verbatim in attrs["zagg_objects"].
The roster here is QUERY-SCOPED — a named exception.
:func:moczarr.pyramid.open_overview_order records zagg_objects
for every stamped object BEFORE any AOI filtering, so its roster (and
its §4.3 classification) answers structural questions about the store;
this surface does not. Because aoi cuts the CANDIDATE leaves (see
below), both the roster and the §4.6 wrong-identity raise are functions
of the query: an AOI that misses a leaf never reads that leaf's stamp,
so a disjoint AOI yields zagg_objects == [] on a store that carries
columns, and a column declaring another node's identity raises only when
the query reaches it (aoi=None, an AOI selecting it, or the
unrestricted fallback probe below). That is deliberate — the exception
buys the cost posture in the next paragraph — but it means structural
questions ("does this store carry columns at all?", "is every column
conformant?") belong to the unconditional surfaces:
:func:moczarr.store.walk_columns,
:func:moczarr.column.read_column_record, and
:func:moczarr.pyramid.read_pyramid, never to an AOI-scoped level's
roster. The three-way behavior is pinned in tests/test_level.py.
aoi restricts the CANDIDATE leaves arithmetically (root MOC ∩ AOI,
the same shard-level cut :func:moczarr.open.candidate_leaves makes —
columns are leaf-sibling artifacts, one per shard, so an unscoped probe
would pay the leaf tier's own stamp GETs on every open: 2,918 on ATL03,
against the 4^(s-k)-fold fewer ancestor nodes that let
open_overview_order keep its candidates unscoped for free) and then
rows exactly, per group. An AOI that excludes every column-carried cell
returns the issue-#4 schema-correct empty dataset with a
UserWarning — which names WHICH of the two empties it is: the AOI
missing the column coverage, or the AOI's own stamped columns carrying
no group r (under-coverage, the schema then coming from the
fallback probe's out-of-AOI leaf); None
is returned — with a warning — only when NO stamped column anywhere
carries this group (not yet written, or a declaration that never
carried it), or when the root coverage.moc is unusable (candidates
are named arithmetically, exactly as
:func:moczarr.pyramid.open_overview_order refuses to walk). Unlike
overviews, a grouped tree needs no refusal: a column is a leaf sibling,
so path_grouping renders its path exactly as it renders the leaf's.
window follows the leaf dialect (D23): required on a windowed
(morton-hive/2) store — its columns are {window}.pyramid.zarr
per window, with NO all-time column (the all.pyramid.zarr stem is
the unwindowed store's spelling, reached by window=None) — refused
on an unwindowed one, and the reserved token is refused at the shared
validate_window seam. anonymous/store/_envelope/
store_kwargs follow :func:moczarr.pyramid.open_overview_order's
posture (one shared handle, one root-MOC read per product).
Source code in src/moczarr/level.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 328 329 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 390 391 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 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
open_level(store_root, cell_order, *, 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, _envelope=None, **store_kwargs)
Open ONE resolution level of a pyramid store as one Dataset, or None.
The #37 entry point: cell_order addresses a level of
:func:pyramid_levels' table — resolution is the reader-facing axis,
and which artifact kind materializes it is this function's dispatch,
not the caller's:
- the native order opens through :func:
moczarr.open.open_hive(the same lazy Dataset, plus the per-object roster underattrs["zagg_objects"]); - an overview order opens through
:func:
moczarr.pyramid.open_overview_order(ancestor artifacts,/1constant-depth and/2ladder rungs alike); - a column order opens through :func:
open_column_order(the §4.6 leaf tier of a/2declaration).
Every arm returns the ONE shape this module's docstring specifies, and
every arm inherits its opener's degrade postures verbatim: None
with a warning when a declared level has no stamped artifact (or the
root MOC is unusable), the issue-#4 schema-correct empty dataset under
an AOI that misses the coverage, and the shared window= seam. An
undeclared cell_order raises, listing the store's levels — the
§4.6 node-order member (cell_order == shard_order) is a recorded
partial tier rather than a level, reachable explicitly through
:func:open_column_order.
On top of the arm's own attrs the result carries :data:LEVEL_ATTR
(zagg_level) — the level's record from the table plus the
declaration-side context a per-level consumer needs without re-reading
the manifest::
{"cell_order": 5, "order": 4, "artifact": "column",
"spec": "zagg-pyramid/2",
"fields": {...}, # the §4.5 all-fields map, classes included
"fold_source": "cascade"}
fields is the DECLARED all-fields view (a none-class entry
records an absence — the zero-open §4.4 answer); per-artifact truth
(what a given object actually folded, its regime and generation, any
stamped demotions) stays in the zagg_objects roster, per
object, never summarized. spec/fields/fold_source are
None on a declared-off store, whose one level is the native order.
all_time opens a windowed store's §4.5 CROSS-WINDOW folds at this
level (issue #31, the recorded option-(1) posture): overview levels
only — a windowed store has no all-time source leaf (the fold is of
the windows) and no all-time column (§4.6: the all.pyramid.zarr
stem is the unwindowed store's spelling) — so naming a source or
column level under all_time=True raises, and the arm's own seams
refuse it on an unwindowed store (whose artifacts ARE the all-time
folds, reached with window=None) and beside a window=. What the
declaration says is deliberately NOT a seam here: a store whose
pyramid.overview.all_time is unset still reads whatever all.zarr
folds are stamped (declaring is free, sweeping is the operational
decision — zagg#381 point (11)), degrading to the ordinary warned
None when none are. Only :func:open_pyramid gates on the
declaration, where the alternative is a childless tree of warnings.
product re-roots on a D19 multi-product subtree; manifest
threads an already-read manifest (of the subtree actually opened) and
store one already-constructed obstore handle — both reach EVERY
arm, the native one included (issue #5: one store construction and one
manifest GET per open, whichever artifact kind owns the level, so
threading a handle across a product's levels behaves uniformly); the
private _envelope likewise shares one already-read root MOC across
a product's non-source levels (how :func:open_pyramid calls this —
the sidecar tier must not grow with the number of levels);
everything else follows :func:moczarr.open.open_hive's posture.
Deliberately no decode=: new pyramid surfaces are native moczarr
only (the englacial/zagg#550 ruling) — the returned Dataset is plain
xarray plus the core lazy index.
Source code in src/moczarr/level.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 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 | |
open_pyramid(store_root, *, product=None, manifest=None, levels=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 a pyramid store's whole resolution ladder as one xarray.DataTree.
The espg/moczarr#36b multi-order assembly over :func:pyramid_levels:
one child group per addressable resolution, finest first, each named
o{cell_order} (o5 for the level storing order-5 cells — the
espg-ruled group grammar: attribute-style access works, tree.o5.ds,
and the name is an unambiguous string rather than a type-mangled
number) and holding exactly the Dataset
:func:open_level returns for that resolution (the #37 shape — the
cells axis, the lazy morton coordinate, ragged digests encoded,
zagg_level/zagg_objects attrs) — whichever artifact kind
materializes it (source leaves, §4.6 column groups, §4.1/§4.4 overview
artifacts), on either declaration grammar (/1 constant-depth and
the /2 fixed ladder alike). The oN spelling is READER-SIDE tree
vocabulary only: store-side wire paths stay numeric (an order-19 group
on disk is 19/..., unchanged). The tree layer adds no reads of its
own: the sidecar tier is CONSTANT in the number of levels (issue #5) —
one manifest GET, and one root-MOC read threaded across every
non-source level, beside the one :func:moczarr.open.open_hive takes
on the source arm (it has no _envelope parameter, deliberately —
the source axis owns its own coverage read). "Lazy" stays each
level's own laziness.
The root node is empty — no variables, no coordinates — and carries the declaration:
morton_hive— the manifest summary (spec, the nativecell_order,shard_order,dataset);semantic_hash— a SIBLING attr besidemorton_hive, never a member of it, present only when the manifest records one (theopen_storeproduct-node spelling, so the two agree);zagg_pyramid— the normalized :func:moczarr.pyramid. pyramid_declarationrecord, decoded from the NORMATIVEpyramidblock (absent on a declared-off store, whose tree is the valid one-level degenerate form: the native order and nothing else);multiscales— the manifest's §4.9zagg-multiscales/1discovery mirror verbatim, when the manifest carries one. It is surfaced as recorded, never re-derived and never consulted: the levels come from thepyramidblock, which wins any disagreement by §4.9's own precedence rule.
A declared level with no stamped artifact is OMITTED from the tree with
its opener's warning (declared-but-unmaterialized is a legal recorded
state — declaring is free, sweeping is the operational decision), and
an aoi scopes ROWS per level, never the tree's shape: an
out-of-coverage AOI empties each materialized level schema-correct
(issue #4). The seamless mixed-order composite stays a computed view,
never a node, and zoom-out ergonomics (a default coarse level for a
first render) stay espg/moczarr#21's.
levels restricts the assembly to a subset of the declared cell
orders (a bounded-cost open on a wide ladder — a /2 store declares
every order down to 0); an order outside :func:pyramid_levels' table
raises, listing the store's levels. product re-roots on a D19
multi-product subtree, manifest/store thread an already-read
manifest and an already-constructed handle, and window follows each
arm's D23 seam (required on a windowed store, refused on an unwindowed
one, the reserved all-time token refused everywhere). Deliberately no
decode=: pyramid surfaces are native moczarr only (the
englacial/zagg#550 ruling).
all_time is the windowed store's cross-window surface (issue #31,
the recorded option-(1) posture): the tree's groups are the §4.5
all-time FOLD levels alone — overviews-only, honest about what is
materialized. The source level and any §4.6 column levels are ABSENT
(a windowed store has no all-time source leaf and no all-time column),
unless levels= names one explicitly, which raises instead of
silently dropping the request. Refused beside window= (the fold
sums every window), on an unwindowed store (whose artifacts ARE its
all-time folds — open them with window=None), and — THIS opener
alone, see :func:open_level — on a declaration without all_time
folds, because the whole-ladder alternative is a childless tree of
warnings rather than a pointed answer.
Source code in src/moczarr/level.py
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 | |
pyramid_levels(manifest)
{cell order: level record} — every addressable resolution, finest first.
The resolution table of the #37 model: one entry per level of the store, keyed by the CELL ORDER a reader picks (never by node order — resolution is the reader-facing axis, zagg spec §4's "a reader picks its resolution and reads it"). Each record is::
{"cell_order": r, "order": k, "artifact": kind}
where order is the hive-tree node order whose artifact carries the
level and artifact names the kind — the vocabulary deliberately
mirrors the zagg-multiscales/1 dataset entries (zagg#392/#555:
order/cells/artifact), read here from the normative
pyramid block via :func:moczarr.pyramid.pyramid_declaration
rather than the derived mirror:
"source"— the native resolution (manifest["cell_order"]at the shard nodes), present for EVERY store: a declared-off pyramid is the one-level table;"overview"— a §4.1 ancestor-node artifact: the/1constant-depth orders, or a/2fixed-ladder rung;"column"— a/2declared leaf resolution, materialized by the §4.6 leaf columns (leaf_cells;/1declares none).
Declared, not probed: what is on disk is :func:moczarr.pyramid.
read_pyramid's question (declaring is free, sweeping is the
operational decision — zagg#381 point (11)), and the §4.6 node-order
member (r == shard_order — a recorded column group, never a
manifest member) is deliberately absent here while
:func:open_column_order still opens it. Raises when one cell order is
declared at two nodes: "one resolution names one level" is this model's
addressing law, and a duplicated resolution has no single answer.
Source code in src/moczarr/level.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |