Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

oesteban
Copy link
Collaborator

Summary

  • add regression test for applying a single 3D transform to a 4D dataset

Testing

  • pytest nitransforms/tests/test_resampling.py::test_apply_single_3d_on_4d -q

https://chatgpt.com/codex/tasks/task_e_689f54b6c3bc8330a3230878ab5c4454

Copy link

codecov bot commented Aug 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.74%. Comparing base (0c2ad9f) to head (1428106).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #282   +/-   ##
=======================================
  Coverage   96.74%   96.74%           
=======================================
  Files          16       16           
  Lines        1994     1994           
  Branches      267      267           
=======================================
  Hits         1929     1929           
  Misses         41       41           
  Partials       24       24           
Flag Coverage Δ
unittests 96.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@effigies effigies force-pushed the codex/add-tests-for-missing-use-case branch from 6926d3c to 1428106 Compare September 5, 2025 18:00
Comment on lines +333 to +354
@pytest.mark.xfail(reason="gh-281: applying a single 3D transform to 4D data")
def test_apply_single_3d_on_4d():
"""Apply one 3D transform across all timepoints of a 4D dataset."""
nvols = 5
data = np.zeros((10, 5, 5, nvols), dtype=np.float32)
for i in range(nvols):
data[i + 1, 2, 2, i] = i + 1

img = nb.Nifti1Image(data, np.eye(4))

mat = np.eye(4)
mat[0, 3] = -1.0
ref = nb.Nifti1Image(np.zeros((10, 5, 5), dtype=np.uint8), np.eye(4))
xfm = nitl.Affine(mat, reference=ref)

moved = apply(xfm, img, order=0)
moved_data = np.asanyarray(moved.dataobj)

assert moved_data.shape == data.shape
for i in range(nvols):
assert moved_data[i + 2, 2, 2, i] == i + 1
assert moved_data[i + 1, 2, 2, i] == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present, this could fail because checking the values after applying the transform is wrong. I think a much simpler test is:

Suggested change
@pytest.mark.xfail(reason="gh-281: applying a single 3D transform to 4D data")
def test_apply_single_3d_on_4d():
"""Apply one 3D transform across all timepoints of a 4D dataset."""
nvols = 5
data = np.zeros((10, 5, 5, nvols), dtype=np.float32)
for i in range(nvols):
data[i + 1, 2, 2, i] = i + 1
img = nb.Nifti1Image(data, np.eye(4))
mat = np.eye(4)
mat[0, 3] = -1.0
ref = nb.Nifti1Image(np.zeros((10, 5, 5), dtype=np.uint8), np.eye(4))
xfm = nitl.Affine(mat, reference=ref)
moved = apply(xfm, img, order=0)
moved_data = np.asanyarray(moved.dataobj)
assert moved_data.shape == data.shape
for i in range(nvols):
assert moved_data[i + 2, 2, 2, i] == i + 1
assert moved_data[i + 1, 2, 2, i] == 0
@pytest.mark.xfail(reason="gh-281: applying a single 3D transform to 4D data", strict=True)
def test_apply_single_3d_on_4d():
"""Apply one 3D transform across all timepoints of a 4D dataset."""
img4d = nb.Nifti1Image(np.zeros((2, 3, 4, 5), np.eye(4))
ref3d = img4d.slicer[..., 0]
xfm = nitl.Affine(np.eye(4))
# Just a smoke test. When this passes, we should validate the values.
apply(xfm, img, reference=ref3d)

I'm adding strict=True so that the test doesn't just sit around XPASSing when we should start validating values after that point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants