def test_convolve2d_adaptive_checks(self): bad_shape_kernel = np.random.random((3, 3)) bad_shape_image = np.random.random((100, )) kernel = np.random.random((3, 3, 1)) with self.assertRaises(ValueError): ois.convolve2d_adaptive(self.ref_img, bad_shape_kernel, 0) with self.assertRaises(ValueError): ois.convolve2d_adaptive(bad_shape_image, kernel, 0) ois.convolve2d_adaptive(self.ref_img.astype('int32'), kernel, 0) ois.convolve2d_adaptive(self.ref_img, kernel.astype('int32'), 0)
def test_subtractongrid_adaptive_ri(self): deg = 2 bkg_deg = None k_side = 3 k_shape = (k_side, k_side) pol_dof = (deg + 1) * (deg + 2) / 2 kernel = np.random.random((k_side, k_side, pol_dof)) image = ois.convolve2d_adaptive(self.ref_img, kernel, deg) subt_img, o, k, b = ois.subtractongrid(image, self.ref_img, kernelshape=k_shape, bkgdegree=bkg_deg, gridshape=(1, 1), method="AdaptiveBramich", poly_degree=deg) norm_diff = np.linalg.norm(subt_img) / np.linalg.norm(image) self.assertLess(norm_diff, 1E-10) self.assertFalse(isinstance(subt_img, np.ma.MaskedArray)) self.assertFalse(isinstance(o, np.ma.MaskedArray)) self.assertFalse(isinstance(b, np.ma.MaskedArray))
def test_convolve2d_array_dims(self): with self.assertRaises(ValueError): ois.convolve2d_adaptive(np.zeros((10, 10, 2)), np.ones((3, 3, 6)), 2) with self.assertRaises(ValueError): ois.convolve2d_adaptive(np.zeros((10, 10)), np.ones((9, 6)), 2)
def test_convolve2d_adaptive_dtype_check(self): kernel = np.random.random((3, 3, 1)) ois.convolve2d_adaptive(np.random.randint(low=0, high=100, size=(100, 100), dtype='int32'), kernel, 0) ois.convolve2d_adaptive(np.random.random((100, 100)), kernel.astype('int32'), 0)