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

Method test_read_with_header

tests/data/test_nrrd_reader.py:100–116  ·  view source on GitHub ↗
(self, data_shape, filename, expected_shape, dtype, reference_header)

Source from the content-addressed store, hash-verified

98
99 @parameterized.expand([TEST_CASE_8])
100 def test_read_with_header(self, data_shape, filename, expected_shape, dtype, reference_header):
101 test_image = np.random.rand(*data_shape).astype(dtype)
102 with tempfile.TemporaryDirectory() as tempdir:
103 filename = os.path.join(tempdir, filename)
104 nrrd.write(filename, test_image.astype(dtype), header=reference_header)
105 reader = NrrdReader()
106 image_array, image_header = reader.get_data(reader.read(filename))
107 self.assertIsInstance(image_array, np.ndarray)
108 self.assertEqual(image_array.dtype, dtype)
109 self.assertTupleEqual(image_array.shape, expected_shape)
110 np.testing.assert_allclose(image_array, test_image)
111 self.assertIsInstance(image_header, dict)
112 self.assertTupleEqual(tuple(image_header["spatial_shape"]), expected_shape)
113 np.testing.assert_allclose(
114 image_header["affine"],
115 np.array([[-0.7, 0.0, 0.0, -1.0], [0.0, 0.0, -0.9, -5.0], [0.0, -0.8, 0.0, 20.0], [0.0, 0.0, 0.0, 1.0]]),
116 )
117
118 @parameterized.expand([TEST_CASE_8])
119 def test_read_with_header_index_order_c(self, data_shape, filename, expected_shape, dtype, reference_header):

Callers

nothing calls this directly

Calls 6

get_dataMethod · 0.95
readMethod · 0.95
NrrdReaderClass · 0.90
astypeMethod · 0.80
arrayMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected