Repository navigation
BF: Resolve slice starts against axis length in slice_affine - #1534
Conversation
|
@wterrr The three follow-on pieces are up as wterrr#1 against this branch, opened on 27 July: the doctest update, an independent affine assertion in Flagging them here because two of them affect what this PR leaves behind:
The third is one line asserting Whichever is least work for you. If you would rather not take a PR into your branch, I can open the doctest and No rush from my side. I just did not want the doctest to slip through quietly. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1534 +/- ##
==========================================
- Coverage 95.45% 95.45% -0.01%
==========================================
Files 209 209
Lines 30089 30113 +24
Branches 5183 5187 +4
==========================================
+ Hits 28722 28744 +22
- Misses 937 938 +1
- Partials 430 431 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
`SpatialFirstSlicer.slice_affine` copied `subslicer.start` straight into the affine translation. Two cases were therefore wrong: * A negative start (``img.slicer[-2:]``) put the negative value into the affine instead of the equivalent positive index. * A negative step with an implicit start (``img.slicer[::-1]``) used 0 as the origin, but the first voxel of the result is the *last* voxel of the axis. In both cases the returned data was correct while the affine was not, so the image was silently shifted in RAS+ space. ``img.slicer[-2:]`` and ``img.slicer[8:]`` select the same voxels but produced affines 20 mm apart. `nib-roi` is affected too, since it accepts negative starts and ``:-1`` steps and calls `slice_affine` directly. Resolve each spatial subslicer with `slice.indices()` so the transform is built from the concrete start and step that `dataobj[slicer]` uses. Closes nipygh-1533. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
c2ac2ce to
637dc0b
Compare
Documentation build overview
50 files changed ·
|
|
Apologies for taking so long to get around to this. @Arthur031221 Do you by chance still have that repository around locally? I could cherry-pick your fixes before merge. |
|
@effigies I don't have a local checkout anymore, but the commit is still on GitHub as the single commit of wterrr#1 (closed unmerged): I ran exactly that on this PR's current head (42a0585) and it applies cleanly. It touches three files: the With it applied, |
Three things the fix needs alongside it. The flip example in doc/source/nibabel_images.rst prints an X translation of 117.86, which is the value from before the fix. With the fix in place that doctest fails, and the job that would catch it is continue-on-error, so it would land quietly. test_nib_roi asserted np.allclose(in_sliced.affine, out_img.affine), which compares the slicer against itself and passes whatever the slicer does. It already exercises -j -1:1:-1, so that assertion is why this was never caught there. It now compares both against an affine calculated independently. test_slicer_preserves_ras_position went through img.slicer only. One line asserts slice_affine directly as well, so the affine calculator is covered on its own rather than through its caller.
SpatialFirstSlicer.slice_affinecopiedsubslicer.startstraight into the affine translation. Two cases were therefore wrong:img.slicer[-2:]) put the negative value into the affine instead of the equivalent positive index.img.slicer[::-1]) used 0 as the origin, but the first voxel of the result is the last voxel of the axis.In both cases the returned data was correct while the affine was not, so the image was silently shifted in RAS+ space.
img.slicer[-2:]andimg.slicer[8:]select the same voxels but produced affines 20 mm apart.nib-roiis affected too, since it accepts negative starts and:-1steps and callsslice_affinedirectly.Resolve each spatial subslicer with
slice.indices()so the transform is built from the concrete start and step thatdataobj[slicer]uses.Closes gh-1533.