Beispiel #1
0
def test_center_kernel():
    x_grid, y_gird = Util.make_grid(31, 1)
    sigma = 2
    flux = gaussian.function(x_grid, y_gird, amp=1, sigma=sigma)
    kernel = Util.array2image(flux)
    kernel = kernel_util.kernel_norm(kernel)

    # kernel being centered
    kernel_new = kernel_util.center_kernel(kernel, iterations=20)
    kernel_new = kernel_util.kernel_norm(kernel_new)
    npt.assert_almost_equal(kernel_new/kernel, 1, decimal=8)
    # kernel shifted in x
    kernel_shifted = interp.shift(kernel, [-.1, 0], order=1)
    kernel_new = kernel_util.center_kernel(kernel_shifted, iterations=5)
    kernel_new = kernel_util.kernel_norm(kernel_new)
    npt.assert_almost_equal((kernel_new + 0.00001) / (kernel + 0.00001), 1, decimal=4)
    # kernel shifted in y
    kernel_shifted = interp.shift(kernel, [0, -0.4], order=1)
    kernel_new = kernel_util.center_kernel(kernel_shifted, iterations=5)
    kernel_new = kernel_util.kernel_norm(kernel_new)
    npt.assert_almost_equal((kernel_new + 0.01) / (kernel + 0.01), 1, decimal=3)
    # kernel shifted in x and y
    kernel_shifted = interp.shift(kernel, [0.2, -0.3], order=1)
    kernel_new = kernel_util.center_kernel(kernel_shifted, iterations=5)
    kernel_new = kernel_util.kernel_norm(kernel_new)
    npt.assert_almost_equal((kernel_new + 0.01) / (kernel + 0.01), 1, decimal=3)
Beispiel #2
0
    def test_raise(self):
        with self.assertRaises(ValueError):
            kernel = np.zeros((2, 2))
            kernel_util.center_kernel(kernel, iterations=1)

        with self.assertRaises(ValueError):
            kernel_super = np.ones((9, 9))
            kernel_util.split_kernel(kernel_super, supersampling_kernel_size=2, supersampling_factor=3)
        with self.assertRaises(ValueError):
            kernel_util.split_kernel(kernel_super, supersampling_kernel_size=3, supersampling_factor=0)
        with self.assertRaises(ValueError):
            image = np.ones((10, 10))
            kernel_util.cutout_source(x_pos=3, y_pos=2, image=image, kernelsize=2)
        with self.assertRaises(ValueError):
            kernel_util.fwhm_kernel(kernel=np.ones((4, 4)))
        with self.assertRaises(ValueError):
            kernel_util.fwhm_kernel(kernel=np.ones((5, 5)))