(self)
| 149 | os.remove(test_image) |
| 150 | |
| 151 | def test_write_2d(self): |
| 152 | with tempfile.TemporaryDirectory() as out_dir: |
| 153 | image_name = os.path.join(out_dir, "test.nii.gz") |
| 154 | for p in TEST_NDARRAYS: |
| 155 | img = p(np.arange(6).reshape((2, 3))) |
| 156 | writer_obj = NibabelWriter() |
| 157 | writer_obj.set_data_array(img, channel_dim=None) |
| 158 | writer_obj.set_metadata({"affine": np.diag([1, 1, 1]), "original_affine": np.diag([1.4, 1, 1])}) |
| 159 | writer_obj.write(image_name, verbose=True) |
| 160 | out = nib.load(image_name) |
| 161 | np.testing.assert_allclose(out.get_fdata(), [[0, 1, 2], [3.0, 4, 5]], atol=1e-4, rtol=1e-4) |
| 162 | np.testing.assert_allclose(out.affine, np.diag([1.4, 1, 1, 1]), atol=1e-4, rtol=1e-4) |
| 163 | |
| 164 | image_name = os.path.join(out_dir, "test1.nii.gz") |
| 165 | img = np.arange(5).reshape((1, 5)) |
| 166 | writer_obj.set_data_array(img, channel_dim=None) |
| 167 | writer_obj.set_metadata( |
| 168 | {"affine": np.diag([1, 1, 1, 3, 3]), "original_affine": np.diag([1.4, 2.0, 1, 3, 5])} |
| 169 | ) |
| 170 | writer_obj.write(image_name, verbose=True) |
| 171 | out = nib.load(image_name) |
| 172 | np.testing.assert_allclose(out.get_fdata(), [[0, 2, 4]], atol=1e-4, rtol=1e-4) |
| 173 | np.testing.assert_allclose(out.affine, np.diag([1.4, 2, 1, 1]), atol=1e-4, rtol=1e-4) |
| 174 | |
| 175 | def test_write_3d(self): |
| 176 | with tempfile.TemporaryDirectory() as out_dir: |
nothing calls this directly
no test coverage detected