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

Method test_orientation

tests/data/test_nifti_rw.py:76–107  ·  view source on GitHub ↗
(self, array, affine, reader_param, expected)

Source from the content-addressed store, hash-verified

74class TestNiftiLoadRead(unittest.TestCase):
75 @parameterized.expand(TESTS)
76 def test_orientation(self, array, affine, reader_param, expected):
77 test_image = make_nifti_image(array, affine)
78
79 # read test cases
80 loader = LoadImage(**reader_param)
81 load_result = loader(test_image)
82 data_array = load_result.numpy()
83 if reader_param.get("image_only", False):
84 header = None
85 else:
86 header = load_result.meta
87 header["affine"] = header["affine"].numpy()
88 if os.path.exists(test_image):
89 os.remove(test_image)
90
91 # write test cases
92 writer_obj = NibabelWriter()
93 writer_obj.set_data_array(data_array, channel_dim=None)
94 if header is not None:
95 writer_obj.set_metadata(header)
96 elif affine is not None:
97 writer_obj.set_metadata({"affine": affine})
98 writer_obj.write(test_image, verbose=True)
99 saved = nib.load(test_image)
100 saved_affine = saved.affine
101 saved_data = saved.get_fdata()
102 if os.path.exists(test_image):
103 os.remove(test_image)
104
105 if affine is not None:
106 assert_allclose(saved_affine, affine, type_test=False)
107 assert_allclose(saved_data, expected, type_test=False)
108
109 def test_consistency(self):
110 np.set_printoptions(suppress=True, precision=3)

Callers

nothing calls this directly

Calls 10

set_data_arrayMethod · 0.95
set_metadataMethod · 0.95
writeMethod · 0.95
make_nifti_imageFunction · 0.90
LoadImageClass · 0.90
NibabelWriterClass · 0.90
assert_allcloseFunction · 0.90
getMethod · 0.80
removeMethod · 0.80
loadMethod · 0.80

Tested by

no test coverage detected