-
Notifications
You must be signed in to change notification settings - Fork 17
test: add xfail for 3d transform on 4d data #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6926d3c
to
1428106
Compare
@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 |
There was a problem hiding this comment.
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:
@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.
Summary
Testing
pytest nitransforms/tests/test_resampling.py::test_apply_single_3d_on_4d -q
https://chatgpt.com/codex/tasks/task_e_689f54b6c3bc8330a3230878ab5c4454