itacart.index
The compositional hierarchical index: parsing, composition, canonical form.
A single index string may denote one terminal cell or a whole region:
SE(1400/0374(3(C2(3)))) one cell
NW(0625/0451(1(E1(3(B2(4(A2,B2))))))) two sibling cells under one parent
Parentheses descend a level, commas separate siblings at the same level.
Every public operation in the package accepts this form; operations that
return one value per cell return a list aligned with
decompose() order.
Satisfies OGC DGGS Core requirement 13 (unique address): uniqueness holds
only against the canonical form produced by normalize(), since the
same region admits several spellings (4(1,2,3,4) and 4 denote the
same space).
Provenance: itacart_core/compositional_index.py, plus the parser from
the DGGS_Tree notebook.
Grammar accepted by parse(). The first production is a list rather
than a single root, so that compose() over cells of several
quadrants produces a string this module can read back:
index := root (',' root)*
root := QUADRANT subtree?
subtree := '(' nodelist ')'
nodelist := node (',' node)*
node := component subtree?
component := base | refinement
base := DIGITS '/' DIGITS (resolution 1 only)
refinement := a code of refinement_alphabet(resolution)
The even/odd rule is deliberately absent from that last production: it
lives in itacart.constants.refinement_alphabet() and nowhere else
in one place. Writing it a second time here is exactly how the inverted
happened in the prototype.
Module constants
Resolution addressed by a quadrant code, namely zero. |
|
Resolution addressed by an |
|
Resolution of the synthetic root of a parsed tree, one level up. |
Functions
Resolution-1 ancestor of the addressed cells. |
|
Fold a list of atomic indices back into one compositional index. |
|
Number of terminal cells addressed, without materialising them. |
|
Expand a compositional index into a flat list of atomic indices. |
|
Whether the index denotes exactly one terminal cell. |
|
Whether the string parses and every code is legal for its level. |
|
Stream atomic indices in |
|
Assemble a component path into a fully qualified atomic index. |
|
Reduce an index to its canonical form. |
|
Parse an index string into a nested structural tree. |
|
Global quadrant of the addressed cells. |
|
Break an atomic index into its per-level components. |