ngff_zarr._v2_store_reader¶
Minimal pure-Python reader for zarr MutableMapping stores.
zarrista only opens FilesystemStore/MemoryStore/ZipStore — its
SyncStore is a closed union with no way to feed it an arbitrary
key-to-bytes mapping (see the Phase 01 capability matrix). This module covers
the store types that therefore cannot go through zarrista: zip archives read
as name-to-bytes mappings, tifffile’s aszarr virtual store, and plain
in-memory dicts.
The zarr format 2 reader parses .zgroup/.zattrs/.zarray documents
(consolidated .zmetadata is used for all metadata lookups when present,
matching zarr-python’s consolidated semantics) and decodes chunks with
numcodecs (compressor + filters, C/F order, fill_value for missing chunks,
. and / dimension separators). A companion zarr format 3 reader
parses zarr.json documents for unsharded arrays whose codec chain is the
bytes codec plus numcodecs-decodable compression (what tifffile’s
aszarr store serves); sharded v3 stores must be read through zarrista.
Arrays are exposed as lazy dask arrays with one delayed chunk fetch per
stored chunk. This module intentionally imports neither zarr-python nor
zarrista.
Module Contents¶
Classes¶
Plain dict exposing zarr-python’s |
|
Buffer factory returning plain |
|
The |
|
Read-only |
|
A |
|
Shared lazy-dask surface for chunked array nodes read from a mapping. |
|
A zarr format 2 array node read lazily from a bytes mapping. |
|
A zarr format 2 group node read from a bytes mapping. |
|
An unsharded zarr format 3 array node read lazily from a bytes mapping. |
|
A zarr format 3 group node read from a bytes mapping. |
Functions¶
Normalize a node path to the store-key form (no leading/trailing /). |
|
Decode a |
|
Decode a JSON |
|
Run coro to completion from synchronous code. |
|
Open the node at path within a v2 bytes-mapping store. |
|
Open the array node at path within a v2 bytes-mapping store. |
|
Open the group node at path within a v2 bytes-mapping store. |
|
A numcodecs codec that decodes the given v3 bytes-to-bytes codec. |
|
Open the node at path within a v3 bytes-mapping store. |
|
Open the node at path within store, auto-detecting the zarr format. |
|
Open the array node at path within store (either zarr format). |
Data¶
API¶
- ngff_zarr._v2_store_reader.__all__¶
[‘AsyncStoreMapping’, ‘AttrsDict’, ‘V2Array’, ‘V2Group’, ‘V3Array’, ‘V3Group’, ‘open_store_array’, ‘…
- ngff_zarr._v2_store_reader._FLOAT_FILLS¶
None
- class ngff_zarr._v2_store_reader.AttrsDict¶
Bases:
dictPlain dict exposing zarr-python’s
Attributes.asdict()surface.Lets the read path treat node attributes uniformly across backends (zarr-python groups, this reader, the compat-layer local reader).
Initialization
Initialize self. See help(type(self)) for accurate signature.
- ngff_zarr._v2_store_reader._normalize_path(path) str¶
Normalize a node path to the store-key form (no leading/trailing /).
- ngff_zarr._v2_store_reader._decode_dtype(spec) numpy.dtype¶
Decode a
.zarraydtype: a numpy string or the structured list form.
- ngff_zarr._v2_store_reader._parse_fill_value(fill, dtype: numpy.dtype)¶
Decode a JSON
fill_valueto a numpy scalar of dtype.None(JSON null, “undefined” in the v2 spec) maps to zero, matching what zarr-python materializes for missing chunks in that case. Float specials arrive as the strings"NaN"/"Infinity"/"-Infinity"; fixed-length bytes and structured fills arrive base64-encoded.
- ngff_zarr._v2_store_reader._run_coroutine(coro)¶
Run coro to completion from synchronous code.
Chunk fetches happen inside dask worker threads, which have no running event loop; when one is running (e.g. the caller’s thread in Jupyter), the coroutine runs on a private loop in a helper thread instead.
- class ngff_zarr._v2_store_reader._BytesBufferShim¶
Buffer factory returning plain
bytes, ducking zarr’s Buffer API.
- class ngff_zarr._v2_store_reader._BytesPrototypeShim¶
The
prototype.buffersurface async stores build results through.- buffer¶
None
- class ngff_zarr._v2_store_reader.AsyncStoreMapping(store)¶
Bases:
collections.abc.MappingRead-only
Mapping[str, bytes]view over an async byte store.Adapts stores implementing the zarr-python 3 async
Storeinterface (await get(key, prototype),async for key in list()) – e.g. tifffile’saszarrZarrTiffStore– to the bytes-mapping surface- Func:
open_v2consumes, without importing zarr-python: the prototype handed togetis a minimal shim producing plainbytes.
Iteration yields the store’s listable keys (for tifffile these are the metadata documents; chunk keys are computed on demand), which is exactly the surface :class:
_V2Sourceneeds for metadata lookups and child listing. Missing keys – including chunks the store reports as absent – raiseKeyError, which the reader materializes asfill_value.Initialization
- __iter__() collections.abc.Iterator[str]¶
- class ngff_zarr._v2_store_reader._V2Source(mapping: collections.abc.Mapping)¶
A
MutableMapping[str, bytes]plus its consolidated metadata.Shared by every node opened from one store so
.zmetadatais parsed once. When consolidated metadata is present it is the sole source for metadata documents and child listing (zarr-python’s consolidated semantics); chunk payloads always come from the mapping.Initialization
- metadata_keys() collections.abc.Iterator[str]¶
- class ngff_zarr._v2_store_reader._LazyChunkedArray¶
Shared lazy-dask surface for chunked array nodes read from a mapping.
Subclasses set
shape/chunks/dtype/ndimand implement_read_chunk(chunk_index) -> np.ndarrayreturning the in-bounds extent at that grid position.- _trim_edge_chunk( ) numpy.ndarray¶
Trim a full-shape stored chunk to its in-bounds extent.
Both zarr formats store edge chunks padded to the full chunk shape.
- to_dask() dask.array.Array¶
The array as a lazy dask array chunked on the stored chunk grid.
One delayed chunk fetch per stored chunk; nothing is read until compute.
pure=Falsekeeps dask from tokenizing the fetch arguments, which would hash (or choke on) the backing store object.
- class ngff_zarr._v2_store_reader.V2Array(source: ngff_zarr._v2_store_reader._V2Source, path: str, meta: dict)¶
Bases:
ngff_zarr._v2_store_reader._LazyChunkedArrayA zarr format 2 array node read lazily from a bytes mapping.
Initialization
- _decode_chunk(raw) numpy.ndarray¶
- class ngff_zarr._v2_store_reader.V2Group(source: ngff_zarr._v2_store_reader._V2Source, path: str)¶
A zarr format 2 group node read from a bytes mapping.
Initialization
- __getitem__(name)¶
- open_array(name) ngff_zarr._v2_store_reader.V2Array¶
- open_group(name) ngff_zarr._v2_store_reader.V2Group¶
- ngff_zarr._v2_store_reader.open_v2(store: collections.abc.Mapping, path=None)¶
Open the node at path within a v2 bytes-mapping store.
Returns a :class:
V2Arrayor :class:V2Groupdepending on the node type (arrays win when both documents exist, matching zarr-python), or raisesKeyErrorwhen neither metadata document is present.
- ngff_zarr._v2_store_reader.open_v2_array(
- store: collections.abc.Mapping,
- path=None,
Open the array node at path within a v2 bytes-mapping store.
- ngff_zarr._v2_store_reader.open_v2_group(
- store: collections.abc.Mapping,
- path=None,
Open the group node at path within a v2 bytes-mapping store.
- ngff_zarr._v2_store_reader._V3_BLOSC_SHUFFLE¶
None
- ngff_zarr._v2_store_reader._v3_bytes_codec(codec: dict)¶
A numcodecs codec that decodes the given v3 bytes-to-bytes codec.
- class ngff_zarr._v2_store_reader.V3Array(mapping: collections.abc.Mapping, path: str, doc: dict)¶
Bases:
ngff_zarr._v2_store_reader._LazyChunkedArrayAn unsharded zarr format 3 array node read lazily from a bytes mapping.
Supports the
bytesarray-to-bytes codec (either endian) followed by numcodecs-decodable compression. The sharding and transpose codecs are rejected: stores using them should be read through zarrista instead.Initialization
- class ngff_zarr._v2_store_reader.V3Group(mapping: collections.abc.Mapping, path: str, doc: dict)¶
A zarr format 3 group node read from a bytes mapping.
Initialization
- __getitem__(name)¶
- ngff_zarr._v2_store_reader.open_v3(store: collections.abc.Mapping, path=None)¶
Open the node at path within a v3 bytes-mapping store.
Returns a :class:
V3Arrayor :class:V3Group, or raisesKeyErrorwhen nozarr.jsondocument is present at that path.
- ngff_zarr._v2_store_reader.open_store_node(store: collections.abc.Mapping, path=None)¶
Open the node at path within store, auto-detecting the zarr format.
Zarr format 3 (
zarr.json) wins when both formats are present, matching zarr-python’s auto-detection order.
- ngff_zarr._v2_store_reader.open_store_array(store: collections.abc.Mapping, path=None)¶
Open the array node at path within store (either zarr format).