MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / test_write_3d

Method test_write_3d

tests/data/test_nifti_rw.py:175–197  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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:
177 image_name = os.path.join(out_dir, "test.nii.gz")
178 for p in TEST_NDARRAYS:
179 img = p(np.arange(6).reshape((1, 2, 3)))
180 writer_obj = NibabelWriter()
181 writer_obj.set_data_array(img, channel_dim=None)
182 writer_obj.set_metadata({"affine": np.diag([1, 1, 1, 1]), "original_affine": np.diag([1.4, 1, 1, 1])})
183 writer_obj.write(image_name, verbose=True)
184 out = nib.load(image_name)
185 np.testing.assert_allclose(out.get_fdata(), [[[0, 1, 2], [3, 4, 5]]], atol=1e-4, rtol=1e-4)
186 np.testing.assert_allclose(out.affine, np.diag([1.4, 1, 1, 1]), atol=1e-4, rtol=1e-4)
187
188 image_name = os.path.join(out_dir, "test1.nii.gz")
189 img = p(np.arange(5).reshape((1, 1, 5)))
190 writer_obj.set_data_array(img, channel_dim=None)
191 writer_obj.set_metadata(
192 {"affine": np.diag([1, 1, 1, 3, 3]), "original_affine": np.diag([1.4, 2.0, 2, 3, 5])}
193 )
194 writer_obj.write(image_name, verbose=True)
195 out = nib.load(image_name)
196 np.testing.assert_allclose(out.get_fdata(), [[[0, 2, 4]]], atol=1e-4, rtol=1e-4)
197 np.testing.assert_allclose(out.affine, np.diag([1.4, 2, 2, 1]), atol=1e-4, rtol=1e-4)
198
199 def test_write_4d(self):
200 with tempfile.TemporaryDirectory() as out_dir:

Callers

nothing calls this directly

Calls 5

set_data_arrayMethod · 0.95
set_metadataMethod · 0.95
writeMethod · 0.95
NibabelWriterClass · 0.90
loadMethod · 0.80

Tested by

no test coverage detected