def test_shift_and_crop_static(self): shift_node = ShiftAugment(sigma=1, shift_axis=0) shift_node.ndim = 2 upstream_arr = np.arange(16).reshape(4, 4) sub_shift_array = np.zeros(8, dtype=int).reshape(4, 2) roi_shape = (4, 4) voxel_size = Coordinate((1, 1)) downstream_arr = np.arange(16).reshape(4, 4) result = shift_node.shift_and_crop(upstream_arr, roi_shape, sub_shift_array, voxel_size) self.assertTrue(np.array_equal(result, downstream_arr))
def test_shift_and_crop3(self): shift_node = ShiftAugment(sigma=1, shift_axis=1) shift_node.ndim = 2 upstream_arr = np.arange(16).reshape(4, 4) sub_shift_array = np.zeros(8, dtype=int).reshape(4, 2) sub_shift_array[:, 0] = np.array([0, 1, 0, 2], dtype=int) roi_shape = (2, 4) voxel_size = Coordinate((1, 1)) downstream_arr = np.array([[8, 5, 10, 3], [12, 9, 14, 7]], dtype=int) result = shift_node.shift_and_crop(upstream_arr, roi_shape, sub_shift_array, voxel_size) # print(result) self.assertTrue(np.array_equal(result, downstream_arr))
def test_shift_and_crop2(self): shift_node = ShiftAugment(sigma=1, shift_axis=0) shift_node.ndim = 2 upstream_arr = np.arange(16).reshape(4, 4) sub_shift_array = np.zeros(8, dtype=int).reshape(4, 2) sub_shift_array[:, 1] = np.array([0, -1, -2, 0], dtype=int) roi_shape = (4, 2) voxel_size = Coordinate((1, 1)) downstream_arr = np.array([[0, 1], [5, 6], [10, 11], [12, 13]], dtype=int) result = shift_node.shift_and_crop(upstream_arr, roi_shape, sub_shift_array, voxel_size) self.assertTrue(np.array_equal(result, downstream_arr))