Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions tests/test_nifti_rw.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def test_write_2d(self):
writer_obj.set_metadata({"affine": np.diag([1, 1, 1]), "original_affine": np.diag([1.4, 1, 1])})
writer_obj.write(image_name, verbose=True)
out = nib.load(image_name)
np.testing.assert_allclose(out.get_fdata(), [[0, 1, 2], [3.0, 4, 5]])
np.testing.assert_allclose(out.affine, np.diag([1.4, 1, 1, 1]))
np.testing.assert_allclose(out.get_fdata(), [[0, 1, 2], [3.0, 4, 5]], atol=1e-4, rtol=1e-4)
np.testing.assert_allclose(out.affine, np.diag([1.4, 1, 1, 1]), atol=1e-4, rtol=1e-4)

image_name = os.path.join(out_dir, "test1.nii.gz")
img = np.arange(5).reshape((1, 5))
Expand All @@ -168,8 +168,8 @@ def test_write_2d(self):
)
writer_obj.write(image_name, verbose=True)
out = nib.load(image_name)
np.testing.assert_allclose(out.get_fdata(), [[0, 2, 4]])
np.testing.assert_allclose(out.affine, np.diag([1.4, 2, 1, 1]))
np.testing.assert_allclose(out.get_fdata(), [[0, 2, 4]], atol=1e-4, rtol=1e-4)
np.testing.assert_allclose(out.affine, np.diag([1.4, 2, 1, 1]), atol=1e-4, rtol=1e-4)

def test_write_3d(self):
with tempfile.TemporaryDirectory() as out_dir:
Expand All @@ -192,8 +192,8 @@ def test_write_3d(self):
)
writer_obj.write(image_name, verbose=True)
out = nib.load(image_name)
np.testing.assert_allclose(out.get_fdata(), [[[0, 2, 4]]])
np.testing.assert_allclose(out.affine, np.diag([1.4, 2, 2, 1]))
np.testing.assert_allclose(out.get_fdata(), [[[0, 2, 4]]], atol=1e-4, rtol=1e-4)
np.testing.assert_allclose(out.affine, np.diag([1.4, 2, 2, 1]), atol=1e-4, rtol=1e-4)

def test_write_4d(self):
with tempfile.TemporaryDirectory() as out_dir:
Expand All @@ -216,8 +216,8 @@ def test_write_4d(self):
)
writer_obj.write(image_name, verbose=True)
out = nib.load(image_name)
np.testing.assert_allclose(out.get_fdata(), [[[[0], [2], [4]]]])
np.testing.assert_allclose(out.affine, np.diag([1.4, 2, 2, 1]))
np.testing.assert_allclose(out.get_fdata(), [[[[0], [2], [4]]]], atol=1e-4, rtol=1e-4)
np.testing.assert_allclose(out.affine, np.diag([1.4, 2, 2, 1]), atol=1e-4, rtol=1e-4)

def test_write_5d(self):
with tempfile.TemporaryDirectory() as out_dir:
Expand All @@ -241,8 +241,10 @@ def test_write_5d(self):
writer_obj.set_metadata({"affine": np.diag([1, 1, 1, 3]), "original_affine": np.diag([1.4, 2.0, 2, 3])})
writer_obj.write(image_name, verbose=True)
out = nib.load(image_name)
np.testing.assert_allclose(out.get_fdata(), np.array([[[[[0.0, 2.0]], [[4.0, 5.0]], [[7.0, 9.0]]]]]))
np.testing.assert_allclose(out.affine, np.diag([1.4, 2, 2, 1]))
np.testing.assert_allclose(
out.get_fdata(), np.array([[[[[0.0, 2.0]], [[4.0, 5.0]], [[7.0, 9.0]]]]]), atol=1e-4, rtol=1e-4
)
np.testing.assert_allclose(out.affine, np.diag([1.4, 2, 2, 1]), atol=1e-4, rtol=1e-4)


if __name__ == "__main__":
Expand Down