Headers

Format-specific header preservation for zarr vectors stores.

Headers are stored in the attributes of /headers/<format>/ as raw JSON-compatible dicts. The registry provides opaque round-trip storage; typed (de)serialisation of header dicts lives in the format package.

Source-format headers (for example from .trk, .swc or Neuroglancer precomputed files) kept with a store. Each is stored whole, uninterpreted, as the attributes of /headers/<format>/.

class zarr_vectors.headers.registry.HeaderRegistry(store_path_or_root)[source]

Bases: object

Manages format-specific headers within a zarr vectors store.

Parameters:

store_path_or_root (str | Path | Group) – Either a filesystem path (str/Path) to the store, or an already-open Group root handle.

The handle check is against Group, not FsGroup. FsGroup is returned only when the backing store happens to be a LocalStore, so testing for it meant a cloud-backed root fell through to open_store(str(root)) – which stringifies a Group and then tries to open the result as a path.

__init__(store_path_or_root)[source]
Parameters:

store_path_or_root (str | Path | Group)

Return type:

None

add(format_name, header)[source]

Store a format header as a dict.

If a header for this format already exists, it is overwritten.

Parameters:
  • format_name (str) – Format identifier.

  • header (dict[str, Any]) – JSON-compatible dict of header fields.

Return type:

None

property available_formats: list[str]

List of format names with stored headers.

get(format_name)[source]

Read a format header as a raw dict.

Parameters:

format_name (str) – Format identifier (e.g. "trk", "swc").

Returns:

The JSON-compatible attributes dict for this format.

Raises:

KeyError – If no header exists for this format.

Return type:

dict[str, Any]

has(format_name)[source]

Check if a header exists for the given format.

Parameters:

format_name (str)

Return type:

bool

remove(format_name)[source]

Remove a stored header.

Parameters:

format_name (str) – Format to remove.

Raises:

KeyError – If no header exists for this format.

Return type:

None

Reached from a dataset as headers:

import zarr_vectors as zv

ds = zv.open("tracts.zarrvectors", mode="r+")
ds.headers.add("trk", {"voxel_to_rasmm": [[1, 0, 0, 0], [0, 1, 0, 0],
                                          [0, 0, 1, 0], [0, 0, 0, 1]]})
ds.headers.available_formats      # ['trk']
ds.headers.get("trk")             # the dict back, unchanged