def test_robust_to_ordering(self, axial_slices):
        '''
        The DICOM slices should be able to be passed in in any order, and they
        should be recombined appropriately.
        '''
        a, _ = _merge_slice_pixel_arrays(
            [axial_slices[0], axial_slices[1], axial_slices[2]])
        b, _ = _merge_slice_pixel_arrays(
            [axial_slices[1], axial_slices[0], axial_slices[2]])
        assert np.array_equal(a, b)

        c, _ = _merge_slice_pixel_arrays(
            [axial_slices[0], axial_slices[1], axial_slices[2]])
        d, _ = _merge_slice_pixel_arrays(
            [axial_slices[2], axial_slices[0], axial_slices[1]])
        assert np.array_equal(c, d)
        print('Passed test_robust_to_ordering()')
 def test_no_rescale_if_forced_false(self):
     slice_datasets = [
         MockSlice(np.ones((10, 20), dtype=np.uint8),
                   0,
                   RescaleSlope=2,
                   RescaleIntercept=3)
     ]
     voxels, _ = _merge_slice_pixel_arrays(slice_datasets, rescale=False)
     assert voxels.dtype == np.uint8
     print('Passed test_no_rescale_if_forced_false()')
    def test_casting_if_only_rescale_slope(self):
        '''
        If the `RescaleSlope` DICOM attribute is present, the
        `RescaleIntercept` attribute should also be present, however, we handle
        this case anyway.
        '''
        slices = [
            MockSlice(np.ones((10, 20), dtype=np.uint8), 0, RescaleSlope=2),
            MockSlice(np.ones((10, 20), dtype=np.uint8), 1, RescaleSlope=2),
        ]

        voxels, _ = _merge_slice_pixel_arrays(slices)
        assert voxels.dtype == np.dtype('float32')
        assert voxels[0, 0, 0] == 2.0
        print('Passed test_casting_if_only_rescale_slope()')
    def test_casting_rescale_slope_and_intercept(self):
        '''
        Some DICOM modules contain the `RescaleSlope` and `RescaleIntercept` DICOM attributes.
        '''
        slices = [
            MockSlice(np.ones((10, 20), dtype=np.uint8),
                      0,
                      RescaleSlope=2,
                      RescaleIntercept=3),
            MockSlice(np.ones((10, 20), dtype=np.uint8),
                      1,
                      RescaleSlope=2,
                      RescaleIntercept=3),
        ]

        voxels, _ = _merge_slice_pixel_arrays(slices)
        assert voxels.dtype == np.dtype('float32')
        assert voxels[0, 0, 0] == 5.0
        print('Passed test_casting_rescale_slope_and_intercept()')
 def test_rescales_if_forced_true(self):
     slice_datasets = [MockSlice(np.ones((10, 20), dtype=np.uint8), 0)]
     voxels, _ = _merge_slice_pixel_arrays(slice_datasets, rescale=True)
     assert voxels.dtype == np.float32
     print('Passed test_rescales_if_forced_true')