The zvtools command line¶
Installing zarr-vectors-tools puts a zvtools executable on your path.
It covers the common end-to-end jobs — convert a file, build a pyramid,
check conformance, inspect a store — without writing any Python.
zvtools --version
zvtools {convert,pyramid,validate,info} ...
It is also runnable as a module, which is useful when the script shim is
not on PATH:
python -m zarr_vectors_tools convert cells.csv out.zarrvectors --chunk-shape 100,100,100
Exit codes¶
Code |
Meaning |
|---|---|
|
success |
|
an error, printed as |
|
interrupted with Ctrl-C (prints |
Ingest, coarsening and validation errors are funnelled into that single clean one-line form rather than a traceback.
zvtools convert¶
zvtools convert INPUT OUTPUT [options]
Moves data between a file and a store, in whichever direction INPUT
implies:
|
|
What happens |
|---|---|---|
a file |
a store path |
ingest, optionally building coarser levels in the same run |
a store |
a file |
export, reading the level you name |
A directory carrying a zarr.json is a store; anything else is a file to
read. That is the same test --overwrite uses, so the two cannot disagree
about what a store is.
# In.
zvtools convert tracts.trk tracts.zarrvectors --num-chunks 5000
# Out, from the coarsest level, one bundle only.
zvtools convert tracts.zarrvectors cst.trk --level 2 --group-id 4
Format selection¶
--format defaults to auto, which resolves from the file extension — of
INPUT when ingesting, of OUTPUT when exporting:
|
Extensions |
Ingest function |
Geometry |
Extra |
|---|---|---|---|---|
|
|
|
streamlines |
|
|
|
|
streamlines |
|
|
|
|
streamlines |
|
|
|
|
skeleton |
— |
|
|
|
mesh |
— |
|
|
|
mesh |
— |
|
|
|
points |
|
|
|
|
points |
|
|
|
|
points |
— |
|
(none) |
|
lines |
— |
|
(none) |
|
graph |
|
|
|
|
graph |
|
|
|
|
mesh |
|
|
a subject directory |
|
mesh |
|
|
a URL, or a directory with an |
|
skeleton or mesh |
|
Note
lines and edgelist register no extensions, because a .csv file
auto-detects to csv (points). Both therefore need an explicit
--format:
zvtools convert segments.csv out.zarrvectors --format lines --chunk-shape 50,50,50
zvtools convert edges.csv out.zarrvectors --format edgelist --nodes nodes.csv \
--chunk-shape 50,50,50
If an extension does not resolve, the error names every valid --format
value. If the format’s extra is missing, the error carries the exact
pip install command to fix it.
Options¶
Flag |
Type |
Default |
Notes |
|---|---|---|---|
|
choice |
|
see the table above |
|
shape |
— |
required for every format except |
|
int or triple |
— |
|
|
shape |
— |
optional intra-chunk sub-binning |
|
str |
|
stored position dtype |
|
flag |
off |
replace an existing output store |
|
choice |
|
|
|
int |
— |
parallel worker processes |
|
choice |
|
|
|
int |
— |
|
|
flag |
off |
streamlines: store per-object length |
|
flag |
off |
streamlines: store per-object endpoints |
|
path |
— |
required for |
|
int |
— |
points: k for the kNN-distance enrichment (needs |
|
str |
|
|
|
|
both |
|
|
|
|
|
|
str, repeatable |
present defaults |
|
|
ints |
— |
|
|
ints |
|
|
|
str |
layer root |
|
|
int, repeatable |
every ID |
|
|
int |
|
|
|
int |
|
|
Plus every pyramid option below.
Precomputed skeleton and mesh layers¶
A Neuroglancer precomputed layer is a directory or a bucket prefix, not a
file. auto recognises a URL (gs://, s3://, https://, file://,
with or without precomputed://) and a local directory holding an info
file. The layer’s info then picks the ingester:
Layer is |
Level-0 chunks |
|
|---|---|---|
skeletons with a |
the index’s own, one per |
leave out |
skeletons with no spatial index |
a grid you choose |
required, in nm |
meshes, legacy or multi-resolution |
a grid you choose |
required, in nm |
Point it at the skeleton or mesh directory itself. A segmentation layer’s
info is refused, with the directories it names.
A mesh layer is read one object per segment, with fragment seams welded,
and its pyramid is built after the ingest, as for OBJ input. --anchor,
--counts, --frags-dir, --drop-interior-below, --compressor,
--dtype and --bin-shape are refused for it. See
Meshes.
For a skeleton layer:
Without --anchor, every .frags file in the layer is listed and
ingested. On a production EM layer that is a large job; pass --anchor
and --counts to take a block. The pyramid is built inside the ingest:
--coarsen gives each level’s decimation stride, --chunk-scale
defaults to 2 per level, and --sparsity-strategy random becomes
length, as it does for zvtools pyramid on a skeleton store.
--compressor, --dtype and --bin-shape are refused. See
Skeletons in EM.
Export options¶
These apply when INPUT is a store. Every one of them is refused by name
if it does not apply to the format being written, rather than ignored.
Flag |
Type |
Default |
Notes |
|---|---|---|---|
|
int |
|
resolution level to export; |
|
int, repeatable |
all |
export only these objects |
|
int, repeatable |
all |
streamlines: export only these bundles |
|
floats |
— |
export only what falls in the box |
|
int, repeatable |
— |
one |
|
str, repeatable |
|
per-vertex attributes to include |
|
str, repeatable |
every numeric one |
|
|
str, repeatable |
all |
|
|
str |
— |
|
|
int, repeatable |
all |
|
|
str |
from the store, else nm |
|
|
str |
|
|
|
Extensions |
Export function |
Reads |
Extra |
|---|---|---|---|---|
|
|
|
streamlines |
|
|
|
|
streamlines |
|
|
|
|
skeleton |
— |
|
|
|
mesh |
— |
|
|
|
points |
|
|
|
|
points |
— |
|
|
|
points |
|
|
a directory: |
|
surface |
|
|
a URL, or a directory with |
|
skeleton, graph or mesh |
|
TRK and TRX exports write back the store’s attributes, TRX its named groups, and both the reference image from the store’s header. See Export → streamlines.
More formats can be ingested than exported: las, stl, lines,
edgelist, graphml and table have no writer, and asking for one names
the formats that do.
Warning
--overwrite deliberately refuses to remove a directory that does not
contain a zarr.json or .zattrs. It will not let you point it at your
home directory and delete it. Do not work around this.
Examples¶
# MERFISH transcripts, 100 µm chunks, with per-cell transcript counts.
zvtools convert transcripts.csv cells.zarrvectors --chunk-shape 100,100,100
# Tractogram: ~5000 chunks, 12 dask workers, compressed, with a 2-level pyramid.
zvtools convert tracts.trk tracts.zarrvectors \
--num-chunks 5000 --workers 12 --workers-backend dask \
--compressor zstd --coarsen 8,8 --sparsity 2,4
# Back out again: the whole store as CSV, with one attribute.
zvtools convert cells.zarrvectors cells.csv --attribute cell_type
# Neuron morphology from SWC.
zvtools convert neuron.swc neuron.zarrvectors --chunk-shape 50,50,50
# A FreeSurfer subject, then CIFTI myelin maps onto it.
zvtools convert subjects/bert bert.zarrvectors --chunk-shape 20,20,20
zvtools attach bert.zarrvectors bert.MyelinMap_BC.164k_fs_LR.dscalar.nii
# A FlyWire cutout from the spatial index, with a three-level pyramid.
zvtools convert gs://flywire_v141_m783/skeletons_mip_1 flywire_cutout.zv \
--anchor 17398,10448,3088 --counts 8,8,4 \
--coarsen 8,8,8 --sparsity 1,1,4 --drop-interior-below 3 --workers 8
# Mouselight has no spatial index, so choose a grid: 1 mm chunks.
zvtools convert precomputed://gs://allen_neuroglancer_ccf/Mouselight mouselight.zv \
--chunk-shape 1000000,1000000,1000000 --coarsen 8,8 --sparsity 1,4
See Cortical surfaces and Skeletons in EM.
zvtools pyramid¶
zvtools pyramid STORE [options]
Build coarser resolution levels on an existing store. Geometry routing
is automatic — the coarsener is chosen from the store’s
links_convention and geometry_types, so you do not select it by hand.
See Strategies.
Both --coarsen and --sparsity are required here.
Flag |
Type |
Default |
Notes |
|---|---|---|---|
|
choice |
(store default) |
|
|
int |
(store default, 1) |
|
|
choice |
|
match what level 0 was written with |
|
int |
— |
parallel worker processes |
|
choice |
|
|
Plus the pyramid options below.
zvtools pyramid tracts.zarrvectors \
--coarsen 8,8,8 --sparsity 2,2,2 \
--sparsity-strategy length --compressor zstd --workers 8
Pyramid options¶
These appear on both convert and pyramid.
Flag |
Type |
Default |
Notes |
|---|---|---|---|
|
float list |
— |
per-level vertex coarsen factor, or decimation stride |
|
float list |
— |
per-level object-drop divisor ( |
|
int list |
— |
per-level chunk-size multiplier |
|
choice |
|
|
|
choice |
|
|
|
float list |
derived |
streamlines in |
--coarsen and --sparsity must have equal length, one entry per
coarser level; a mismatch exits with an error naming both counts. Giving
neither means no pyramid is built.
Note
Passing --sparsity-strategy length on a streamline format
auto-enables --compute-length, since the strategy needs the lengths it
ranks by. The CLI prints a note: when it does this for you.
The two axes are explained in Coarsening versus sparsity.
Setting the simplification as a distance¶
By default an rdp level’s tolerance is derived from its bin, half the
smallest bin edge, so it grows with --coarsen. --rdp-tolerance sets
it directly instead, in the store’s own coordinate units — millimetres
for a tractogram in RAS mm:
# Level 1 may move a tract by at most 0.5 mm from level 0, level 2 by at
# most 1 mm from level 1, level 3 by at most 2 mm from level 2.
zvtools pyramid tracts.zarrvectors \
--coarsen 2,2,2 --sparsity 1,2,4 --rdp-tolerance 0.5,1,2
Each tolerance bounds the deviation from the level below, so the
deviation from level 0 is at most their running sum. --coarsen still
sets each level’s bin (its scale); with --rdp-tolerance it no longer
decides how much is simplified.
The tolerance each level was built with is recorded on the level, and a pyramid refresh rebuilds it at the same value; see Strategies.
--rdp-tolerance is refused, before anything is ingested or written:
without
--coarsen, or with a different number of entries;with
--coarsen-mode decimate, which has no tolerance;for a value that is not a distance above zero;
on
convertfor any input buttrk,trxandtck, and onpyramidfor any store not coarsened by the streamline coarsener (points, meshes, graphs, skeletons);when
convertis exporting.
zvtools validate¶
zvtools validate STORE [--level N]
Run core conformance validation. --level is the conformance level 1–5
and defaults to 3. Prints errors, messages and issues; returns 0 when
the store conforms and 1 otherwise, so it drops straight into CI.
zvtools validate tracts.zarrvectors --level 4
zvtools info¶
zvtools info STORE
Print a store’s zv_version, geometry_types, links_convention,
chunk_shape, bounds, resolution levels, cross-level depth and
storage, and format capabilities.
This is the fastest way to answer “what coarsener will zvtools pyramid
pick?” — the links_convention and geometry_types lines are exactly
the inputs to that decision.
zvtools run¶
zvtools run RECIPE [--dry-run] [--force] [--from N]
Runs a recipe: the steps that take raw files to a validated, sharded,
multi-level store, in one command. Each step is a subcommand (convert,
pyramid, attach, merge, split, validate, info, shard, bundles) with
its options written as a mapping:
name: tractography
steps:
- convert:
input: data/sub-01_tracts.trk
output: out/sub-01_tracts.zarrvectors
num_chunks: 5000
coarsen: [8, 8]
sparsity: [1, 4]
- validate: {store: out/sub-01_tracts.zarrvectors}
- shard: {store: out/sub-01_tracts.zarrvectors, shape: 8}
Keys are the subcommand’s long options with underscores for dashes (
chunk_shapeis--chunk-shape), plus its positional arguments by name (input,output,store,target,sources).Lists become comma-separated values for options that take a list (
coarsen: [8, 8]is--coarsen 8,8), and repeated flags for options that repeat (attribute: [fa, md]is--attribute fa --attribute md).trueswitches a flag on.Paths resolve against the recipe’s directory, or
workdir:when the recipe sets one. URLs are left alone.Checked the same way. Each step becomes the argument list its command already parses, so an option it does not have is refused, naming the step.
Progress is kept in <recipe>.run.json beside the recipe. A rerun skips a
step that finished, has the same options, and whose output still exists.
Once a step reruns, every step after it reruns too. The run stops at the
first step that fails, and running again resumes there. --from N reruns
from step N, --force reruns everything, and --dry-run prints and
checks each step’s command without running it.
Recipes can be .yaml (needs the recipes extra), .toml or .json.
examples/recipes/ has one per track: tractography, EM skeletons,
cortical surfaces, and cells. The test suite dry-runs each one, so they
stay valid.
The other CLI¶
precomputed_skeletons also keeps its own argparse entry point, which
predates zvtools convert and exposes --no-align:
python -m zarr_vectors_tools.convert.ingest.precomputed_skeletons \
SOURCE OUT_STORE --anchor X Y Z [--counts ...] [--frags-dir ...] \
[--strides ...] [--chunk-scales ...] [--sparsity ...] \
[--workers N] [--drop-interior-below N]
See Skeletons in EM.
See also¶
Quickstart — the same jobs from Python.
Ingest workflows — per-format detail.
Parallel workflows —
--workersand--workers-backend.Choosing a compressor —
--compressor.Coarsening versus sparsity —
--coarsenand--sparsity.