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

QUADRANT_RESOLUTION

Resolution addressed by a quadrant code, namely zero.

BASE_CELL_RESOLUTION

Resolution addressed by an X/Y pair, namely one.

GLOBE_RESOLUTION

Resolution of the synthetic root of a parsed tree, one level up.

Functions

base_cell_of

Resolution-1 ancestor of the addressed cells.

compose

Fold a list of atomic indices back into one compositional index.

count_cells

Number of terminal cells addressed, without materialising them.

decompose

Expand a compositional index into a flat list of atomic indices.

is_atomic

Whether the index denotes exactly one terminal cell.

is_valid_index

Whether the string parses and every code is legal for its level.

iter_cells

Stream atomic indices in decompose() order.

join_components

Assemble a component path into a fully qualified atomic index.

normalize

Reduce an index to its canonical form.

parse

Parse an index string into a nested structural tree.

quadrant_of

Global quadrant of the addressed cells.

split_components

Break an atomic index into its per-level components.