def test__interferometer_generator_from_aggregator(
    visibilities_7,
    visibilities_noise_map_7,
    uv_wavelengths_7x2,
    mask_2d_7x7,
    samples,
    model,
):

    path_prefix = "aggregator_interferometer"

    database_file = path.join(conf.instance.output_path,
                              "interferometer.sqlite")
    result_path = path.join(conf.instance.output_path, path_prefix)

    clean(database_file=database_file, result_path=result_path)

    interferometer_7 = ag.Interferometer(
        visibilities=visibilities_7,
        noise_map=visibilities_noise_map_7,
        uv_wavelengths=uv_wavelengths_7x2,
        real_space_mask=mask_2d_7x7,
        settings=ag.SettingsInterferometer(
            grid_class=ag.Grid2DIterate,
            grid_inversion_class=ag.Grid2DIterate,
            fractional_accuracy=0.5,
            sub_steps=[2],
            transformer_class=ag.TransformerDFT,
        ),
    )

    search = mock.MockSearch(samples=samples)
    search.paths = af.DirectoryPaths(path_prefix=path_prefix)

    analysis = ag.AnalysisInterferometer(dataset=interferometer_7)

    search.fit(model=model, analysis=analysis)

    agg = af.Aggregator.from_database(filename=database_file)
    agg.add_directory(directory=result_path)

    interferometer_agg = ag.agg.InterferometerAgg(aggregator=agg)
    interferometer_gen = interferometer_agg.interferometer_gen()

    for interferometer in interferometer_gen:
        assert (interferometer.visibilities == interferometer_7.visibilities
                ).all()
        assert (interferometer.real_space_mask == mask_2d_7x7).all()
        assert isinstance(interferometer.grid, ag.Grid2DIterate)
        assert isinstance(interferometer.grid_inversion, ag.Grid2DIterate)
        assert interferometer.grid.sub_steps == [2]
        assert interferometer.grid.fractional_accuracy == 0.5
        assert isinstance(interferometer.transformer, ag.TransformerDFT)

    clean(database_file=database_file, result_path=result_path)
示例#2
0
    def test__1x2_image__1x2_visibilities__simple_fourier_transform(self):
        # The image plane image generated by the galaxy is [1.0, 1.0]

        # Thus the chi squared is 4.0**2.0 + 3.0**2.0 = 25.0

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

        interferometer = ag.Interferometer(
            visibilities=ag.Visibilities.full(fill_value=5.0, shape_slim=(1,)),
            noise_map=ag.Visibilities.ones(shape_slim=(1,)),
            uv_wavelengths=np.array([[0.0, 0.0]]),
            real_space_mask=real_space_mask,
            settings=ag.SettingsInterferometer(
                grid_class=ag.Grid2D, sub_size=1, transformer_class=ag.TransformerDFT
            ),
        )

        interferometer.visibilities[0] = 5.0 + 4.0j

        # Setup as a ray trace instance, using a light profile for the galaxy

        g0 = ag.Galaxy(redshift=0.5, light_profile=MockLightProfile(value=1.0, size=2))
        plane = ag.Plane(galaxies=[g0])

        fit = ag.FitInterferometer(interferometer=interferometer, plane=plane)

        assert (fit.visibilities.slim == np.array([5.0 + 4.0j])).all()
        assert (fit.noise_map.slim == np.array([1.0 + 1.0j])).all()
        assert (fit.model_visibilities.slim == np.array([2.0 + 0.0j])).all()
        assert (fit.residual_map.slim == np.array([3.0 + 4.0j])).all()
        assert (fit.normalized_residual_map.slim == np.array([3.0 + 4.0j])).all()
        assert (fit.chi_squared_map.slim == np.array([9.0 + 16.0j])).all()

        assert fit.chi_squared == 25.0
        assert fit.noise_normalization == pytest.approx(
            2.0 * np.log(2 * np.pi * 1.0 ** 2.0), 1.0e-4
        )
        assert fit.log_likelihood == pytest.approx(
            -0.5 * (25.0 + 2.0 * np.log(2 * np.pi * 1.0 ** 2.0)), 1.0e-4
        )
示例#3
0
def interferometer_via_database_from(
    fit: Fit,
    real_space_mask: Optional[ag.Mask2D] = None,
    settings_interferometer: Optional[ag.SettingsInterferometer] = None,
):
    """
    Returns a `Interferometer` 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
    `Interferometer` generator.

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

    Parameters
    ----------
    fit : af.SearchOutput
        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")
    uv_wavelengths = fit.value(name="uv_wavelengths")
    real_space_mask = real_space_mask or fit.value(name="real_space_mask")
    settings_interferometer = settings_interferometer or fit.value(
        name="settings_dataset"
    )

    interferometer = ag.Interferometer(
        visibilities=data,
        noise_map=noise_map,
        uv_wavelengths=uv_wavelengths,
        real_space_mask=real_space_mask,
    )

    interferometer = interferometer.apply_settings(settings=settings_interferometer)

    return interferometer
示例#4
0
    def test__hyper_background_changes_background_sky__reflected_in_likelihood(self,):
        uv_wavelengths = np.array([[1.0, 0.0], [1.0, 1.0], [2.0, 2.0]])

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

        interferometer = ag.Interferometer(
            visibilities=ag.Visibilities.full(fill_value=5.0, shape_slim=(3,)),
            noise_map=ag.Visibilities.full(fill_value=2.0, shape_slim=(3,)),
            uv_wavelengths=uv_wavelengths,
            real_space_mask=real_space_mask,
            settings=ag.SettingsInterferometer(grid_class=ag.Grid2D, sub_size=1),
        )

        # Setup as a ray trace instance, using a light profile for the galaxy

        g0 = ag.Galaxy(redshift=0.5, light_profile=MockLightProfile(value=1.0, size=2))
        plane = ag.Plane(galaxies=[g0])

        hyper_background_noise = ag.hyper_data.HyperBackgroundNoise(noise_scale=1.0)

        fit = ag.FitInterferometer(
            interferometer=interferometer,
            plane=plane,
            hyper_background_noise=hyper_background_noise,
        )

        assert (
            fit.visibilities.slim == np.array([5.0 + 5.0j, 5.0 + 5.0j, 5.0 + 5.0j])
        ).all()

        assert (
            fit.noise_map.slim == np.array([3.0 + 3.0j, 3.0 + 3.0j, 3.0 + 3.0j])
        ).all()