itacart.hierarchy

Hierarchical navigation: ascent, descent, compaction.

Part of OGC DGGS Core requirement 17 (topological query functions), with the neighbour half living in itacart.topology.

Every function here accepts a compositional index. Where the input holds several cells, the return is positionally aligned with itacart.index.decompose().

Two relations live here, and they coincide everywhere except at the domain border.

Lexical ancestry relates spellings: one index is an ancestor of another when it is a prefix of it, which costs a slice and never consults the domain. get_parent(), is_ancestor() and contains() answer it, and itacart.boundary.is_valid_cell() is the only arbiter of whether a prefix they return names a cell.

Physical refinement relates cells: the children of a cell are the cells that partition it. get_children(), get_descendants(), child_position(), compact_cells() and uncompact_cells() answer it, and so does the tree blob, whose compaction folds by the same rule. itacart.index.normalize() answers neither: it rewrites spelling, and withholds the one rewrite that would change the region.

Away from the border the children of a cell are the codes of the next alphabet spelled under it, and the two relations are one. A cell whose outer side has been carried onto the domain border reaches east past its own nominal column, so some of its children are spelled under the next column’s resolution-1 prefix: they exist and are addressed uniquely, but their prefix names no cell. Enumerated between resolutions 1 and 2, 2 392 of the 4 002 absorbing cells of the lateral border father 3 327 such children under 2 437 prefixes that name no cell. Under the two caps the same happens deeper: 12 of the 88 cells at resolution 4 and 228 of the 2 388 at resolution 5 are spelled under a prefix that names no cell. For each of those the lexical parent is a well-formed string that names no cell, contains() of the physical parent answers false, and the physical parent is found by refinement. Their descendants carry the prefix as a lexical ancestor; under the caps, the other 284 cells of resolution 5 with such an ancestor are spelled under their physical parent.

Functions that descend consult itacart.boundary.absorbs_border() first and take a purely lexical path when it answers false, which it does for every cell of the lattice except the border-absorbing family.

The absorbing side is a chord, and a child’s chord is not its parent’s. This is the geometric half of the same parting, and it is a declared limitation of this version rather than a defect awaiting repair. The domain border is a smooth convex curve on the plane, and an absorbing cell replaces its outer side by the chord of that curve across its own height. A parent spans one cell height and takes one chord; each child spans half that and takes two, and a chord of a convex curve over a shorter span lies further out. So a child of an absorbing cell reaches past its parent’s effective ring, by construction rather than by accident, and no enumeration order changes it.

Measured over 572 lateral parents – the last column of every seventh row in four quadrants – every parent is affected and exactly two children of each leave, which is 1 144 children. The share of a child’s own area falling outside its parent has a median of 0.038142 per cent, a mean of 0.056931, a ninetieth percentile of 0.104096 and a worst case of 2.411015 at SE(1930/0196). The excess has a closed form: the sagitta of the border across the parent’s height, times half that height, to four decimal places. Every figure in this paragraph is fixed by a named test, and those tests fail if the absorbing side stops being a per-cell chord.

What the approximation does not cost is stated with the same care, because a limitation whose edges are not drawn is read as larger than it is. The children still cover the parent: the shortfall stays under one part in a million of the parent’s area, measured at 1.1e-12 over those 572 parents and 2.1e-16 under the caps. The criterion that bounds it is one-sided by design – it bounds the shortfall and says nothing about the excess, which is this section’s subject, so it must not be read as saying the cover is exact or the summed child area a fixed multiple of the parent’s. Neither is true here. Quantisation stays total and deterministic: a position inside the excess is answered by the child whose excess it is at the child’s resolution, and by the parent at the parent’s, in a fresh interpreter as in this one. No public name has to emit a spelling itacart.boundary.is_valid_cell() denies because of any of it. Physical refinement preserves the region, so itacart.index.normalize() does not grow one and compaction still folds by the children a parent has.

What it does cost is contains(), which tests the effective chordal ring. A query bounded by the domain border can leave out a leaf whose effective geometry protrudes past the query’s own piece, by a few square metres or by a few thousand, and under contains that leaf is not kept. Measured on row 300 in four quadrants, with the parent’s effective ring as the query, one leaf of three is kept at resolution 2 and 53 of 63 at resolution 3, while intersects returns the whole family. That is the excess asked about from outside instead of from the parent, not a second defect and not a defect of contains.

Representing the border exactly would mean carrying a side, a resolution-1 row and an interval instead of a ring. That was investigated and is not in this version.

The cell that holds a pole at resolution 10 is not refined. That cell, NE(0000/1000(1(B2(4(E5(4(B2(4(A1(4)))))))))) at the north pole and its twin under SE at the south, exists, and its children cannot be enumerated: the cells found leave part of its ring uncovered, so they do not partition it. get_children(), get_descendants() and uncompact_cells() raise GeometryError for it as their result is iterated, and the names that refine through them do the same: itacart.intervals.cells_to_intervals() asked for a resolution finer than 10 there, and itacart.geometry.polyfill(), itacart.geometry.count_internal_cells(), itacart.interop.from_geojson() and itacart.interop.from_geodataframe() for a geometry that reaches the cell, from resolution 11. Inside the cell, at resolutions 11 and 12, a position can be answered with a spelling that names no cell, as itacart.cells states. Both are known limitations of this version, and named tests pin them so that they fail when either is fixed.

Functions

child_position

Ordinal of a cell among its siblings.

common_ancestor

Deepest cell containing every terminal cell of the index.

compact_cells

Replace exhaustive sibling sets by their parent, recursively.

contains

Whether a compositional region covers a cell.

get_ancestors

Every ancestor of a cell, coarse to fine.

get_children

Project descendants of an index down to a target resolution.

get_descendants

Stream every descendant at a target resolution.

get_parent

Ascend the hierarchy by lexical truncation.

is_ancestor

Whether one cell contains another in the hierarchy.

uncompact_cells

Expand a compacted index back to uniform resolution.