moczarr.open
open_hive: a morton-hive store as one lazy xarray Dataset.
The §5 reader flow, arithmetic-first (D10): manifest GET → root coverage MOC ∩ AOI → hive paths by string arithmetic → stamped-leaf opens → concat along the cell dimension. The discovery walk runs only when the root MOC is absent/unusable (D9: caches degrade to the walk, never to wrong answers). Debris (unstamped leaves) is skipped silently — absence of a stamp IS the answer (D4).
AOI semantics: aoi is a morton cover — packed uint64 words, decimal
strings, or an object exposing __morton_moc__() (mortie's Moc),
mixed orders allowed. Shards are rejected arithmetically
(root MOC ∩ AOI), then per leaf by the tier-0 box off the stamp already
fetched, and finally rows are subset exactly on the morton coordinate
(tier 2 — the coordinate is the truth; the MOC tiers are only indexes).
An AOI (or window) that intersects no coverage is a data answer, not an
error: the result is a schema-correct EMPTY dataset plus a UserWarning
(issue #4). Only a store with no stamped coverage anywhere — no schema
source at all — raises, as :class:moczarr.exceptions.NoCoverageError.
candidate_leaves(store_root, manifest=None, aoi=None, window=None, *, when=None, store=None, concurrency=None, **store_kwargs)
Store-relative leaf paths to try, ascending in packed-word order.
The store's leaf-discovery seam, shared by :func:open_hive and
:func:moczarr.iter_occupancy_and so the two agree on what a store
contains by construction rather than by duplicated arithmetic. Public
(issue #39) for readers that need the leaf roster without opening
anything — the paths are what moczarr.store.read_commits and
moczarr.store.read_leaf_metas take. :func:candidate_shards is the
same seam returning shard IDS — what :func:moczarr.open_leaf, and so
the ragged/HHDC readers it hands a store to, take — through one shared
implementation (issue #49), so the two views can never disagree; a
caller wanting ids asks it rather than re-parsing these paths, whose
grammar (the .zarr suffix, the path_grouping node depth, the
windowed {id}_{window} dialect) is the store's own.
manifest is optional (issue #49): when omitted, this call fetches it
— ONE extra metadata GET, the same one-GET-if-absent posture
:func:moczarr.open_leaf takes for manifest=None — and raises
ValueError when the root has none (a multi-product root gets the
pointed §6.5 error naming its products). Pass it explicitly to skip the
GET — the right call in a loop over many AOIs against one store. The
GET is the whole extra cost: a call resolves ONE object store up front
and threads it through every read it makes, so the transport count is
one per call whichever route runs and whether or not the manifest was
passed. **store_kwargs pass through to
:func:moczarr.store.open_object_store (anonymous=True,
region=..., explicit keys, ...), the passthrough the sibling
functions (:func:moczarr.store.load_root_coverage,
:func:moczarr.open_leaf) already have; store= stays the way to
share ONE handle across many calls and wins when both are given, per
moczarr.store._resolve_store.
Contract, in three parts:
- Discovery. The root
coverage.mocnames the committed shards, and leaf paths come from it by string arithmetic (D10) — no LIST. The discovery walk (moczarr.store.walk_leaves) runs only when that envelope is absent or unusable, and is SEMANTICALLY EQUIVALENT: it is a fallback, never a wrong answer, so a caller never keys on which route ran (D9 — caches degrade to the walk, never to wrong answers). Both return CANDIDATES in ascending packed-word order, and the two candidate sets differ only where a stamp settles it anyway (D4: absence of a stamp IS the answer): the walk additionally names debris (unstamped leaves the root MOC does not list), and the arithmetic path additionally names MOC-listed shards whose object is gone. After the caller's commit-stamp GET — which every consumer here does — the two agree leaf-for-leaf withwhen=None; underwhen=the walk returns a SUPERSET, because the temporal map it would prune against rides the same absent carrier (see thewhenbullet — degradation in the safe direction, D9, and no commit stamp settles it: a stamp says the leaf exists, not when its rows are). Objects that reuse the window-naming dialect at ancestor nodes (overview zarrs, spec §4.2) are not leaves and neither route returns them, and neither names an order-29 POINT stem (§2/§6.6: points never live in hive paths). One further asymmetry: the walk can name a single shard TWICE, because a*.zarrchild is a leaf at whatever node holds it and its node depth is not checked against the shard's order — so a store holding one shard's leaf at two nodes walks as two leaves, which is two distinguishable paths here and two EQUAL ids from :func:candidate_shards. The arithmetic route names each word once and never does; the two entries' relative order is the walk's own (the sort key is the word alone). - Window selection.
windowpicks the time window of amorton-hive/2store, validated through the oneconvention.validate_windowseam (which also refuses the reserved all-time token). A windowed store withwindow=Nonecannot take the arithmetic path — the walk enumerates what exists and theValueErrorlists the labels present.windowon an unwindowed store is aValueError. aoirestriction (SHARD cover only). A morton cover — packed words, decimal strings, or an object exposing__morton_moc__()(mortie'sMoc), mixed orders allowed — restricts the returned leaves to those whose subtree meets it. It cuts SHARDS and nothing finer: a returned leaf is kept whole, and the cells inside it are NOT clipped to the cover, so any cell-level use of this roster is a superset with respect to the AOI (false positives possible, false negatives impossible — zagg's AOI-overhang convention). The exact cell-level cut is :func:moczarr.coverage.aoi_mask, which :func:open_hiveapplies to themortoncoordinate itself (tier 2 — the coordinate is the truth; the MOC tiers are only indexes).whenrestriction (temporal, spec §10; issue #45). A temporal query —(start, end)as ISO strings /datetime64/ internal-ns ints (a CLOSED real interval — unlike every other window in this docstring,enditself is included), rawuint64toc words, or an object exposing__toc_words__()(mortie'sToc) — prunes candidates against the root envelope's tier-1 per-shard toc word map, before anything is opened. The §10 asymmetry is the contract: only a shard the map LISTS whose word failsmortie.toc_overlapsfor the window is dropped; a shard ABSENT from the map is always KEPT (unlisted is unknown, never empty — the section is a regenerable accelerator, not truth). A store publishing notemporalsection prunes nothing, silently (§10's absence rule), andwhen=Noneis byte-identical to today. Pruning rides the root envelope's tier-1 map ALONE, so the discovery walk — which runs exactly when that envelope is absent or unusable — has nothing to prune against and returns the unpruned candidate set, a conservative superset (D9: degrade, never wrong). Likeaoi, the cut is conservative and SHARD-level: kept leaves may hold rows outside the window. The over-report near window edges runs to a few seconds — up to TWO encoding quanta, one from round-tripping the query window itself throughspan2toc/toc2timeand one from the shard's own outward-rounded word undermortie.toc_overlaps— and every widening is outward, so it never under-reports.
Source code in src/moczarr/open.py
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 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 | |
candidate_shards(store_root, manifest=None, aoi=None, window=None, *, when=None, store=None, concurrency=None, **store_kwargs)
Candidate shard IDS (morton decimal strings), ascending in packed-word order.
:func:candidate_leaves returning what :func:moczarr.open_leaf takes
(issue #49): the same discovery seam through the same one implementation
— discovery routes, window selection, the shard-level aoi and
when restrictions, and every posture in that docstring hold here
verbatim; only what is handed back differs. A separate name rather than
a flag because the return TYPE changes (mortie's Moc.to_order
precedent, espg/mortie#197): ids like "11213", not store-relative
paths like "1/1/2/1/3/11213.zarr".
The id is the path's stem the library knew before it built the path, so
select-then-open needs no string surgery and no knowledge of the path
grammar (.zarr suffix, path_grouping depth, the windowed
{id}_{window} dialect). With the manifest fetched when omitted and
**store_kwargs passing through (issue #49; the posture and the
one-extra-GET cost are on :func:candidate_leaves's docstring), the
whole selection is one call — and the manifest it fetched is worth
reading once for the loop, since open_leaf(manifest=...) skips its
own manifest GET (each open still GETs its leaf's root stamp — the
versioned-leaf pointer, zagg spec §1.5 — unless stamp= is threaded
from one batched :func:moczarr.store.read_commits over the paired
:func:candidate_leaves)::
shards = candidate_shards(root, aoi=q, anonymous=True)
manifest = read_manifest(root, anonymous=True) # once, not per leaf
for shard in shards:
leaf = open_leaf(root, shard, manifest=manifest, anonymous=True)
On a windowed store the id is the BARE shard — the window label is not
part of it; pass the same window= to :func:moczarr.open_leaf.
Positionally identical lists: candidate_shards(...)[i] names the
leaf candidate_leaves(...)[i] locates, for equal arguments against
an unchanged store. The shared implementation makes ONE discovery's two
views agree; it does not join two calls. Each call is its own discovery
— two root-MOC GETs, or two full walks — so against a store being
written concurrently the two lists can differ in length, and index
i then names different things. The ruled idiom (issue #49 review;
the internal pair stays private until a consumer shows real friction):
make both calls share their inputs — fetch the manifest ONCE (or thread
one store=) and pass it to both. Sharing buys exactly two things —
the duplicate manifest GET is skipped, and ONE path_grouping is
pinned across the pair so both render the same path grammar. It
snapshots nothing: each call still re-GETs the root envelope (or
re-walks), so the "unchanged store" caveat above is untouched by the
idiom. A pair that must be tear-proof against a concurrent writer takes
ONE view and derives the other through the convention seam — library
parsers, not caller-side string surgery — instead of issuing both
calls. Path to id: :func:moczarr.convention.split_leaf_name on the
path's BASENAME (rel.rsplit("/", 1)[-1], .zarr suffix included
— it is the suffixed name the parser requires, not the bare id),
returning (id, window_label). Id to path:
:func:moczarr.convention.leaf_path threaded with the same two
arguments the discovery used, leaf_path(shard, window=window,
path_grouping=manifest_path_grouping(manifest)) — a bare
leaf_path(shard) silently drops the window label and assumes
path_grouping=1, and stops naming the same objects.
Source code in src/moczarr/open.py
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 | |
open_hive(store_root, *, product=None, aoi=None, window=None, anonymous=False, fabricate_cell_ids='auto', decode=False, index_kind='moc', concurrency=32, xr_kwargs=None, store=None, manifest=None, _objects_out=None, **store_kwargs)
Open a morton-hive store as one xarray Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store_root
|
str
|
Store root (local directory or |
required |
product
|
str
|
Named product of a multi-product store root (D19, spec §6.5): sugar
for opening the |
None
|
aoi
|
array - like
|
Morton cover of the area of interest — packed |
None
|
window
|
str
|
Window label for a time-windowed ( |
None
|
anonymous
|
bool
|
Unsigned S3 requests (public buckets). |
False
|
fabricate_cell_ids
|
('auto', True, False)
|
NESTED |
"auto"
|
decode
|
bool
|
Assign the xdggs |
False
|
index_kind
|
('moc', 'pandas')
|
Index posture for the |
"moc"
|
concurrency
|
int or None
|
Maximum in-flight metadata requests (the candidate leaves' stamp
GETs, and the discovery walk's per-level LISTs), default 32 — the
zarr-python knob vocabulary. |
32
|
xr_kwargs
|
dict
|
Extra keyword arguments for each leaf's |
None
|
store
|
obstore store
|
An already-constructed object store rooted at the subtree actually
opened, shared instead of building one from |
None
|
manifest
|
dict
|
An already-read |
None
|
**store_kwargs
|
Any
|
Extra keyword arguments for the object store ( |
{}
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Leaves concatenated along the cell dimension in ascending packed
morton order, with An Raises |
Source code in src/moczarr/open.py
543 544 545 546 547 548 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 733 734 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 921 | |
open_leaf(store_root, shard, *, window=None, product=None, manifest=None, stamp=None, anonymous=False, store=None, **store_kwargs)
Open ONE shard's leaf zarr as a read-only zarr store.
The leaf-direct twin of :func:open_hive, for the per-leaf readers
(:func:moczarr.hhdc.read_tensors, :func:moczarr.ragged.open_ragged,
...): it owns the three layers a caller otherwise hand-assembles — the
leaf path from the manifest's grammar (convention.leaf_path under the
manifest's path_grouping), the transport with the SAME credential /
anonymous handling as :func:open_hive, and the
zarr.storage.ObjectStore read-only wrapper the readers take. No
external path arithmetic, no bare-obstore incantation.
It also follows the versioned-leaf pointer (zagg spec §1.5): ONE GET of
the leaf's root zarr.json (none when stamp= is threaded), and
when that stamp names current the
returned store is rooted at the version subgroup holding the arrays
(:func:moczarr.store.leaf_data_prefix) — a legacy leaf, and an
unstamped or absent one, root at the stable prefix as before. Either
way the readers address {cell_order}/{name} unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store_root
|
str
|
The hive store root ( |
required |
shard
|
str or int
|
The leaf's shard — packed morton word or decimal string. |
required |
window
|
str
|
Time-window label for a windowed leaf ( |
None
|
product
|
str
|
Product name under a multi-product root (D19) — the open re-roots on
the product subtree, exactly as :func: |
None
|
manifest
|
dict
|
An already-read manifest of the subtree actually opened — the
PRODUCT's manifest when |
None
|
stamp
|
dict
|
The leaf's already-read ROOT commit stamp — e.g. from
:func: |
None
|
anonymous
|
bool
|
Skip request signing (public buckets). |
False
|
store
|
obstore store
|
A shared handle for the manifest and root-stamp GETs (issue #5),
rooted at the subtree this call opens — the PRODUCT subtree when
|
None
|
**store_kwargs
|
Any
|
Forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
ObjectStore
|
Read-only store rooted at the leaf's arrays (the current version
of a versioned leaf); pass it with a field path like
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in src/moczarr/open.py
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 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 | |
open_store(store_root, *, products=None, aoi=None, window=None, anonymous=False, fabricate_cell_ids='auto', decode=False, index_kind='moc', concurrency=32, xr_kwargs=None, **store_kwargs)
Open a store root — multi-product or bare — as one xarray.DataTree.
The tree shape follows the zagg O14 rulings (issue #15): the product
axis becomes child nodes — one node per named product (D19, mortie
spec §6.5), each holding exactly the lazy Dataset :func:open_hive
returns for that product — and the root node is empty (store-level
attrs only; a multi-product root is manifest-less by design). The
window axis is never nodes (time stays a per-node dimension,
scoped by window=), and the spatial digit axis is never nodes.
Resolution (pyramid-order) nodes (issue #15 phase 8b): when a
product's manifest declares sweep-generated overviews (the zagg spec
§4.5 pyramid.overview.orders binding — manifest declaration is the
only discovery path), the product node becomes an empty intermediate
and the stored orders become its children, named by the integer cell
order they store: the source data is the source-order child (the same
open_hive Dataset, plus per-object role entries under
attrs["zagg_objects"]) and each declared overview order with at
least one stamped object is a sibling node opened by
:func:moczarr.pyramid.open_overview_order. role is per object,
never per node; sibling variable sets differ in both directions; the
seamless mixed-order composite is a computed view, never a node.
Selection helpers: :func:moczarr.pyramid.source_orders,
:func:moczarr.pyramid.overview_orders,
:func:moczarr.pyramid.finest_source_at.
A zagg-pyramid/2 declaration (the fixed ladder, issue #36b) grows
the same level: one child per materialized RESOLUTION of
:func:moczarr.level.pyramid_levels' table — the §4.6 column-carried
leaf resolutions included — named o{cell_order} (the espg-ruled
reader-side group grammar, shared with
:func:moczarr.level.open_pyramid: dot access works and the name is an
unambiguous string; store-side wire paths stay numeric), each holding
the :func:moczarr.level.open_level Dataset for that cell order
(zagg_level/zagg_objects attrs riding along), with the
normalized declaration record under the product node's
zagg_pyramid attr. decode=True is refused for such a product
(pyramid level surfaces are native moczarr only — the englacial/zagg#550
ruling), and an unknown pyramid revision fails loudly rather than
reading as declared-off (§4.5's conformance rule).
Named after its scope (the store), not its return type: the xarray-
native name open_datatree is reserved for zarr-native hierarchies,
which the hive tree deliberately is not (the D12 interop hierarchy is
xr.open_datatree's to open someday).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store_root
|
str
|
Store root (local directory or |
required |
products
|
sequence of str
|
Open only these products (a filter for stores with many). An empty
sequence raises — a childless tree is never the intended answer;
pass |
None
|
aoi
|
Forwarded to each node's :func: |
None
|
|
window
|
Forwarded to each node's :func: |
None
|
|
anonymous
|
Forwarded to each node's :func: |
None
|
|
fabricate_cell_ids
|
Forwarded to each node's :func: |
None
|
|
decode
|
Forwarded to each node's :func: |
None
|
|
index_kind
|
Forwarded to each node's :func: |
None
|
|
concurrency
|
Forwarded to each node's :func: |
None
|
|
xr_kwargs
|
Forwarded to each node's :func: |
None
|
|
**store_kwargs
|
Forwarded to each node's :func: |
None
|
Returns:
| Type | Description |
|---|---|
DataTree
|
Root node: no data variables, no coordinates — only
A bare single-product store returns the valid degenerate form:
a one-child tree, the child named from the manifest's dataset
Raises |
Source code in src/moczarr/open.py
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 | |