zarr_indexing.transform
zarr_indexing.transform ¶
Index transforms — composable, lazy coordinate mappings.
An IndexTransform pairs an input domain (the coordinates a user sees)
with a tuple of output maps (the storage coordinates those inputs map to).
One output map per storage dimension. See output_map.py for the three
output map types.
Key operations:
-
Indexing (
transform[2:8],.oindex[idx],.vindex[idx]) — produces a new transform with a narrower input domain and adjusted output maps. No I/O occurs. This is how lazy slicing works. -
intersect(output_domain) — restrict to storage coordinates within a region. This is chunk resolution: "which of my coordinates fall in this chunk?"
-
translate(shift) — shift all output coordinates. This makes coordinates chunk-local: "express my coordinates relative to the chunk origin."
-
compose(outer, inner) — chain two transforms. See
composition.py.
The transform is the atomic unit that connects user-facing indexing to
chunk-level I/O. Every Array holds a transform (identity by default).
Array.lazy[...] composes a new transform lazily. Reading resolves the
transform against the chunk grid via intersect + translate.
IndexTransform
dataclass
¶
A composable mapping from input coordinates to storage coordinates.
An IndexTransform has:
domain: anIndexDomaindescribing the valid input coordinates (the user-facing shape, possibly with non-zero origin).output: a tuple of output maps (one per storage dimension), each describing which storage coordinates the inputs touch.
For a freshly opened array, the transform is the identity: input
coordinate i maps to storage coordinate i. Indexing operations
compose new transforms without I/O.
Source code in packages/zarr-indexing/src/zarr_indexing/transform.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 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 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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
selection_repr
property
¶
selection_repr: str
Compact domain string, e.g. '{ [2, 8), [0, 10) }'.
Follows TensorStore's IndexDomain notation: each dimension shown
as [inclusive_min, exclusive_max) with stride annotation if not 1.
Constant (integer-indexed) dimensions show as a single value.
Array-indexed dimensions show the set of selected coordinates.
__getitem__ ¶
__getitem__(selection: Any) -> IndexTransform
__post_init__ ¶
Source code in packages/zarr-indexing/src/zarr_indexing/transform.py
__repr__ ¶
__repr__() -> str
Source code in packages/zarr-indexing/src/zarr_indexing/transform.py
from_shape
classmethod
¶
from_shape(shape: tuple[int, ...]) -> IndexTransform
identity
classmethod
¶
identity(domain: IndexDomain) -> IndexTransform
intersect ¶
intersect(
output_domain: IndexDomain,
) -> (
tuple[
IndexTransform,
dict[int, ndarray[Any, dtype[intp]]]
| ndarray[Any, dtype[intp]]
| None,
]
| None
)
Restrict this transform to storage coordinates within output_domain.
Returns (restricted_transform, out_indices) or None if empty.
out_indices carries the surviving output positions: None when all
positions survive (ConstantMap/DimensionMap only), a single integer array
for one ArrayMap (or correlated/vectorized ArrayMaps), or a dict keyed by
output dimension for >= 2 orthogonal ArrayMaps (an outer product).
Source code in packages/zarr-indexing/src/zarr_indexing/transform.py
translate ¶
translate(shift: tuple[int, ...]) -> IndexTransform
Shift all output coordinates by shift.
Source code in packages/zarr-indexing/src/zarr_indexing/transform.py
translate_domain_by ¶
translate_domain_by(
shift: tuple[int, ...],
) -> IndexTransform
Shift the input domain by shift, preserving which cells are addressed.
TensorStore's translate_by: the domain moves, and every output map is
re-offset so that new coordinate c addresses the cell that c - shift
addressed before. ArrayMaps are indexed positionally over the domain, so
their index arrays are unchanged.
Source code in packages/zarr-indexing/src/zarr_indexing/transform.py
translate_domain_to ¶
translate_domain_to(
origins: tuple[int, ...],
) -> IndexTransform
Move the input domain so its per-dimension origins equal origins.
TensorStore's translate_to; translate_domain_to((0,) * rank)
re-zeros a view's coordinate system without changing which cells it
addresses.
Source code in packages/zarr-indexing/src/zarr_indexing/transform.py
selection_to_transform ¶
selection_to_transform(
selection: Any,
transform: IndexTransform,
mode: Literal["basic", "orthogonal", "vectorized"],
) -> IndexTransform
Convert a user selection into a composed IndexTransform.
Negative indices are treated as literal coordinates (TensorStore convention). The caller (Array layer) is responsible for converting numpy-style negative indices before calling this function.