Exemple #1
0
        def test__4x3_grid__non_symmetric_centre_shift(self):
            #   _ _ _
            #  |_|_|_|
            #  |_|_|_|
            #  |_|_|_|
            #  |_|_|_|

            pixelization_grid = np.array([[3.0, -0.5], [3.0,
                                                        0.51], [2.49, -0.5],
                                          [1.4, 1.0], [1.0, 2.5]])

            pix = pixelizations.Rectangular(shape=(4, 3))

            geometry = pix.geometry_from_grid(grid=pixelization_grid)

            grids = MockGridStack(regular=pixelization_grid,
                                  sub=MockSubGrid(pixelization_grid,
                                                  sub_to_regular=np.ones((1)),
                                                  sub_grid_size=1))

            pix = mappers.RectangularMapper(pixels=12,
                                            shape=(4, 3),
                                            grid_stack=grids,
                                            border=None,
                                            geometry=geometry)

            assert (pix.regular_to_pix == np.array([0, 1, 3, 10, 11])).all()
            assert (pix.sub_to_pix == np.array([0, 1, 3, 10, 11])).all()
            assert pix.pix_to_regular == [[0], [1], [], [2], [], [], [], [],
                                          [], [], [3], [4]]
            assert pix.pix_to_sub == [[0], [1], [], [2], [], [], [], [], [],
                                      [], [3], [4]]
Exemple #2
0
        def test__3x3_grid_of_pixel_grid__1_coordinate_per_square_pixel__near_edges_of_pixels(
                self):
            #   _ _ _
            #  |_|_|_| Boundaries for pixels x = 0 and y = 0  -1.0 to -(1/3)
            #  |_|_|_| Boundaries for pixels x = 1 and y = 1 - (1/3) to (1/3)
            #  |_|_|_| Boundaries for pixels x = 2 and y = 2 - (1/3)" to 1.0"

            pixelization_grid = np.array([[1.0, -1.0], [1.0, 0.0], [1.0, 1.0],
                                          [-0.32, -1.0], [-0.32, 0.32],
                                          [0.0, 1.0], [-0.34, -0.34],
                                          [-0.34, 0.325], [-1.0, 1.0]])

            pix = pixelizations.Rectangular(shape=(3, 3))

            geometry = pix.geometry_from_grid(grid=pixelization_grid)

            grids = MockGridStack(regular=pixelization_grid,
                                  sub=MockSubGrid(pixelization_grid,
                                                  sub_to_regular=np.ones((1)),
                                                  sub_grid_size=1))

            pix = mappers.RectangularMapper(pixels=9,
                                            shape=(3, 3),
                                            grid_stack=grids,
                                            border=None,
                                            geometry=geometry)

            assert (pix.regular_to_pix == np.array([0, 1, 2, 3, 4, 5, 6, 7,
                                                    8])).all()
            assert (pix.sub_to_pix == np.array([0, 1, 2, 3, 4, 5, 6, 7,
                                                8])).all()
            assert pix.pix_to_regular == [[0], [1], [2], [3], [4], [5], [6],
                                          [7], [8]]
            assert pix.pix_to_sub == [[0], [1], [2], [3], [4], [5], [6], [7],
                                      [8]]
Exemple #3
0
        def test__3x4_grid__change_arcsecond_dimensions__not_symmetric(self):
            #   _ _ _ _
            #  |_|_|_|_|
            #  |_|_|_|_|
            #  |_|_|_|_|

            pixelization_grid = np.array([[1.0, -1.5], [1.0, -0.49],
                                          [0.32, -1.5], [-0.34, 0.49],
                                          [-1.0, 1.5]])

            pix = pixelizations.Rectangular(shape=(3, 4))

            grids = MockGridStack(regular=pixelization_grid,
                                  sub=MockSubGrid(pixelization_grid,
                                                  sub_to_regular=np.ones((1)),
                                                  sub_grid_size=1))

            geometry = pix.geometry_from_grid(grid=pixelization_grid)

            pix = mappers.RectangularMapper(pixels=12,
                                            shape=(3, 4),
                                            grid_stack=grids,
                                            border=None,
                                            geometry=geometry)

            assert (pix.regular_to_pix == np.array([0, 1, 4, 10, 11])).all()
            assert (pix.sub_to_pix == np.array([0, 1, 4, 10, 11])).all()
            assert pix.pix_to_regular == [[0], [1], [], [], [2], [], [], [],
                                          [], [], [3], [4]]
            assert pix.pix_to_sub == [[0], [1], [], [], [2], [], [], [], [],
                                      [], [3], [4]]
Exemple #4
0
        def test__3x3_grid__change_arcsecond_dimensions__not_symmetric(self):
            #   _ _ _
            #  |_|_|_| Boundaries for pixels x = 0 and y = 0  -1.5 to -0.5
            #  |_|_|_| Boundaries for pixels x = 1 and y = 1 -0.5 to 0.5
            #  |_|_|_| Boundaries for pixels x = 2 and y = 2  0.5 to 1.5

            pixelization_grid = np.array([[1.0, -1.5], [1.0, -0.49],
                                          [0.32, -1.5], [0.32, 0.51],
                                          [-1.0, 1.5]])

            pix = pixelizations.Rectangular(shape=(3, 3))

            geometry = pix.geometry_from_grid(grid=pixelization_grid)

            grids = MockGridStack(regular=pixelization_grid,
                                  sub=MockSubGrid(pixelization_grid,
                                                  sub_to_regular=np.ones((1)),
                                                  sub_grid_size=1))

            pix = mappers.RectangularMapper(pixels=9,
                                            shape=(3, 3),
                                            grid_stack=grids,
                                            border=None,
                                            geometry=geometry)

            assert (pix.regular_to_pix == np.array([0, 1, 3, 5, 8])).all()
            assert (pix.sub_to_pix == np.array([0, 1, 3, 5, 8])).all()
            assert pix.pix_to_regular == [[0], [1], [], [2], [], [3], [], [],
                                          [4]]
            assert pix.pix_to_sub == [[0], [1], [], [2], [], [3], [], [], [4]]
Exemple #5
0
        def test__3x3_grid_of_pixel_grid__add_multiple_grid_to_1_pixel_pixel(
                self):
            #                  _ _ _
            # -1.0 to -(1/3)  |_|_|_|
            # -(1/3) to (1/3) |_|_|_|
            #  (1/3) to 1.0   |_|_|_|

            pixelization_grid = np.array([[1.0, -1.0], [0.0, 0.0], [1.0, 1.0],
                                          [0.0, 0.0], [0.0, 0.0], [0.0, 0.0],
                                          [-1.0, -1.0], [0.0, 0.0],
                                          [-1.0, 1.0]])

            pix = pixelizations.Rectangular(shape=(3, 3))

            geometry = pix.geometry_from_grid(grid=pixelization_grid)

            grids = MockGridStack(regular=pixelization_grid,
                                  sub=MockSubGrid(pixelization_grid,
                                                  sub_to_regular=np.ones((1)),
                                                  sub_grid_size=1))

            pix = mappers.RectangularMapper(pixels=9,
                                            shape=(3, 3),
                                            grid_stack=grids,
                                            border=None,
                                            geometry=geometry)

            assert (pix.regular_to_pix == np.array([0, 4, 2, 4, 4, 4, 6, 4,
                                                    8])).all()
            assert (pix.sub_to_pix == np.array([0, 4, 2, 4, 4, 4, 6, 4,
                                                8])).all()
            assert pix.pix_to_regular == [[0], [], [2], [], [1, 3, 4, 5, 7],
                                          [], [6], [], [8]]
            assert pix.pix_to_sub == [[0], [], [2], [], [1, 3, 4, 5, 7], [],
                                      [6], [], [8]]
    def test__5_simple_grid__include_sub_grid__sets_up_correct_mapper(self):

        regular_grid = np.array([[1.0, 1.0], [-1.0, 1.0], [0.0, 0.0],
                                 [1.0, -1.0], [-1.0, -1.0]])

        sub_grid = np.array([[1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [0.0, 0.0],
                             [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [0.0, 0.0],
                             [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0],
                             [1.0, -1.0], [1.0, -1.0], [1.0, -1.0], [0.0, 0.0],
                             [-1.0, -1.0], [-1.0, -1.0], [-1.0, -1.0],
                             [0.0, 0.0]])

        sub_to_regular = np.array(
            [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4])

        pixel_centers = regular_grid

        regular_to_sparse = np.array([0, 1, 2, 3, 4])

        grid_stack = MockGridStack(regular=regular_grid,
                                   sub=MockSubGrid(sub_grid,
                                                   sub_to_regular,
                                                   sub_grid_size=2),
                                   pix=pixel_centers,
                                   regular_to_nearest_pix=regular_to_sparse)

        pix = pixelizations.AdaptiveMagnification(shape=(5, 1))

        mapper = pix.mapper_from_grid_stack_and_border(grid_stack=grid_stack,
                                                       border=None)

        assert mapper.is_image_plane_pixelization == True
        assert mapper.geometry.shape_arc_seconds == pytest.approx((2.0, 2.0),
                                                                  1.0e-4)
        assert (mapper.geometry.pixel_centres == pixel_centers).all()
        assert mapper.geometry.origin == (0.0, 0.0)

        assert isinstance(mapper, pm.VoronoiMapper)

        assert (mapper.mapping_matrix == np.array([[0.75, 0.0, 0.25, 0.0, 0.0],
                                                   [0.0, 0.75, 0.25, 0.0, 0.0],
                                                   [0.0, 0.0, 1.0, 0.0, 0.0],
                                                   [0.0, 0.0, 0.25, 0.75, 0.0],
                                                   [0.0, 0.0, 0.25, 0.0,
                                                    0.75]])).all()

        reg = regularization.Constant(coefficients=(1.0, ))
        regularization_matrix = reg.regularization_matrix_from_pixel_neighbors(
            mapper.geometry.pixel_neighbors,
            mapper.geometry.pixel_neighbors_size)

        assert (regularization_matrix == np.array(
            [[3.00000001, -1.0, -1.0, -1.0, 0.0],
             [-1.0, 3.00000001, -1.0, 0.0, -1.0],
             [-1.0, -1.0, 4.00000001, -1.0, -1.0],
             [-1.0, 0.0, -1.0, 3.00000001, -1.0],
             [0.0, -1.0, -1.0, -1.0, 3.00000001]])).all()
    def test__3x3_simple_grid__include_mask__create_using_regular_grid(self):

        regular_grid = np.array([[1.0, 0.0], [0.0, -1.0], [0.0, 0.0],
                                 [0.0, 1.0], [-1.0, 0.0]])

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

        sub_grid = np.array([[1.0, 0.0], [0.0, -1.0], [0.0, 0.0], [0.0, 1.0],
                             [-1.0, 0.0]])
        sub_to_regular = np.array([0, 1, 2, 3, 4])

        regular_grid = grids.RegularGrid(arr=regular_grid, mask=mask)
        sub_grid = MockSubGrid(sub_grid, sub_to_regular, sub_grid_size=1)

        pix = pixelizations.AdaptiveMagnification(shape=(3, 3))
        image_plane_pix = pix.image_plane_pix_grid_from_regular_grid(
            regular_grid=regular_grid)

        grid_stack = MockGridStack(
            regular=regular_grid,
            sub=sub_grid,
            pix=image_plane_pix.sparse_grid,
            regular_to_nearest_pix=image_plane_pix.regular_to_sparse)

        mapper = pix.mapper_from_grid_stack_and_border(grid_stack=grid_stack,
                                                       border=None)

        assert mapper.is_image_plane_pixelization == True
        assert mapper.geometry.shape_arc_seconds == pytest.approx((2.0, 2.0),
                                                                  1.0e-4)
        assert (mapper.geometry.pixel_centres == image_plane_pix.sparse_grid
                ).all()
        assert mapper.geometry.origin == pytest.approx((0.0, 0.0), 1.0e-4)

        assert isinstance(mapper, pm.VoronoiMapper)

        assert (mapper.mapping_matrix == np.array([[1.0, 0.0, 0.0, 0.0, 0.0],
                                                   [0.0, 1.0, 0.0, 0.0, 0.0],
                                                   [0.0, 0.0, 1.0, 0.0, 0.0],
                                                   [0.0, 0.0, 0.0, 1.0, 0.0],
                                                   [0.0, 0.0, 0.0, 0.0,
                                                    1.0]])).all()

        reg = regularization.Constant(coefficients=(1.0, ))
        regularization_matrix = reg.regularization_matrix_from_pixel_neighbors(
            mapper.geometry.pixel_neighbors,
            mapper.geometry.pixel_neighbors_size)

        assert (regularization_matrix == np.array(
            [[3.00000001, -1.0, -1.0, -1.0, 0.0],
             [-1.0, 3.00000001, -1.0, 0.0, -1.0],
             [-1.0, -1.0, 4.00000001, -1.0, -1.0],
             [-1.0, 0.0, -1.0, 3.00000001, -1.0],
             [0.0, -1.0, -1.0, -1.0, 3.00000001]])).all()
    def test__5_simple_grid__include_sub_grid(self):
        # Source-plane comprises 5 grid, so 5 masked_image pixels traced to the pix-plane.
        regular_grid = np.array([[1.0, -1.0], [1.0, 1.0], [0.0, 0.0],
                                 [-1.0, -1.0], [-1.0, 1.0]])
        # Assume a 2x2 sub-grid, so each of our 5 masked_image-pixels are split into 4.
        # The grid below is unphysical in that the (0.0, 0.0) terms on the end of each sub-grid probably couldn't
        # happen for a real lensing calculation. This is to make a mapping_matrix matrix which explicitly tests the
        # sub-grid.
        sub_grid = np.array([[1.0, -1.0], [1.0, -1.0], [1.0, -1.0], [0.0, 0.0],
                             [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [0.0, 0.0],
                             [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0],
                             [-1.0, -1.0], [-1.0, -1.0], [-1.0, -1.0],
                             [0.0, 0.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0],
                             [0.0, 0.0]])

        sub_to_regular = np.array(
            [0, 0, 0, 2, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 2, 4, 4, 4, 2])

        grid_stack = MockGridStack(regular=regular_grid,
                                   sub=MockSubGrid(sub_grid,
                                                   sub_to_regular,
                                                   sub_grid_size=2))

        pix = pixelizations.Rectangular(shape=(3, 3))

        mapper = pix.mapper_from_grid_stack_and_border(grid_stack=grid_stack,
                                                       border=None)

        assert mapper.is_image_plane_pixelization == False
        assert mapper.geometry.shape_arc_seconds == pytest.approx((2.0, 2.0),
                                                                  1.0e-4)
        assert mapper.geometry.origin == pytest.approx((0.0, 0.0), 1.0e-4)

        assert (mapper.mapping_matrix == np.array(
            [[0.75, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 0.75, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.75, 0.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.75]])).all()
        assert mapper.shape == (3, 3)

        reg = regularization.Constant(coefficients=(1.0, ))
        regularization_matrix = reg.regularization_matrix_from_pixel_neighbors(
            mapper.geometry.pixel_neighbors,
            mapper.geometry.pixel_neighbors_size)

        assert (regularization_matrix == np.array(
            [[2.00000001, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
             [-1.0, 3.00000001, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, -1.0, 2.00000001, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0],
             [-1.0, 0.0, 0.0, 3.00000001, -1.0, 0.0, -1.0, 0.0, 0.0],
             [0.0, -1.0, 0.0, -1.0, 4.00000001, -1.0, 0.0, -1.0, 0.0],
             [0.0, 0.0, -1.0, 0.0, -1.0, 3.00000001, 0.0, 0.0, -1.0],
             [0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 2.00000001, -1.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 3.00000001, -1.0],
             [0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 2.00000001]])).all()
    def test__same_as_above_but_grid_requires_border_relocation(self):

        regular_grid = np.array([[1.0, -1.0], [1.0, 1.0], [0.0, 0.0],
                                 [-1.0, -1.0], [-1.0, 1.0]])
        sub_grid = np.array([[2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0],
                             [-2.0, -2.0]])
        # These will all be relocated to the regular grid edge.
        pix_grid = np.array([[1.1, -1.1], [1.1, 1.1], [0.0, 0.0], [-1.1, -1.1],
                             [-1.1, 1.1]])

        border = grids.RegularGridBorder(arr=np.array([0, 1, 3, 4]))

        sub_to_regular = np.array([0, 1, 2, 3, 4])

        regular_to_sparse = np.array([0, 1, 2, 3, 4])

        grid_stack = MockGridStack(regular=regular_grid,
                                   sub=MockSubGrid(sub_grid,
                                                   sub_to_regular,
                                                   sub_grid_size=1),
                                   pix=pix_grid,
                                   regular_to_nearest_pix=regular_to_sparse)

        pix = pixelizations.AdaptiveMagnification(shape=(5, 1))

        mapper = pix.mapper_from_grid_stack_and_border(grid_stack=grid_stack,
                                                       border=border)

        assert mapper.is_image_plane_pixelization == True
        assert mapper.geometry.shape_arc_seconds == pytest.approx((2.0, 2.0),
                                                                  1.0e-4)
        assert mapper.geometry.pixel_centres == pytest.approx(
            regular_grid, 1e-4)
        assert mapper.geometry.origin == (0.0, 0.0)

        assert isinstance(mapper, pm.VoronoiMapper)

        assert (mapper.mapping_matrix == np.array([[0.0, 1.0, 0.0, 0.0, 0.0],
                                                   [0.0, 1.0, 0.0, 0.0, 0.0],
                                                   [0.0, 1.0, 0.0, 0.0, 0.0],
                                                   [0.0, 1.0, 0.0, 0.0, 0.0],
                                                   [0.0, 0.0, 0.0, 1.0,
                                                    0.0]])).all()

        reg = regularization.Constant(coefficients=(1.0, ))
        regularization_matrix = reg.regularization_matrix_from_pixel_neighbors(
            mapper.geometry.pixel_neighbors,
            mapper.geometry.pixel_neighbors_size)

        assert (regularization_matrix == np.array(
            [[3.00000001, -1.0, -1.0, -1.0, 0.0],
             [-1.0, 3.00000001, -1.0, 0.0, -1.0],
             [-1.0, -1.0, 4.00000001, -1.0, -1.0],
             [-1.0, 0.0, -1.0, 3.00000001, -1.0],
             [0.0, -1.0, -1.0, -1.0, 3.00000001]])).all()
    def test__5_simple_grid__no_sub_grid(self):
        # Source-plane comprises 5 grid, so 5 masked_image pixels traced to the pix-plane.
        regular_grid = np.array([[1.0, -1.0], [1.0, 1.0], [0.0, 0.0],
                                 [-1.0, -1.0], [-1.0, 1.0]])
        sub_grid = np.array([[1.0, -1.0], [1.0, 1.0], [0.0, 0.0], [-1.0, -1.0],
                             [-1.0, 1.0]])

        sub_to_regular = np.array([0, 1, 2, 3, 4])

        grid_stack = MockGridStack(regular=regular_grid,
                                   sub=MockSubGrid(
                                       sub_grid=sub_grid,
                                       sub_to_regular=sub_to_regular,
                                       sub_grid_size=1))

        # There is no sub-grid, so our sub_grid are just the masked_image grid (note the NumPy weighted_data structure
        # ensures this has no sub-gridding)

        pix = pixelizations.Rectangular(shape=(3, 3))

        mapper = pix.mapper_from_grid_stack_and_border(grid_stack=grid_stack,
                                                       border=None)

        assert mapper.is_image_plane_pixelization == False
        assert mapper.geometry.shape_arc_seconds == pytest.approx((2.0, 2.0),
                                                                  1.0e-4)
        assert mapper.geometry.origin == pytest.approx((0.0, 0.0), 1.0e-4)

        assert (mapper.mapping_matrix == np.array(
            [[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]])).all()
        assert mapper.shape == (3, 3)

        reg = regularization.Constant(coefficients=(1.0, ))
        regularization_matrix = reg.regularization_matrix_from_pixel_neighbors(
            mapper.geometry.pixel_neighbors,
            mapper.geometry.pixel_neighbors_size)

        assert (regularization_matrix == np.array(
            [[2.00000001, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
             [-1.0, 3.00000001, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, -1.0, 2.00000001, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0],
             [-1.0, 0.0, 0.0, 3.00000001, -1.0, 0.0, -1.0, 0.0, 0.0],
             [0.0, -1.0, 0.0, -1.0, 4.00000001, -1.0, 0.0, -1.0, 0.0],
             [0.0, 0.0, -1.0, 0.0, -1.0, 3.00000001, 0.0, 0.0, -1.0],
             [0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 2.00000001, -1.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 3.00000001, -1.0],
             [0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 2.00000001]])).all()
Exemple #11
0
        def test__sub_to_pix_of_mapper_matches_nearest_neighbor_calculation(
                self):

            pixel_centers = np.array([[0.1, 0.1], [1.1, 0.1], [2.1, 0.1],
                                      [0.1, 1.1], [1.1, 1.1], [2.1, 1.1]])

            pixelization_sub_grid = np.array([[0.05, 0.15], [0.15, 0.15],
                                              [0.05, 0.05], [0.15, 0.05],
                                              [1.05, 0.15], [1.15, 0.15],
                                              [1.05, 0.05], [1.15, 0.05],
                                              [2.05, 0.15], [2.15, 0.15],
                                              [2.05, 0.05], [2.15, 0.05],
                                              [0.05, 1.15], [0.15, 1.15],
                                              [0.05, 1.05], [0.15, 1.05],
                                              [1.05, 1.15], [1.15, 1.15],
                                              [1.05, 1.05], [1.15, 1.05],
                                              [2.05, 1.15], [2.15, 1.15],
                                              [2.05, 1.05], [2.15, 1.05]])

            sub_to_pix_nearest_neighbour = grid_to_pixel_pixels_via_nearest_neighbour(
                pixelization_sub_grid, pixel_centers)

            sub_to_regular = np.array([
                0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5,
                5, 5, 5
            ])
            regular_to_nearest_pix = np.array([0, 0, 1, 0, 0, 1, 2, 2, 3])
            grids = MockGridStack(
                regular=np.array([]),
                sub=MockSubGrid(pixelization_sub_grid,
                                sub_to_regular,
                                sub_grid_size=1),
                pix=pixelization_sub_grid,
                regular_to_nearest_pix=regular_to_nearest_pix)

            pix = pixelizations.Voronoi()
            voronoi = pix.voronoi_from_pixel_centers(pixel_centers)
            pixel_neighbors, pixel_neighbors_size = pix.neighbors_from_pixelization(
                pixels=6, ridge_points=voronoi.ridge_points)

            mapper = mappers.VoronoiMapper(
                pixels=6,
                grid_stack=grids,
                border=None,
                voronoi=voronoi,
                geometry=MockGeometry(
                    pixel_centres=pixel_centers,
                    pixel_neighbors=pixel_neighbors,
                    pixel_neighbors_size=pixel_neighbors_size))

            assert (mapper.sub_to_pix == sub_to_pix_nearest_neighbour).all()
    def test__grid__requires_border_relocation(self):

        regular_grid = np.array([[1.0, -1.0], [1.0, 1.0], [0.0, 0.0],
                                 [-1.0, -1.0], [-1.0, 1.0]])
        sub_grid = np.array([[2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0],
                             [-2.0, -2.0]])

        border = grids.RegularGridBorder(arr=np.array([0, 1, 3, 4]))

        sub_to_regular = np.array([0, 1, 2, 3, 4])

        grid_stack = MockGridStack(regular=regular_grid,
                                   sub=MockSubGrid(sub_grid,
                                                   sub_to_regular,
                                                   sub_grid_size=1))

        pix = pixelizations.Rectangular(shape=(3, 3))

        mapper = pix.mapper_from_grid_stack_and_border(grid_stack, border)

        assert mapper.is_image_plane_pixelization == False
        assert mapper.geometry.shape_arc_seconds == pytest.approx((2.0, 2.0),
                                                                  1.0e-4)
        assert mapper.geometry.origin == pytest.approx((0.0, 0.0), 1.0e-4)

        assert (mapper.mapping_matrix == np.array(
            [[0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0]])).all()
        assert mapper.shape == (3, 3)

        reg = regularization.Constant(coefficients=(1.0, ))
        regularization_matrix = reg.regularization_matrix_from_pixel_neighbors(
            mapper.geometry.pixel_neighbors,
            mapper.geometry.pixel_neighbors_size)

        assert (regularization_matrix == np.array(
            [[2.00000001, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
             [-1.0, 3.00000001, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, -1.0, 2.00000001, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0],
             [-1.0, 0.0, 0.0, 3.00000001, -1.0, 0.0, -1.0, 0.0, 0.0],
             [0.0, -1.0, 0.0, -1.0, 4.00000001, -1.0, 0.0, -1.0, 0.0],
             [0.0, 0.0, -1.0, 0.0, -1.0, 3.00000001, 0.0, 0.0, -1.0],
             [0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 2.00000001, -1.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 3.00000001, -1.0],
             [0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 2.00000001]])).all()
Exemple #13
0
        def test__4x3_grid_of_pixel_grid__1_coordinate_in_each_pixel(self):
            #   _ _ _
            #  |_|_|_|
            #  |_|_|_|
            #  |_|_|_|
            #  |_|_|_|

            # Boundaries for column pixel 0 -1.0 to -(1/3)
            # Boundaries for column pixel 1 -(1/3) to (1/3)
            # Boundaries for column pixel 2  (1/3) to 1.0

            # Bounadries for row pixel 0 -1.0 to -0.5
            # Bounadries for row pixel 1 -0.5 to 0.0
            # Bounadries for row pixel 2  0.0 to 0.5
            # Bounadries for row pixel 3  0.5 to 1.0

            pixelization_grid = np.array([[1.0, -1.0], [1.0, 0.0], [1.0, 1.0],
                                          [0.5, -1.0], [-0.5, 1.0],
                                          [-1.0, 1.0]])

            pix = pixelizations.Rectangular(shape=(4, 3))

            geometry = pix.geometry_from_grid(grid=pixelization_grid)

            grids = MockGridStack(regular=pixelization_grid,
                                  sub=MockSubGrid(pixelization_grid,
                                                  sub_to_regular=np.ones((1)),
                                                  sub_grid_size=1))

            pix = mappers.RectangularMapper(pixels=12,
                                            shape=(4, 3),
                                            grid_stack=grids,
                                            border=None,
                                            geometry=geometry)

            assert (pix.regular_to_pix == np.array([0, 1, 2, 3, 8, 11])).all()
            assert (pix.sub_to_pix == np.array([0, 1, 2, 3, 8, 11])).all()
            assert pix.pix_to_regular == [[0], [1], [2], [3], [], [], [], [],
                                          [4], [], [], [5]]
            assert pix.pix_to_sub == [[0], [1], [2], [3], [], [], [], [], [4],
                                      [], [], [5]]