Ejemplo n.º 1
0
    def test__new_imaging_with_signal_to_noise_limit__include_mask_to_only_increase_centre_values(
        self, ):
        image = aa.Array2D.full(fill_value=20.0,
                                shape_native=(2, 2),
                                pixel_scales=1.0)
        image[2] = 5.0
        image[3] = 5.0

        noise_map_array = aa.Array2D.full(fill_value=5.0,
                                          shape_native=(2, 2),
                                          pixel_scales=1.0)
        noise_map_array[2] = 2.0
        noise_map_array[3] = 2.0

        mask = aa.Mask2D.manual(mask=[[True, False], [False, True]],
                                pixel_scales=1.0)

        imaging = aa.Imaging(
            image=image,
            psf=aa.Kernel2D.zeros(shape_native=(3, 3), pixel_scales=1.0),
            noise_map=noise_map_array,
        )

        imaging_capped = imaging.signal_to_noise_limited_from(
            signal_to_noise_limit=2.0, mask=mask)

        assert (imaging_capped.image.native == np.array([[20.0, 20.0],
                                                         [5.0, 5.0]])).all()

        assert (imaging_capped.noise_map.native == np.array([[5.0, 10.0],
                                                             [2.5,
                                                              2.0]])).all()

        assert (imaging_capped.signal_to_noise_map.native == np.array(
            [[4.0, 2.0], [2.0, 2.5]])).all()
Ejemplo n.º 2
0
    def test__new_imaging_with_signal_to_noise_limit__limit_above_max_signal_to_noise__signal_to_noise_map_unchanged(
        self, ):

        image = aa.Array2D.full(fill_value=20.0,
                                shape_native=(2, 2),
                                pixel_scales=1.0)
        image[3] = 5.0

        noise_map_array = aa.Array2D.full(fill_value=5.0,
                                          shape_native=(2, 2),
                                          pixel_scales=1.0)
        noise_map_array[3] = 2.0

        imaging = aa.Imaging(
            image=image,
            psf=aa.Kernel2D.zeros(shape_native=(3, 3), pixel_scales=1.0),
            noise_map=noise_map_array,
        )

        imaging = imaging.signal_to_noise_limited_from(
            signal_to_noise_limit=100.0)

        assert (imaging.image == np.array([20.0, 20.0, 20.0, 5.0])).all()

        assert (imaging.noise_map == np.array([5.0, 5.0, 5.0, 2.0])).all()

        assert (imaging.signal_to_noise_map == np.array([4.0, 4.0, 4.0,
                                                         2.5])).all()
Ejemplo n.º 3
0
    def test__new_imaging_with_signal_to_noise_limit_below_max_signal_to_noise__signal_to_noise_map_capped_to_limit(
        self, ):
        image = aa.Array2D.full(fill_value=20.0,
                                shape_native=(2, 2),
                                pixel_scales=1.0)
        image[3] = 5.0

        noise_map_array = aa.Array2D.full(fill_value=5.0,
                                          shape_native=(2, 2),
                                          pixel_scales=1.0)
        noise_map_array[3] = 2.0

        imaging = aa.Imaging(
            image=image,
            psf=aa.Kernel2D.zeros(shape_native=(3, 3), pixel_scales=1.0),
            noise_map=noise_map_array,
        )

        imaging_capped = imaging.signal_to_noise_limited_from(
            signal_to_noise_limit=2.0)

        assert (imaging_capped.image.native == np.array([[20.0, 20.0],
                                                         [20.0, 5.0]])).all()

        assert (imaging_capped.noise_map.native == np.array([[10.0, 10.0],
                                                             [10.0,
                                                              2.5]])).all()

        assert (imaging_capped.signal_to_noise_map.native == np.array(
            [[2.0, 2.0], [2.0, 2.0]])).all()
Ejemplo n.º 4
0
    def test__different_imaging_without_mock_objects__customize_constructor_inputs(
        self, ):

        psf = aa.Kernel2D.ones(shape_native=(7, 7), pixel_scales=3.0)

        imaging = aa.Imaging(
            image=aa.Array2D.ones(shape_native=(19, 19), pixel_scales=3.0),
            psf=psf,
            noise_map=aa.Array2D.full(fill_value=2.0,
                                      shape_native=(19, 19),
                                      pixel_scales=3.0),
        )
        mask = aa.Mask2D.unmasked(shape_native=(19, 19),
                                  pixel_scales=1.0,
                                  invert=True,
                                  sub_size=8)
        mask[9, 9] = False

        masked_imaging = imaging.apply_mask(mask=mask)

        assert masked_imaging.psf.native == pytest.approx(
            (1.0 / 49.0) * np.ones((7, 7)), 1.0e-4)
        assert masked_imaging.convolver.kernel.shape_native == (7, 7)
        assert (masked_imaging.image == np.array([1.0])).all()
        assert (masked_imaging.noise_map == np.array([2.0])).all()
Ejemplo n.º 5
0
def _imaging_from(fit: af.Fit, settings_imaging: Optional[aa.SettingsImaging] = None):
    """
    Returns a `Imaging` object from an aggregator's `SearchOutput` class, which we call an 'agg_obj' to describe
    that it acts as the aggregator object for one result in the `Aggregator`. This uses the aggregator's generator
    outputs such that the function can use the `Aggregator`'s map function to to create a `Imaging` generator.

     The `Imaging` is created following the same method as the PyAutoGalaxy `Search` classes, including using the
    `SettingsImaging` instance output by the Search to load inputs of the `Imaging` (e.g. psf_shape_2d).

    Parameters
    ----------
    fit : ImaginSearchOutput
        A PyAutoFit aggregator's SearchOutput object containing the generators of the results of PyAutoGalaxy model-fits.
    """

    data = fit.value(name="data")
    noise_map = fit.value(name="noise_map")
    psf = fit.value(name="psf")
    settings_imaging = settings_imaging or fit.value(name="settings_dataset")

    if not hasattr(settings_imaging, "relative_accuracy"):
        settings_imaging.relative_accuracy = None

    imaging = aa.Imaging(
        image=data,
        noise_map=noise_map,
        psf=psf,
        settings=settings_imaging,
        pad_for_convolver=True,
    )

    imaging.apply_settings(settings=settings_imaging)

    return imaging
Ejemplo n.º 6
0
    def test__image_and_model_are_different__include_masking__check_values_are_correct(
        self, ):

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

        data = aa.Array2D.manual_mask(array=[1.0, 2.0, 4.0], mask=mask)
        noise_map = aa.Array2D.manual_mask(array=[2.0, 2.0, 2.0], mask=mask)

        imaging = aa.Imaging(image=data, noise_map=noise_map)

        model_image = aa.Array2D.manual_mask(array=[1.0, 2.0, 3.0], mask=mask)

        fit = aa.FitImaging(imaging=imaging,
                            model_image=model_image,
                            use_mask_in_fit=False)

        assert (fit.mask == np.array([[False, False], [True, False]])).all()

        assert (fit.image.slim == np.array([1.0, 2.0, 4.0])).all()
        assert (fit.image.native == np.array([[1.0, 2.0], [0.0, 4.0]])).all()

        assert (fit.noise_map.slim == np.array([2.0, 2.0, 2.0])).all()
        assert (fit.noise_map.native == np.array([[2.0, 2.0], [0.0,
                                                               2.0]])).all()

        assert (fit.signal_to_noise_map.slim == np.array([0.5, 1.0,
                                                          2.0])).all()
        assert (fit.signal_to_noise_map.native == np.array([[0.5, 1.0],
                                                            [0.0,
                                                             2.0]])).all()

        assert (fit.model_image.slim == np.array([1.0, 2.0, 3.0])).all()
        assert (fit.model_image.native == np.array([[1.0, 2.0], [0.0,
                                                                 3.0]])).all()

        assert (fit.residual_map.slim == np.array([0.0, 0.0, 1.0])).all()
        assert (fit.residual_map.native == np.array([[0.0, 0.0],
                                                     [0.0, 1.0]])).all()

        assert (fit.normalized_residual_map.slim == np.array([0.0, 0.0,
                                                              0.5])).all()
        assert (fit.normalized_residual_map.native == np.array([[0.0, 0.0],
                                                                [0.0,
                                                                 0.5]])).all()

        assert (fit.chi_squared_map.slim == np.array([0.0, 0.0, 0.25])).all()
        assert (fit.chi_squared_map.native == np.array([[0.0, 0.0],
                                                        [0.0, 0.25]])).all()

        assert fit.chi_squared == 0.25
        assert fit.reduced_chi_squared == 0.25 / 3.0
        assert fit.noise_normalization == np.sum(
            np.log(2 * np.pi * noise_map**2.0))
        assert fit.log_likelihood == -0.5 * (fit.chi_squared +
                                             fit.noise_normalization)
Ejemplo n.º 7
0
    def test__psf_and_mask_hit_edge__automatically_pads_image_and_noise_map(
            self):

        image = aa.Array2D.ones(shape_native=(3, 3), pixel_scales=1.0)
        noise_map = aa.Array2D.ones(shape_native=(3, 3), pixel_scales=1.0)
        psf = aa.Kernel2D.ones(shape_native=(3, 3), pixel_scales=1.0)

        imaging = aa.Imaging(image=image,
                             noise_map=noise_map,
                             psf=psf,
                             setup_convolver=False)

        assert imaging.image.shape_native == (3, 3)
        assert imaging.noise_map.shape_native == (3, 3)

        imaging = aa.Imaging(image=image,
                             noise_map=noise_map,
                             psf=psf,
                             setup_convolver=True)

        assert imaging.image.shape_native == (5, 5)
        assert imaging.noise_map.shape_native == (5, 5)
        assert imaging.image.mask[0, 0] == True
        assert imaging.image.mask[1, 1] == False
Ejemplo n.º 8
0
    def test__image_and_model_are_identical__inversion_included__changes_certain_properties(
        self, ):

        mask = aa.Mask2D.manual(mask=[[False, False], [False, False]],
                                sub_size=1,
                                pixel_scales=(1.0, 1.0))

        data = aa.Array2D.manual_mask(array=[1.0, 2.0, 3.0, 4.0], mask=mask)
        noise_map = aa.Array2D.manual_mask(array=[2.0, 2.0, 2.0, 2.0],
                                           mask=mask)

        imaging = aa.Imaging(image=data, noise_map=noise_map)

        masked_imaging = imaging.apply_mask(mask=mask)

        model_image = aa.Array2D.manual_mask(array=[1.0, 2.0, 3.0, 4.0],
                                             mask=mask)

        inversion = mock.MockFitInversion(
            regularization_term=2.0,
            log_det_curvature_reg_matrix_term=3.0,
            log_det_regularization_matrix_term=4.0,
        )

        fit = aa.FitImaging(
            imaging=masked_imaging,
            model_image=model_image,
            inversion=inversion,
            use_mask_in_fit=False,
        )

        assert fit.chi_squared == 0.0
        assert fit.reduced_chi_squared == 0.0
        assert fit.noise_normalization == np.sum(
            np.log(2 * np.pi * noise_map**2.0))
        assert fit.log_likelihood == -0.5 * (fit.chi_squared +
                                             fit.noise_normalization)

        assert fit.log_likelihood_with_regularization == -0.5 * (
            fit.chi_squared + 2.0 + fit.noise_normalization)
        assert fit.log_evidence == -0.5 * (fit.chi_squared + 2.0 + 3.0 - 4.0 +
                                           fit.noise_normalization)
        assert fit.figure_of_merit == fit.log_evidence
    def test__15_grid__no_sub_grid(self):

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

        # There is no sub-grid, so our grid are just the masked_image grid (note the NumPy weighted_data structure
        # ensures this has no sub-gridding)
        grid = aa.Grid2D.manual_mask(
            grid=[
                [0.9, -0.9],
                [1.0, -1.0],
                [1.1, -1.1],
                [0.9, 0.9],
                [1.0, 1.0],
                [1.1, 1.1],
                [-0.01, 0.01],
                [0.0, 0.0],
                [0.01, 0.01],
                [-0.9, -0.9],
                [-1.0, -1.0],
                [-1.1, -1.1],
                [-0.9, 0.9],
                [-1.0, 1.0],
                [-1.1, 1.1],
            ],
            mask=mask,
        )

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

        mapper = pix.mapper_from_grid_and_sparse_grid(
            grid=grid,
            sparse_grid=None,
            settings=aa.SettingsPixelization(use_border=False),
        )

        assert mapper.data_pixelization_grid == None
        assert mapper.source_pixelization_grid.shape_native_scaled == pytest.approx(
            (2.2, 2.2), 1.0e-4)
        assert mapper.source_pixelization_grid.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],
            [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, 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, 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, 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, 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],
        ])).all()
        assert mapper.shape_native == (3, 3)

        reg = aa.reg.Constant(coefficient=1.0)
        regularization_matrix = reg.regularization_matrix_from_mapper(
            mapper=mapper)

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

        image = aa.Array2D.ones(shape_native=(7, 7), pixel_scales=1.0)
        noise_map = aa.Array2D.ones(shape_native=(7, 7), pixel_scales=1.0)
        psf = aa.Kernel2D.no_blur(pixel_scales=1.0)

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

        masked_imaging = imaging.apply_mask(mask=mask)

        inversion = aa.Inversion(
            dataset=masked_imaging,
            mapper=mapper,
            regularization=reg,
            settings=aa.SettingsInversion(check_solution=False),
        )

        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(15), 1.0e-4)
Ejemplo n.º 10
0
    def test__3x3_simple_grid__include_mask_with_offset_centre(self):

        mask = aa.Mask2D.manual(
            mask=[
                [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.Grid2D.manual_mask(grid=grid, mask=mask)

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

        mapper = pix.mapper_from_grid_and_sparse_grid(
            grid=grid,
            sparse_grid=sparse_grid,
            settings=aa.SettingsPixelization(use_border=False),
        )

        assert mapper.source_pixelization_grid.shape_native_scaled == pytest.approx(
            (2.0, 2.0), 1.0e-4)
        assert (mapper.source_pixelization_grid == sparse_grid).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.Array2D.ones(shape_native=(7, 7), pixel_scales=1.0)
        noise_map = aa.Array2D.ones(shape_native=(7, 7), pixel_scales=1.0)
        psf = aa.Kernel2D.no_blur(pixel_scales=1.0)

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

        masked_imaging = imaging.apply_mask(mask=mask)

        inversion = aa.Inversion(
            dataset=masked_imaging,
            mapper=mapper,
            regularization=reg,
            settings=aa.SettingsInversion(check_solution=False),
        )

        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)
Ejemplo n.º 11
0
    def test__5_simple_grid__include_sub_grid(self):

        mask = aa.Mask2D.manual(
            mask=[
                [True, True, True, True, True, True, 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],
            ],
            pixel_scales=2.0,
            sub_size=2,
        )

        # 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 lens calculation. This is to make a mapping_matrix matrix which explicitly tests the
        # sub-grid.
        grid = aa.Grid2D.manual_mask(
            grid=[
                [1.0, -1.0],
                [1.0, -1.0],
                [1.0, -1.0],
                [1.0, 1.0],
                [1.0, 1.0],
                [1.0, 1.0],
                [-1.0, -1.0],
                [-1.0, -1.0],
                [-1.0, -1.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],
                [0.0, 0.0],
                [0.0, 0.0],
                [0.0, 0.0],
            ],
            mask=mask,
        )

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

        mapper = pix.mapper_from_grid_and_sparse_grid(
            grid=grid,
            sparse_grid=None,
            settings=aa.SettingsPixelization(use_border=False),
        )

        assert mapper.data_pixelization_grid == None
        assert mapper.source_pixelization_grid.shape_native_scaled == pytest.approx(
            (2.0, 2.0), 1.0e-4)
        assert mapper.source_pixelization_grid.origin == pytest.approx(
            (0.0, 0.0), 1.0e-4)

        assert (mapper.mapping_matrix == np.array([
            [0.75, 0.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            [0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0],
            [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.75],
            [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],
        ])).all()
        assert mapper.shape_native == (3, 3)

        reg = aa.reg.Constant(coefficient=1.0)
        regularization_matrix = reg.regularization_matrix_from_mapper(
            mapper=mapper)

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

        image = aa.Array2D.ones(shape_native=(7, 7), pixel_scales=1.0)
        noise_map = aa.Array2D.ones(shape_native=(7, 7), pixel_scales=1.0)
        psf = aa.Kernel2D.no_blur(pixel_scales=1.0)

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

        masked_imaging = imaging.apply_mask(mask=mask)

        inversion = aa.Inversion(
            dataset=masked_imaging,
            mapper=mapper,
            regularization=reg,
            settings=aa.SettingsInversion(check_solution=False),
        )

        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)