Skip to content

feat: read uncompressed .nii inputs, not only .nii.gz - #79

Merged
Hendrik-code merged 5 commits into
mainfrom
feat/accept-plain-nii
Oct 19, 2026
Merged

Hendrik-code merged 5 commits into
mainfrom
feat/accept-plain-nii

Conversation

@Hendrik-code

Copy link
Copy Markdown
Owner

Stacked on #77 (fix/clearer-cli-messages), whose --input validation this builds on. The diff
shown here is just the incremental change; merge #77 first and the base switches to main automatically.

Problem

Plain .nii is what dcm2niix writes without -z y, and what a good share of public datasets ship.
SPINEPS could not read it at all:

  • the CLI appended .nii.gz to whatever it was given, turning scan.nii into scan.nii.nii.gz,
  • BIDS_FILE.file is keyed by extension, so the three img_ref.file["nii.gz"] lookups raised KeyError
    for a .nii input, and
  • process_dataset's query filtered on filter_filetype("nii.gz"), so .nii scans were invisible to
    dataset mode.

A user with a .nii dataset had to gzip all of it first.

Fix

  • A shared input_image_path(img_ref) in seg_utils resolves nii.gz or nii, used at all three
    lookups, with NIFTI_FILE_TYPES as the single source of truth.
  • process_dataset passes both extensions to filter_filetype.
  • --input and spineps.segment() accept both; the extension is still appended when --input is given
    without one. A genuinely unreadable extension (scan.mha) still gets the clear error from fix: make CLI messages name flags that exist and causes users can act on #77, and
    that PR's test is retargeted accordingly.
  • Outputs are unchanged: always .nii.gz, since get_changed_path(file_type="nii.gz") sets them.

Tests

unit_tests/test_plain_nii_input.py: input_image_path on both extensions, the compatibility check on a
.nii, a full segment_image run on sub-01_T2w.nii that asserts all four outputs land on disk as
.nii.gz, and run_sample not rejecting a .nii. The file does not even import on the base branch.

Full suite: 233 passed, ruff clean.

🤖 Generated with Claude Code

Hendrik-code and others added 3 commits October 5, 2026 08:50
Plain `.nii` is what dcm2niix writes without `-z y` and what a good share of public
datasets ship, and SPINEPS could not read it: the CLI appended `.nii.gz` to whatever it
was given, `BIDS_FILE.file` is keyed by extension so the three `file["nii.gz"]` lookups
raised KeyError, and the dataset query filtered on that single extension. Users had to
gzip their whole dataset first.

A shared `input_image_path()` resolves either extension, the dataset query accepts both,
and `--input` / `spineps.segment()` take both. Outputs are still always written as
`.nii.gz`; a genuinely unreadable extension still gets the clear error.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Keeps this change off the paragraph the non-BIDS-filename PR also adds to.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
One source of truth, and it keeps the top of entrypoint.py free so this does not overlap
the CT-default change that also adds code there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Hendrik-code

Copy link
Copy Markdown
Owner Author

No CI here on purpose: the tests workflow only triggers for pull requests whose base is main, and this one targets fix/clearer-cli-messages (#77). GitHub retargets it to main when #77 merges, and CI runs then. Verified locally in the meantime: 233 tests pass on this branch, and 284 pass in a tree with all ten PRs of this round merged together.

Base automatically changed from fix/clearer-cli-messages to main October 19, 2026 11:47
@Hendrik-code
Hendrik-code merged commit 201f35f into main Oct 19, 2026
10 checks passed
@Hendrik-code
Hendrik-code deleted the feat/accept-plain-nii branch October 19, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant