"""Virtual zarr-vectors stores: a standard file read as a zarr-vectors store
on demand, without converting it.
The file is read once and binned into spatial cells; every key of the store
(``zarr.json``, ``0/vertices/c/1/0/2``, …) is then made when asked. The
layout matches, chunk for chunk, the one the browser makes from the same
file (ngplatform's Zarr Vectors plugin reads local tractograms this way),
and is a valid format 0.10.0 store (``zarr_vectors.validate(level=3)``).
Tractograms (TrackVis ``.trk``, MRtrix ``.tck``, ``.trx``), meshes
(``.obj`` by object, ``.stl``, ``.ply``, GIFTI ``.gii`` and FreeSurfer
surfaces such as ``lh.pial``, anatomical ones in scanner RAS), SWC neurons
(skeletons, one object per tree; ``folder/@all.swc`` reads every SWC file in
a folder as one store) and point tables (``.csv``, ``.tsv``, ``.xyz``)::
from zarr_vectors_tools.virtual import open_virtual
store = open_virtual("tracts.trk")
store.get("zarr.json"), store.list("0/object_attributes/")
``zvtools virtual serve tracts.trk`` serves them over HTTP to any
Neuroglancer with the zarr-vectors data source (ranges, CORS and folder
listings included).
"""
from __future__ import annotations
from pathlib import Path
from .meshes import MeshStore, is_mesh_file
from .points import (
CellStore,
is_point_file,
open_point_file,
parse_point_table,
parse_swc,
parse_swc_collection,
point_store,
skeleton_store,
)
from .streamlines import StreamlineStore, cell_size, fragment_index
from .tractograms import open_tck, open_tractogram, open_trk, open_trx
VIRTUAL_SUFFIXES = (
".trk",
".tck",
".trx",
".obj",
".stl",
".ply",
".gii",
".swc",
".csv",
".tsv",
".xyz",
)
[docs]
def open_virtual(path: str | Path) -> StreamlineStore | MeshStore | CellStore:
"""A file as a virtual zarr-vectors store, read once now."""
if is_mesh_file(path):
return MeshStore(path)
if is_point_file(path):
return open_point_file(path)
return StreamlineStore(open_tractogram(path))
__all__ = [
"CellStore",
"MeshStore",
"StreamlineStore",
"VIRTUAL_SUFFIXES",
"cell_size",
"fragment_index",
"open_tck",
"open_tractogram",
"open_trk",
"open_trx",
"open_point_file",
"open_virtual",
"parse_point_table",
"parse_swc",
"parse_swc_collection",
"point_store",
"skeleton_store",
]