Headers¶
zarr_vectors_tools.headers: the source format’s metadata that the store’s
arrays cannot hold, kept under headers/<format>/ so that an export can
write it back. HeaderRegistry
reads and writes it as one dataclass per format.
Registry¶
HeaderRegistry — typed format headers on top of core’s dict registry.
Headers live in the attributes of /headers/<format>/ (its
zarr.json). Core owns the storage half
(zarr_vectors.headers.HeaderRegistry), which round-trips opaque
JSON dicts and knows nothing about formats; this subclass adds the half
that belongs to a format package — turning those dicts into the
Header dataclasses, and back.
- class zarr_vectors_tools.headers.registry.HeaderRegistry(*args, **kwargs)[source]¶
Bases:
HeaderRegistryManages format-specific headers within a zarr vectors store.
Same constructor as core’s — a path/URL, or an already-open
Grouproot handle.addandgetspeakHeaderrather thandict;available_formats,hasandremoveare inherited unchanged.- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
Format-specific headers¶
Format-specific header dataclasses.
Each header captures the metadata that would be lost when converting
to the zarr vectors format. Stored as JSON-serialisable dicts in the
attributes of /headers/<format>/ (its zarr.json).
- class zarr_vectors_tools.headers.formats.CSVHeader(format_name='csv', column_names=<factory>, delimiter=', ', position_columns=<factory>, attribute_columns=<factory>, has_header_row=True, normalise_offset=None, normalise_scale=None)[source]¶
Bases:
HeaderCSV point cloud file header metadata.
normalise_offsetandnormalise_scaleare populated by thenormalise=Trueingest path so export can invert the transform. They areNonefor stores that were not normalised.- Parameters:
- __init__(format_name='csv', column_names=<factory>, delimiter=', ', position_columns=<factory>, attribute_columns=<factory>, has_header_row=True, normalise_offset=None, normalise_scale=None)¶
- class zarr_vectors_tools.headers.formats.GraphHeader(format_name='graph', node_count=0, edge_count=0, is_directed=False, mean_degree=0.0, n_components=0, largest_component_size=0)[source]¶
Bases:
HeaderGraph-level summary metrics.
Stored as a workaround for the lack of per-object attributes on the
graphsgeometry type in the core write API. When that gap is closed in core, this header can migrate intograph_attributes.- Parameters:
- __init__(format_name='graph', node_count=0, edge_count=0, is_directed=False, mean_degree=0.0, n_components=0, largest_component_size=0)¶
- class zarr_vectors_tools.headers.formats.H5ADHeader(format_name='h5ad', spatial_key='spatial', spatial_ndim=3, spatial_columns=<factory>, n_obs=0, n_vars=0, obs_names=<factory>, obs_attrs=<factory>, gene_names=<factory>, gene_attrs=<factory>, layer=None, categories=<factory>, dtypes=<factory>, row_attr=None, obs_index=None, object_id_column=None, object_id_categories=None, position_names=None)[source]¶
Bases:
HeaderAnnData
.h5adheader metadata.Zarr Vectors stores numeric per-vertex arrays, so three kinds of AnnData information cannot survive in the arrays alone and live here instead:
Names.
obscolumns and genes become attribute arrays whose names are sanitised for Zarr paths, so the original labels are kept in the*_names/*_attrsparallel lists.Categories. Categorical/string
obscolumns are stored as integer codes, dictionary-encoded on the array itself so a reader sees labels;categoriesmaps a column to its level labels too, under its original name, so export can rebuild thepandas.Categorical.Order and identity. Zarr Vectors orders vertices by spatial chunk, not by original row, so
row_attrnames the attribute holding each cell’s source row index andobs_index(when small enough to inline) holds the original barcodes.
- Parameters:
- __init__(format_name='h5ad', spatial_key='spatial', spatial_ndim=3, spatial_columns=<factory>, n_obs=0, n_vars=0, obs_names=<factory>, obs_attrs=<factory>, gene_names=<factory>, gene_attrs=<factory>, layer=None, categories=<factory>, dtypes=<factory>, row_attr=None, obs_index=None, object_id_column=None, object_id_categories=None, position_names=None)¶
- class zarr_vectors_tools.headers.formats.Header(format_name)[source]¶
Bases:
objectBase class for format-specific headers.
- Parameters:
format_name (str)
- class zarr_vectors_tools.headers.formats.LASHeader(format_name='las', version='1.4', point_format=0, point_count=0, scale=(0.001, 0.001, 0.001), offset=(0.0, 0.0, 0.0), min_bound=(0.0, 0.0, 0.0), max_bound=(0.0, 0.0, 0.0), crs_wkt='')[source]¶
Bases:
HeaderLAS/LAZ point cloud file header.
- Parameters:
- __init__(format_name='las', version='1.4', point_format=0, point_count=0, scale=(0.001, 0.001, 0.001), offset=(0.0, 0.0, 0.0), min_bound=(0.0, 0.0, 0.0), max_bound=(0.0, 0.0, 0.0), crs_wkt='')¶
- class zarr_vectors_tools.headers.formats.NIfTIHeader(format_name='nifti', affine=None, dimensions=(1, 1, 1), voxel_sizes=(1.0, 1.0, 1.0), qform_code=0, sform_code=0, xyzt_units=0)[source]¶
Bases:
HeaderNIfTI spatial reference header.
Stores the affine transform, voxel sizes, and dimension info. Used by any geometry type with a known coordinate system.
- Parameters:
- __init__(format_name='nifti', affine=None, dimensions=(1, 1, 1), voxel_sizes=(1.0, 1.0, 1.0), qform_code=0, sform_code=0, xyzt_units=0)¶
- class zarr_vectors_tools.headers.formats.OBJHeader(format_name='obj', mtllib='', object_names=<factory>, group_names=<factory>)[source]¶
Bases:
HeaderWavefront OBJ file header metadata.
- __init__(format_name='obj', mtllib='', object_names=<factory>, group_names=<factory>)¶
- class zarr_vectors_tools.headers.formats.SWCHeader(format_name='swc', comment_lines=<factory>, coordinate_space='', scaling=(1.0, 1.0, 1.0))[source]¶
Bases:
HeaderSWC file header (comment lines and metadata).
- Parameters:
- __init__(format_name='swc', comment_lines=<factory>, coordinate_space='', scaling=(1.0, 1.0, 1.0))¶
- class zarr_vectors_tools.headers.formats.SurfaceHeader(format_name='surface', source='', space='unknown', geometry='', hemispheres=<factory>, alternates=<factory>, scalars=<factory>, label_tables=<factory>, key_attribute='zv_join_key', c_ras=None, extra=<factory>)[source]¶
Bases:
HeaderWhat a cortical surface store needs that its arrays cannot say.
A surface store holds one mesh object per hemisphere. Four things about it live here rather than in the arrays:
Which hemisphere is which object, and how many vertices the source mesh had. CIFTI data is indexed by surface vertex, and a 32k map is meaningless on a 164k surface, so the count is what lets an attach refuse a mismatch instead of writing garbage.
Which surface is the geometry and which ride along as coordinate attributes (
coords_white,coords_inflated…). All share one topology; only one can be chunked.The coordinate space the geometry is in. FreeSurfer surfaces are in surface RAS, offset from scanner RAS by
c_ras; whether that shift was applied is the difference between a surface that overlays a tractogram and one that sits beside it.Label tables. Parcellations are stored as integer codes; the names and colours that make them a parcellation are kept per attribute.
- Parameters:
- __init__(format_name='surface', source='', space='unknown', geometry='', hemispheres=<factory>, alternates=<factory>, scalars=<factory>, label_tables=<factory>, key_attribute='zv_join_key', c_ras=None, extra=<factory>)¶
- hemispheres: list[dict[str, Any]]¶
{object_id, hemisphere, structure, n_vertices, n_faces}.object_idis the store’s;hemisphereis"left"/"right".- Type:
One entry per object
- label_tables: dict[str, dict[str, dict[str, Any]]]¶
{attribute: {code: {"name": str, "rgba": [r, g, b, a]}}}. Codes are strings because JSON object keys must be.
- class zarr_vectors_tools.headers.formats.TRKHeader(format_name='trk', voxel_size=(1.0, 1.0, 1.0), dimensions=(1, 1, 1), vox_to_ras=None, voxel_order='LAS', n_scalars=0, scalar_names=<factory>, n_properties=0, property_names=<factory>, n_count=0, origin=None, version=None, space=None, n_count_mismatch=None, extra=<factory>)[source]¶
Bases:
HeaderTrackVis .trk file header.
Captures the vox_to_ras affine, voxel sizes, dimensions, voxel order, and scalar/property names needed for round-trip.
- Parameters:
- __init__(format_name='trk', voxel_size=(1.0, 1.0, 1.0), dimensions=(1, 1, 1), vox_to_ras=None, voxel_order='LAS', n_scalars=0, scalar_names=<factory>, n_properties=0, property_names=<factory>, n_count=0, origin=None, version=None, space=None, n_count_mismatch=None, extra=<factory>)¶
- extra: dict[str, Any]¶
Any key a producer wrote that this class does not name. Carried so a newer writer’s field survives a round-trip through an older reader instead of being dropped on the floor.
- n_count_mismatch: list[int] | None = None¶
[declared, actual]when the header’s streamline count disagreed with what the file holds.
- space: str | None = None¶
Which space the STORED coordinates are in –
"voxmm"(as the file had them) or"rasmm"(registered at read time). Without it a later merge or export cannot tell whether the affine still has to be applied, which is the difference between two tractograms overlaying and one of them sitting in the wrong place entirely.
- class zarr_vectors_tools.headers.formats.TRXHeader(format_name='trx', voxel_to_rasmm=None, dimensions=(1, 1, 1), dpv_names=<factory>, dps_names=<factory>, dpg_names=<factory>, extra=<factory>)[source]¶
Bases:
HeaderWhat a TRX file says about the image its streamlines belong to.
TRX positions are always RAS millimetres, so unlike TRK there is no stored space to undo. What an export needs back is the reference image – its voxel-to-RAS affine and grid dimensions – because tools that load a TRX against a volume check the two agree.
- Parameters:
- __init__(format_name='trx', voxel_to_rasmm=None, dimensions=(1, 1, 1), dpv_names=<factory>, dps_names=<factory>, dpg_names=<factory>, extra=<factory>)¶
- dpv_names: list[str]¶
Names of the per-vertex (dpv), per-streamline (dps) and per-group (dpg) arrays the file had, as ingested.