Ejemplo n.º 1
0
    def __init__(self, initial, image_list, mask_list=None, invert=False,
            square=False, outdir="", centers=None, psf_hw=13, kernel=None,
            psfreg=0., sceneL2=0.0, dc=0.0, light=False, hdu=0):
        # Metadata.
        self.image_list = image_list
        if mask_list is not None:
            self.mask_list = dict([(k, mask_list[i])
                                    for i, k in enumerate(image_list)])
        else:
            self.mask_list = {}
        self.invert = invert
        self.square = square
        self.outdir = os.path.abspath(outdir)
        self.psf_hw = psf_hw
        self.psfreg = psfreg
        self.sceneL2 = sceneL2
        self.dc = dc
        self.light = False
        self.hdu = hdu

        # Sort out the center vector and save it as a dictionary associated
        # with specific filenames.
        self.centers = centers
        if centers is not None:
            self.centers = dict([(image_list[i], centers[i])
                for i in range(len(image_list))])

        # Inference parameters.
        self.sky = 0
        self.scene = np.array(initial)

        # 'Sky'-subtract the initial scene.
        self.scene -= np.median(self.scene)

        # Deal with the masked pixels if there are any in the initial scene
        # by setting them to the 'sky' level.
        self.scene[np.isnan(self.scene)] = 0.0

        # Check the dimensions of the initial scene and set the size.
        shape = self.scene.shape
        assert shape[0] == shape[1], "The initial scene needs to be square."
        self.size = shape[0] - 2 * self.psf_hw

        # The 'kernel' used for 'light deconvolution'.
        if kernel is None:
            self.kernel = np.exp(-0.5 * (np.arange(-5, 6)[:, None] ** 2
                + np.arange(-5, 6)[None, :] ** 2))
            self.kernel /= np.sum(self.kernel)
        else:
            self.kernel = kernel

        # Index gymnastics.
        self.scene_mask = utils.unravel_scene(self.size + 2 * self.psf_hw,
                self.psf_hw)
        self.psf_rows, self.psf_cols = \
                utils.unravel_psf(self.size + 2 * self.psf_hw, self.psf_hw)
Ejemplo n.º 2
0
    def test_unravel_scene(self):
        """
        Test to make sure that the scene unraveling yields the correct
        results.

        """
        S, P = 4, 1
        unraveled = utils.unravel_scene(S, P)

        # Calculate the brute force unraveled scene.
        brute = np.array(
            [[0, 1, 2, 4, 5, 6, 8, 9, 10], [1, 2, 3, 5, 6, 7, 9, 10, 11],
             [4, 5, 6, 8, 9, 10, 12, 13, 14], [5, 6, 7, 9, 10, 11, 13, 14, 15]
             ],
            dtype=int)

        assert np.all(brute == unraveled)
Ejemplo n.º 3
0
    def test_convolution(self):
        """
        Test that the matrix operation and convolution give the same result.

        """
        # Build a simple scene and PSF as delta functions.
        scene = np.zeros((7, 7))
        psf = np.zeros((3, 3))
        scene[3, 3] = 1
        psf[1, 1] = 1

        # Do the convolution.
        convolution = thresher.convolve(scene, psf, mode="valid")

        # Do the matrix operation.
        M = utils.unravel_scene(len(scene), 1)
        matrix = np.dot(scene.flatten()[M], psf.flatten()[::-1]).reshape(convolution.shape)

        # Check the results.
        np.testing.assert_allclose(convolution, matrix)
Ejemplo n.º 4
0
    def test_convolution(self):
        """
        Test that the matrix operation and convolution give the same result.

        """
        # Build a simple scene and PSF as delta functions.
        scene = np.zeros((7, 7))
        psf = np.zeros((3, 3))
        scene[3, 3] = 1
        psf[1, 1] = 1

        # Do the convolution.
        convolution = thresher.convolve(scene, psf, mode="valid")

        # Do the matrix operation.
        M = utils.unravel_scene(len(scene), 1)
        matrix = np.dot(scene.flatten()[M], psf.flatten()[::-1]) \
                .reshape(convolution.shape)

        # Check the results.
        np.testing.assert_allclose(convolution, matrix)
Ejemplo n.º 5
0
    def test_unravel_scene(self):
        """
        Test to make sure that the scene unraveling yields the correct
        results.

        """
        S, P = 4, 1
        unraveled = utils.unravel_scene(S, P)

        # Calculate the brute force unraveled scene.
        brute = np.array(
            [
                [0, 1, 2, 4, 5, 6, 8, 9, 10],
                [1, 2, 3, 5, 6, 7, 9, 10, 11],
                [4, 5, 6, 8, 9, 10, 12, 13, 14],
                [5, 6, 7, 9, 10, 11, 13, 14, 15],
            ],
            dtype=int,
        )

        assert np.all(brute == unraveled)