This tool eases the processes of adding new templates and updating existing one in the TemplateFlow Archive.
tfmgr validate checks templates against the TemplateFlow rule set
(tfmanager/schema/):
pip install tfmanager tfmgr validate tpl-MyTemplate # a template directory tfmgr validate path/to/templateflow # every template of an Archive checkout tfmgr validate --format json -o report.json tpl-MyTemplate
Templates older than TemplateFlowVersion 2.0.0 are checked in legacy mode, where naming
problems are warnings (--mode strict or --mode legacy override it). Image headers
and values are only checked with --level content, which needs tfmanager[content]
and the images' data. The command exits with 1 when there are errors, and 2 when it
could not run.
Some files are generated from the metadata, and tfmgr validate reports them when they
are missing or out of date. tfmgr generate writes them:
tfmgr generate all tpl-MyTemplate # atlas descriptions and cohorts table tfmgr generate all path/to/templateflow # templates.tsv and dataset_description.json tfmgr generate all tpl-MyTemplate --check # list what would change; change nothing
In a template, atlases writes an atlas-<label>_description.json for each row of
tpl-<label>_atlases.tsv, and cohorts writes tpl-<label>_cohorts.tsv (and its
sidecar) from the cohort block of template_description.json. At the root of the
Archive, templates writes templates.tsv and dataset writes dataset_description.json,
whose TemplateFlowVersion becomes 2.0.0 once every template is at 2.0.0. Files no
longer generated are deleted. With --check, the command exits with 1 when there are
files to write.
tfmgr sanitize works like a linter on the images of a template (rules TF701 to
TF711; needs tfmanager[content]):
tfmgr sanitize tpl-MyTemplate # --check (the default): list the problems tfmgr sanitize --fix tpl-MyTemplate # apply the safe fixes tfmgr sanitize --fix-unsafe tpl-MyTemplate # apply all of them
Safe fixes keep the values and the world coordinates of every voxel: reorienting to RAS,
setting unset units to mm, storing labels as the smallest unsigned integer type, and
integer-valued images as int16. Unsafe fixes change values or move the image: rescaling
probabilities into [0, 1], removing the rotation of oblique images, setting the qform to
the sform when they disagree, and storing floating-point images as int16 with a slope and
an intercept. When a fix moves the grid of every image of a resolution, the res block
of template_description.json is updated to match. Annexed images are replaced by regular
files (datalad save annexes them again).
Adding a template needs DataLad, the GitHub CLI (gh) and the TemplateFlow client:
pip install tfmanager[add]:
tfmgr add MyTemplate --path tpl-MyTemplate
tfmgr add asks for the metadata that template_description.json misses (with an SPDX
license identifier), copies the template into a DataLad dataset without changing it
(--fix and --fix-unsafe apply tfmgr sanitize fixes to the copies), writes the
generated files (as tfmgr generate all), and checks it with tfmgr validate --mode strict --level content: errors stop it before anything
is uploaded. The data then go to GIN, the dataset to GitHub, and a pull request proposes
the template to the Archive. Each step is recorded in a work directory (by default in
the user's cache directory; --workdir sets another one), so a run that fails resumes
where it stopped; --restart starts again.