示例#1
0
    def test__same_as_above__but_remove_some_centre_pixels_and_change_order__order_does_not_change_mapping(
            self):

        ma = mask.Mask(array=np.array([[False, False, False],
                                       [False, False, False],
                                       [False, False, False]]),
                       pixel_scale=1.0)

        unmasked_sparse_grid_pixel_centres = np.array([[0, 0], [0, 1], [2, 2],
                                                       [1, 1], [0, 2], [2, 0],
                                                       [0, 2]])

        total_masked_pixels = mask_util.total_sparse_pixels_from_mask(
            mask=ma,
            unmasked_sparse_grid_pixel_centres=
            unmasked_sparse_grid_pixel_centres)

        sparse_to_unmasked_sparse = mapping_util.sparse_to_unmasked_sparse_from_mask_and_pixel_centres(
            total_sparse_pixels=total_masked_pixels,
            mask=ma,
            unmasked_sparse_grid_pixel_centres=
            unmasked_sparse_grid_pixel_centres)

        assert (sparse_to_unmasked_sparse == np.array([0, 1, 2, 3, 4, 5,
                                                       6])).all()
示例#2
0
    def __init__(self,
                 unmasked_sparse_grid_shape,
                 pixel_scales,
                 regular_grid,
                 origin=(0.0, 0.0)):
        """A sparse grid of coordinates, where each entry corresponds to the (y,x) coordinates at the centre of a \
        pixel on the sparse grid. To setup the sparse-grid, it is laid over a regular-grid of unmasked pixels, such \
        that all sparse-grid pixels which map inside of an unmasked regular-grid pixel are included on the sparse grid.

        To setup this sparse grid, we thus have two sparse grid_stack:

        - The unmasked sparse-grid, which corresponds to a uniform 2D array of pixels. The edges of this grid \
          correspond to the 4 edges of the mask (e.g. the higher and lowest (y,x) arc-second unmasked pixels) and the \
          grid's shape is speciifed by the unmasked_sparse_grid_shape parameter.

        - The (masked) sparse-grid, which is all pixels on the unmasked sparse-grid above which fall within unmasked \
          regular-grid pixels. These are the pixels which are actually used for other modules in PyAutoLens.

        The origin of the unmasked sparse grid can be changed to allow off-center pairings with sparse-grid pixels, \
        which is necessary when a mask has a centre offset from (0.0", 0.0"). However, the sparse grid itself \
        retains an origin of (0.0", 0.0"), ensuring its arc-second grid uses the same coordinate system as the \
        other grid_stack.

        The sparse grid is used to determine the pixel centers of an adaptive grid pixelization.

        Parameters
        ----------
        unmasked_sparse_grid_shape : (int, int)
            The shape of the unmasked sparse-grid whose centres form the sparse-grid.
        pixel_scales : (float, float)
            The pixel-to-arcsecond scale of a pixel in the y and x directions.
        regular_grid : RegularGrid
            The regular-grid used to determine which pixels are in the sparse grid.
        origin : (float, float)
            The centre of the unmasked sparse grid, which matches the centre of the mask.
        """

        self.shape = unmasked_sparse_grid_shape
        self.origin = origin
        self.total_unmasked_sparse_pixels = int(self.shape[0] * self.shape[1])
        self.pixel_scales = pixel_scales

        self.regular_grid = regular_grid
        self.unmasked_sparse_grid = self.grid_1d
        self.unmasked_sparse_grid_pixel_centres = \
            regular_grid.mask.grid_arc_seconds_to_grid_pixel_centres(self.unmasked_sparse_grid)

        self.total_sparse_pixels = mask_util.total_sparse_pixels_from_mask(
            mask=self.regular_grid.mask,
            unmasked_sparse_grid_pixel_centres=self.
            unmasked_sparse_grid_pixel_centres)
示例#3
0
    def test__same_as_above__different_mask_and_centres(self):

        ma = mask.Mask(array=np.array([[False, False, True],
                                       [False, False, False],
                                       [True, False, False]]),
                       pixel_scale=1.0)

        unmasked_sparse_grid_pixel_centres = np.array([[0, 0], [0, 1], [0, 2],
                                                       [0, 2], [0, 2], [1, 1]])

        total_masked_pixels = mask_util.total_sparse_pixels_from_mask(
            mask=ma,
            unmasked_sparse_grid_pixel_centres=
            unmasked_sparse_grid_pixel_centres)

        sparse_to_unmasked_sparse = mapping_util.sparse_to_unmasked_sparse_from_mask_and_pixel_centres(
            total_sparse_pixels=total_masked_pixels,
            mask=ma,
            unmasked_sparse_grid_pixel_centres=
            unmasked_sparse_grid_pixel_centres)

        assert (sparse_to_unmasked_sparse == np.array([0, 1, 5])).all()
示例#4
0
    def test__mask_is_cross__some_pix_pixels_are_masked__omitted_from_mapping(
            self):

        ma = mask.Mask(array=np.array([[True, False, True],
                                       [False, False, False],
                                       [True, False, True]]),
                       pixel_scale=1.0)

        unmasked_sparse_grid_pixel_centres = np.array \
            ([[0 ,0], [0 ,1], [0 ,2], [1 ,0], [1 ,1], [1 ,2], [2 ,0], [2 ,1], [2 ,2]])

        total_masked_pixels = mask_util.total_sparse_pixels_from_mask(
            mask=ma,
            unmasked_sparse_grid_pixel_centres=
            unmasked_sparse_grid_pixel_centres)

        sparse_to_unmasked_sparse = mapping_util.sparse_to_unmasked_sparse_from_mask_and_pixel_centres(
            total_sparse_pixels=total_masked_pixels,
            mask=ma,
            unmasked_sparse_grid_pixel_centres=
            unmasked_sparse_grid_pixel_centres)

        assert (sparse_to_unmasked_sparse == np.array([1, 3, 4, 5, 7])).all()
示例#5
0
    def test__mask_full_false__image_mask_and_pixel_centres_fully_overlap__each_sparse_maps_to_unmaked_sparse(
            self):

        ma = mask.Mask(array=np.array([[False, False, False],
                                       [False, False, False],
                                       [False, False, False]]),
                       pixel_scale=1.0)

        unmasked_sparse_grid_pixel_centres = np.array \
            ([[0 ,0], [0 ,1], [0 ,2], [1 ,0], [1 ,1], [1 ,2], [2 ,0], [2 ,1], [2 ,2]])

        total_masked_pixels = mask_util.total_sparse_pixels_from_mask(
            mask=ma,
            unmasked_sparse_grid_pixel_centres=
            unmasked_sparse_grid_pixel_centres)

        sparse_to_unmasked_sparse = mapping_util.sparse_to_unmasked_sparse_from_mask_and_pixel_centres(
            total_sparse_pixels=total_masked_pixels,
            mask=ma,
            unmasked_sparse_grid_pixel_centres=
            unmasked_sparse_grid_pixel_centres)

        assert (sparse_to_unmasked_sparse == np.array(
            [0, 1, 2, 3, 4, 5, 6, 7, 8])).all()