Exemplo n.º 1
0
 def __init__(self,
              regular,
              sub,
              blurring=None,
              pix=None,
              regular_to_nearest_pix=None):
     self.regular = grids.RegularGrid(regular, mask=None)
     self.sub = sub
     self.blurring = grids.RegularGrid(
         blurring, mask=None) if blurring is not None else None
     self.pix = grids.PixGrid(
         pix, regular_to_nearest_pix=regular_to_nearest_pix,
         mask=None) if pix is not None else np.array([[0.0, 0.0]])
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
        def test__ensure_index_of_plane_image_has_negative_arcseconds_at_start(
                self, grid_stack_0):
            # The grid coordinates -2.0 -> 2.0 mean a plane of shape (5,5) has arc second coordinates running over
            # -1.6, -0.8, 0.0, 0.8, 1.6. The origin -1.6, -1.6 of the model_galaxy means its brighest pixel should be
            # index 0 of the 1D grid and (0,0) of the 2d plane datas_.

            msk = mask.Mask(array=np.full((5, 5), False), pixel_scale=1.0)

            grid_stack_0.regular = grids.RegularGrid(np.array([[-2.0, -2.0],
                                                               [2.0, 2.0]]),
                                                     mask=msk)

            g0 = g.Galaxy(light_profile=lp.EllipticalSersic(centre=(1.6, -1.6),
                                                            intensity=1.0))
            plane_stack = pl_stack.PlaneStack(galaxies=[g0],
                                              grid_stacks=[grid_stack_0])

            assert plane_stack.plane_images[0].shape == (5, 5)
            assert np.unravel_index(plane_stack.plane_images[0].argmax(),
                                    plane_stack.plane_images[0].shape) == (0,
                                                                           0)

            g0 = g.Galaxy(light_profile=lp.EllipticalSersic(centre=(1.6, 1.6),
                                                            intensity=1.0))
            plane_stack = pl_stack.PlaneStack(galaxies=[g0],
                                              grid_stacks=[grid_stack_0])
            assert np.unravel_index(plane_stack.plane_images[0].argmax(),
                                    plane_stack.plane_images[0].shape) == (0,
                                                                           4)

            g0 = g.Galaxy(light_profile=lp.EllipticalSersic(
                centre=(-1.6, -1.6), intensity=1.0))
            plane_stack = pl_stack.PlaneStack(galaxies=[g0],
                                              grid_stacks=[grid_stack_0])
            assert np.unravel_index(plane_stack.plane_images[0].argmax(),
                                    plane_stack.plane_images[0].shape) == (4,
                                                                           0)

            g0 = g.Galaxy(light_profile=lp.EllipticalSersic(centre=(-1.6, 1.6),
                                                            intensity=1.0))
            plane_stack = pl_stack.PlaneStack(galaxies=[g0],
                                              grid_stacks=[grid_stack_0])
            assert np.unravel_index(plane_stack.plane_images[0].argmax(),
                                    plane_stack.plane_images[0].shape) == (4,
                                                                           4)