Beispiel #1
0
        def test__pixel_scales_work_for_voronoi_mapper(self, grid_7x7, image_7x7):
            pixelization_grid = 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]]
            )

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

            pixelization_grid = aa.grid_voronoi(
                grid_1d=pixelization_grid,
                nearest_pixelization_1d_index_for_mask_1d_index=nearest_pixelization_1d_index_for_mask_1d_index,
            )

            mapper = aa.mapper(
                grid=grid_7x7,
                pixelization_grid=pixelization_grid,
                hyper_image=image_7x7,
            )

            pixel_signals = mapper.pixel_signals_from_signal_scale(signal_scale=2.0)

            pixel_signals_util = aa.util.mapper.adaptive_pixel_signals_from_images(
                pixels=6,
                signal_scale=2.0,
                pixelization_1d_index_for_sub_mask_1d_index=mapper.pixelization_1d_index_for_sub_mask_1d_index,
                mask_1d_index_for_sub_mask_1d_index=grid_7x7.regions._mask_1d_index_for_sub_mask_1d_index,
                hyper_image=image_7x7,
            )

            assert (pixel_signals == pixel_signals_util).all()
Beispiel #2
0
        def test__sub_to_pix_of_mapper_matches_nearest_neighbor_calculation(
            self, grid_7x7
        ):
            pixelization_grid = 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]]
            )

            sub_to_pix_nearest_neighbour = grid_to_pixel_pixels_via_nearest_neighbour(
                grid_7x7, pixelization_grid
            )

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

            pixelization_grid = aa.grid_voronoi(
                grid_1d=pixelization_grid,
                nearest_pixelization_1d_index_for_mask_1d_index=nearest_pixelization_1d_index_for_mask_1d_index,
            )

            mapper = aa.mapper(grid=grid_7x7, pixelization_grid=pixelization_grid)

            assert (
                mapper.pixelization_1d_index_for_sub_mask_1d_index
                == sub_to_pix_nearest_neighbour
            ).all()
Beispiel #3
0
def make_voronoi_pixelization_grid_9(grid_7x7):
    grid_9 = aa.grid.manual_1d(
        grid=[
            [0.6, -0.3],
            [0.5, -0.8],
            [0.2, 0.1],
            [0.0, 0.5],
            [-0.3, -0.8],
            [-0.6, -0.5],
            [-0.4, -1.1],
            [-1.2, 0.8],
            [-1.5, 0.9],
        ],
        shape_2d=(3, 3),
        pixel_scales=1.0,
    )
    return aa.grid_voronoi(
        grid_1d=grid_9,
        nearest_pixelization_1d_index_for_mask_1d_index=np.zeros(
            shape=grid_7x7.shape_1d, dtype="int"),
    )
Beispiel #4
0
        [0.6, -0.3],
        [0.5, -0.8],
        [0.2, 0.1],
        [0.0, 0.5],
        [-0.3, -0.8],
        [-0.6, -0.5],
        [-0.4, -1.1],
        [-1.2, 0.8],
        [-1.5, 0.9],
    ],
    shape_2d=(3, 3),
    pixel_scales=1.0,
)
voronoi_grid = aa.grid_voronoi(
    grid_1d=grid_9,
    nearest_pixelization_1d_index_for_mask_1d_index=np.zeros(
        shape=grid_7x7.shape_1d, dtype="int"
    ),
)

voronoi_mapper = aa.mapper(grid=grid_7x7, pixelization_grid=voronoi_grid)

regularization = aa.reg.Constant(coefficient=1.0)

inversion = aa.inversion(
    masked_dataset=masked_imaging, mapper=voronoi_mapper, regularization=regularization
)

aplt.inversion.subplot_inversion(
    inversion=inversion,
    image_positions=[(0.05, 0.05)],
    lines=[(0.0, 0.0), (0.1, 0.1)],
Beispiel #5
0
    def test__3x3_simple_grid__include_mask_with_offset_centre(self):

        mask = aa.mask.manual(
            mask_2d=np.array([
                [True, True, True, True, True, True, True],
                [True, True, True, True, False, True, True],
                [True, True, True, False, False, False, True],
                [True, True, True, True, False, True, True],
                [True, True, True, True, True, True, True],
                [True, True, True, True, True, True, True],
                [True, True, True, True, True, True, True],
            ]),
            pixel_scales=1.0,
            sub_size=1,
        )

        grid = np.array([[2.0, 1.0], [1.0, 0.0], [1.0, 1.0], [1.0, 2.0],
                         [0.0, 1.0]])

        grid = aa.masked.grid.manual_1d(grid=grid, mask=mask)

        pix = aa.pix.VoronoiMagnification(shape=(3, 3))
        sparse_grid = grids.SparseGrid.from_grid_and_unmasked_2d_grid_shape(
            grid=grid, unmasked_sparse_shape=pix.shape)

        pixelization_grid = aa.grid_voronoi(
            grid_1d=sparse_grid.sparse,
            nearest_pixelization_1d_index_for_mask_1d_index=sparse_grid.
            sparse_1d_index_for_mask_1d_index,
        )

        mapper = pix.mapper_from_grid_and_sparse_grid(
            grid=grid,
            sparse_grid=pixelization_grid,
            inversion_uses_border=False)

        assert mapper.is_image_plane_pixelization == True
        assert mapper.pixelization_grid.shape_2d_scaled == pytest.approx(
            (2.0, 2.0), 1.0e-4)
        assert (mapper.pixelization_grid == sparse_grid.sparse).all()
        #   assert mapper.pixelization_grid.origin == pytest.approx((1.0, 1.0), 1.0e-4)

        assert isinstance(mapper, mappers.MapperVoronoi)

        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 = aa.reg.Constant(coefficient=1.0)
        regularization_matrix = reg.regularization_matrix_from_mapper(
            mapper=mapper)

        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()

        image = aa.array.ones(shape_2d=(7, 7))
        noise_map = aa.array.ones(shape_2d=(7, 7))
        psf = aa.kernel.no_blur()

        imaging = aa.imaging(image=image, noise_map=noise_map, psf=psf)

        masked_data = aa.masked.imaging(imaging=imaging, mask=mask)

        inversion = aa.inversion(masked_dataset=masked_data,
                                 mapper=mapper,
                                 regularization=reg)

        assert (
            inversion.blurred_mapping_matrix == mapper.mapping_matrix).all()
        assert (inversion.regularization_matrix == regularization_matrix).all()
        assert inversion.mapped_reconstructed_image == pytest.approx(
            np.ones(5), 1.0e-4)