Zarr Vectors and TRX¶
How Zarr Vectors streamline stores differ from TRX files, and when to use each.
What TRX is for¶
TRX is a tractography exchange
format, with a reference implementation in trx-python; DIPY and scilpy
also read and write it. A TRX file is a ZIP archive (.trx) or a plain
directory with the same contents: a header.json and one file per array.
Each array file is raw little-endian, C-order binary with no header; its
name gives the array’s name, optional second dimension and dtype, as in
positions.3.float16 or offsets.uint64. Because the arrays have no
header, a program can memory-map them and stream every streamline in
order. That works inside a ZIP only when it is stored uncompressed; a
deflated archive must be extracted first.
header.json holds exactly VOXEL_TO_RASMM, DIMENSIONS,
NB_STREAMLINES and NB_VERTICES. Positions are already in RAS
millimetres; the affine is not applied to them, and only relates the
tractogram back to its reference image.
A Zarr Vectors store chunks vertices by position. A program can read the streamlines that pass through a region, one streamline by ID, or a coarser resolution level, without reading the rest.
Comparison¶
TRX |
Zarr Vectors |
|
|---|---|---|
Container |
ZIP archive or directory |
Zarr v3 hierarchy |
Vertices |
One concatenated |
Per-chunk cells, sorted into fragments |
Streamline boundaries |
|
|
Spatial index |
None |
Chunk grid and fragment index |
Per-vertex data |
|
|
Per-streamline data |
|
|
Groups |
|
One row of the |
Per-group data |
|
One |
Reference image |
|
Kept in a |
Positions |
RAS millimetres |
Stored as given; axes record millimetres |
Resolution levels |
One |
Several |
When to use which¶
Use TRX for whole-file processing on local storage. Use Zarr Vectors for spatial queries and hosting in an object store.
zarr-vectors-tools converts both ways (extra zarr-vectors-tools[trx]):
zvtools convert bundles.trx bundles.zarrvectors --chunk-shape 20,20,20
zvtools convert bundles.zarrvectors cst.trx --group-id 0
Ingest carries dpv, dps, groups with their names, dpg and the TRX
header across, and export writes them back. It is not dtype-exact:
float16 positions and attributes widen to float32, bit arrays become
uint8, and dpg values are stored as float32. Integer arrays keep their
dtype. A multi-dimensional object_attributes array is flattened to 2-D
on export. Export writes one resolution level; the chunk layout and other
levels are not part of TRX. See the zarr-vectors-tools
streamlines page.