Repository navigation
feat: sanitize is a linter; tfmgr add resumes and never changes data - #14
Conversation
tfmanager/images.py inspects a NIfTI image (TF702, TF703, TF707-TF710) and applies the fixes of its problems. A safe fix keeps the values and the world coordinates of every voxel (reorient to RAS, units to mm, labels to the smallest unsigned integer type, integer-valued images to int16); an unsafe one changes values or moves the image (rescale probabilities, deoblique, qform := sform, float images to int16 with slope and intercept). Issues carry `autofix`, shown as [fix] / [fix-unsafe]. New rules: TF707 not-ras, TF708 oblique, TF709 storage-dtype, TF710 image-units (all info in legacy mode) and TF711 unreadable-image, which replaces a crash on empty or truncated images. TF505 suggests a LICENSE header only for a valid SPDX expression. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `tfmgr sanitize` lists the image problems (--check, the default), applies the safe fixes (--fix) or all of them (--fix-unsafe), and updates the res blocks of template_description.json when every image of a resolution moved alike. Annexed images are replaced by regular files. The silent int16 cast, probseg rescaling and --normalize are gone, and the swapped positional arguments with them. - `tfmgr add` (tfmanager/add.py) runs copy, validate, save, gin, github and pull-request steps, recorded in <workdir>/state.json (default: the user cache directory) so a failed run resumes; a changed source restarts from the copy. The copy is byte for byte (--fix/--fix-unsafe apply sanitize to it), strict content validation stops it before any upload, commands and DataLad calls stop on failure, siblings are reconfigured (never replaced), gh replaces hub, the intake file is tpl-<ID>.toml, --nprocs is honoured, and the license is an SPDX expression written as the LICENSE header. Prompted answers are kept for the next run. - utils.copy_template is removed; io.run_command takes argument lists and raises on failure. platformdirs joins the [add] extra. The ruff config uses a table for per-file ignores (old pips cannot parse the inline one). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f89edb86ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def lint(root: str | os.PathLike) -> list[Issue]: | ||
| """The image problems of the template at ``root`` (errors and warnings).""" | ||
| issues = run_checks(_context(Path(root))) | ||
| return [i for i in issues if i.code.startswith(PREFIX) and i.severity != 'info'] |
There was a problem hiding this comment.
Fail when sanitize cannot load image dependencies
When nibabel or numpy is unavailable, the content validator reports TF700 as informational, and this filter removes it. tfmgr sanitize then reports no problems and exits successfully without inspecting images; the CLI's ImportError handler does not run because the validator swallowed the error. Preserve the missing-dependency report or fail the command.
Useful? React with 👍 / 👎.
| 'TF709', f'Labels stored as {dtype} (fix: {target}).', 'safe', 'labels' | ||
| ) | ||
| ) | ||
| elif anatomical and np.issubdtype(dtype, np.floating): |
There was a problem hiding this comment.
Check integer anatomical images for TF709
When an anatomical NIfTI is stored as int32 or int64, this branch only handles floating-point storage, so it emits no TF709 even when all values fit in int16. As a result, sanitize --fix and tfmgr add --fix leave these images in wider storage despite the advertised rule. Check integer storage too and offer an exact cast when the values fit.
Useful? React with 👍 / 👎.
From the review of #14: - TF711: nibabel reads lazily, so an image whose voxels no rule reads (MD, boldref...) passed with a truncated payload. Every NIfTI is now streamed (decompressed in chunks, not held in memory) and its length checked against the header. - tfmgr add fingerprints the source by content: an edit that keeps size and modification time (cp -p) restarts from the copy. - tfmgr sanitize exits 2, and tfmgr add stops, when nibabel is missing, instead of reporting a clean template (TF700 was filtered out as info). - TF709 also flags int32/int64 anatomical images whose values fit int16 (safe fix). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
tfmgr sanitizebecomes a linter over the image rules, andtfmgr addbecomes resumable and never changes the data it is given.When a fix moves the grid of every image of a resolution,
sanitizeupdates thatresblock (or the cohort override) of template_description.json, so the fix does not introduce TF701.Evidence
tfmgr sanitizecalledcopy_template(dir, normalize, force_dtype, deoblique)againstcopy_template(path, normalize, deoblique, force_dtype), so the two flags were swapped. Its deoblique multiplied a 3×3 by a 4×4 matrix, and an empty image crashedvalidate --level content.sanitizekeeps res blocks in step, leaves a block alone when its images disagree, and never writes into annex objects;addwith DataLad, git and gh mocked: it resumes after a failed GIN push without repeating any step, does not duplicate an open PR, restarts from the copy when the source changes, and stops before uploading when validation finds errors;sanitizeexits 2 without nibabel instead of reporting a clean template.tfmgr sanitize --checkon the local MNI152NLin2009cAsym data turns up real problems for WP5:Merge Danger
Door: two-way
Blast Radius: contributors
tfmgr sanitizewithout flags no longer writes anything, and--normalize,--force-dtypeand--deobliqueare gone.tfmgr addneedsghinstead ofhub, refuses templates that fail strict validation, and leaves its work directory in the cache until it is removed.