How to use the autolens.Tracer.from_galaxies function in autolens

To help you get started, we’ve selected a few autolens examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jammy2211 / PyAutoLens / test_autolens / plot / inversions / rectangular.py View on Github external
centre=(0.0, 0.0),
)

lens_galaxy = al.Galaxy(
    redshift=0.5, mass=al.mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.6)
)

source_galaxy = al.Galaxy(
    redshift=1.0,
    pixelization=al.pix.Rectangular(shape=(20, 20)),
    regularization=al.reg.Constant(coefficient=1.0),
)

masked_imaging = al.MaskedImaging(imaging=imaging, mask=mask)

tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])
fit = al.FitImaging(masked_imaging=masked_imaging, tracer=tracer)

aplt.FitImaging.subplot_of_galaxy(
    fit=fit,
    galaxy_index=1,
    plot_in_kpc=True,
    include_image_plane_pix=True,
    include_caustics=True,
)

aplt.FitImaging.subplot_of_galaxy(
    fit=fit,
    galaxy_index=1,
    plot_in_kpc=False,
    include_image_plane_pix=True,
    include_caustics=True,
github Jammy2211 / PyAutoLens / test_autolens / unit / fit / test_lens_interferometer_fit.py View on Github external
interferometer=interferometer, mask=mask
        )

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

        g0 = al.Galaxy(
            redshift=0.5,
            light_profile=al.lp.EllipticalSersic(intensity=0.001),
        )

        profile_image = g0.profile_image_from_grid(grid=masked_interferometer_6x6.grid)
        model_visibilities_manual = transformer.visibilities_from_image(
            image=profile_image
        )

        tracer = al.Tracer.from_galaxies(galaxies=[g0])

        fit = al.LensUVPlaneFit.from_masked_data_and_tracer(
            lens_data=masked_interferometer_6x6, tracer=tracer
        )

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

        assert (fit._data == np.array([[5.0, 5.0], [5.0, 5.0], [5.0, 5.0]])).all()
        assert (
            fit.visibilities() == np.array([[[5.0, 5.0], [5.0, 5.0], [5.0, 5.0]]])
        ).all()
        assert (
            fit._noise_map == np.array([[[2.0, 2.0], [2.0, 2.0], [2.0, 2.0]]])
        ).all()
        assert (
            fit.noise_map() == np.array([[[2.0, 2.0], [2.0, 2.0], [2.0, 2.0]]])
github Jammy2211 / PyAutoLens / test_autolens / unit / fit / test_lens_interferometer_fit.py View on Github external
def test___all_lens_fit_quantities__no_hyper_methods(self, masked_interferometer_6x6):

        g0 = al.Galaxy(
            redshift=0.5,
            light_profile=al.lp.EllipticalSersic(intensity=1.0),
            mass_profile=al.mp.SphericalIsothermal(einstein_radius=1.0),
        )

        g1 = al.Galaxy(
            redshift=1.0,
            light_profile=al.lp.EllipticalSersic(intensity=1.0),
        )

        tracer = al.Tracer.from_galaxies(galaxies=[g0, g1])

        fit = al.LensUVPlaneFit.from_masked_data_and_tracer(
            lens_data=masked_interferometer_6x6, tracer=tracer
        )

        assert masked_interferometer_6x6.noise_map(return_x2=True) == pytest.approx(
            fit.noise_map()
        )

        model_visibilities = tracer.profile_visibilities_from_grid_and_transformer(
            grid=masked_interferometer_6x6.grid, transformer=masked_interferometer_6x6.transformer
        )

        assert model_visibilities == pytest.approx(fit._model_data, 1e-4)
        assert model_visibilities == pytest.approx(fit.model_visibilities(), 1e-4)
github Jammy2211 / PyAutoLens / test_autolens / unit / fit / test_fit.py View on Github external
def test___blurred_and_model_images_of_planes_and_unmasked_blurred_image_properties(
            self, masked_imaging_7x7_grid
        ):

            g0 = al.Galaxy(
                redshift=0.5,
                light_profile=al.lp.EllipticalSersic(intensity=1.0),
                mass_profile=al.mp.SphericalIsothermal(einstein_radius=1.0),
            )

            g1 = al.Galaxy(
                redshift=1.0, light_profile=al.lp.EllipticalSersic(intensity=1.0)
            )

            tracer = al.Tracer.from_galaxies(galaxies=[g0, g1])

            fit = al.FitImaging(masked_imaging=masked_imaging_7x7_grid, tracer=tracer)

            blurred_images_of_planes = tracer.blurred_images_of_planes_from_grid_and_convolver(
                grid=masked_imaging_7x7_grid.grid,
                convolver=masked_imaging_7x7_grid.convolver,
                blurring_grid=masked_imaging_7x7_grid.blurring_grid,
            )

            assert blurred_images_of_planes[0].in_2d == pytest.approx(
                fit.model_images_of_planes[0].in_2d, 1.0e-4
            )

            assert blurred_images_of_planes[1].in_2d == pytest.approx(
                fit.model_images_of_planes[1].in_2d, 1.0e-4
            )
github Jammy2211 / PyAutoLens / test_autolens / numerics / deflections / isothermal.py View on Github external
)

source_galaxy = al.Galaxy(
    redshift=1.0,
    light=al.lp.EllipticalSersic(
        centre=(0.1, 0.1),
        elliptical_comps=(0.096225, -0.055555),
        intensity=0.3,
        effective_radius=1.0,
        sersic_index=2.5,
    ),
)


"""Use these galaxies to setup a tracer, which will generate the image for the simulated imaging dataset."""
tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])

deflections = tracer.deflections_from_grid(grid=grid)

print(deflections)
github Jammy2211 / PyAutoLens / test_autolens / unit / simulator / test_simulator.py View on Github external
simulator = al.simulator.imaging(
            shape_2d=(11, 11),
            pixel_scales=0.2,
            sub_size=1,
            psf=psf,
            exposure_time=100.0,
            background_level=1.0,
            add_noise=False,
            noise_if_add_noise_false=0.2,
        )

        imaging_simulated = simulator.from_galaxies(
            galaxies=[lens_galaxy, source_galaxy]
        )

        tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])

        imaging_manual = al.imaging.simulate(
            image=tracer.padded_profile_image_from_grid_and_psf_shape(
                grid=grid, psf_shape_2d=(7, 7)
            ),
            exposure_time=100.0,
            psf=psf,
            background_level=1.0,
            add_noise=False,
            noise_if_add_noise_false=0.2,
        )

        assert (imaging_manual.image == imaging_simulated.image).all()
        assert (imaging_manual.psf == imaging_simulated.psf).all()
        assert (imaging_simulated.noise_map.in_2d == 0.2 * np.ones((11, 11))).all()
        assert imaging_manual.noise_map == imaging_simulated.noise_map
github Jammy2211 / PyAutoLens / howtolens / simulators / chapter_5 / lens_sie__source_sersic.py View on Github external
),
)

source_galaxy = al.Galaxy(
    redshift=1.0,
    light=al.lp.EllipticalSersic(
        centre=(0.0, 0.0),
        elliptical_comps=(0.2, 0.1),
        intensity=0.2,
        effective_radius=0.2,
        sersic_index=2.5,
    ),
)

"""Use these galaxies to setup a tracer, which will generate the image for the simulated _Imaging_ dataset."""
tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])

"""
We can now pass this simulator a tracer, which creates the ray-traced image plotted above and simulates it as an
imaging dataset.
"""
imaging = simulator.from_tracer_and_grid(tracer=tracer, grid=grid)

"""Finally, lets output our simulated dataset to the dataset path as .fits files"""
imaging.output_to_fits(
    image_path=f"{dataset_path}/image.fits",
    psf_path=f"{dataset_path}/psf.fits",
    noise_map_path=f"{dataset_path}/noise_map.fits",
    overwrite=True,
)
github Jammy2211 / PyAutoLens / docs / api / scripts / lensing / tracer.py View on Github external
isothermal_mass_profile = al.mp.EllipticalIsothermal(
    centre=(0.0, 0.0), axis_ratio=0.8, phi=120.0, einstein_radius=1.6
)

another_light_profile = al.lp.EllipticalExponential(
    centre=(0.05, 0.1), axis_ratio=0.6, phi=60.0, intensity=1.0, effective_radius=0.5
)

lens_galaxy = al.Galaxy(
    redshift=0.5, light=sersic_light_profile, mass=isothermal_mass_profile
)

source_galaxy = al.Galaxy(redshift=1.0, light=another_light_profile)

tracer = al.Tracer.from_galaxies(
    galaxies=[lens_galaxy, source_galaxy], cosmology=cosmo.Planck15
)

plotter = aplt.Plotter(
    labels=aplt.Labels(title="Image of Strong Lensing System (Lens & Source Galaxies)"),
    output=aplt.Output(path=plot_path, filename="tracer_image", format="png"),
)

aplt.Tracer.profile_image(tracer=tracer, grid=grid, plotter=plotter)
github Jammy2211 / PyAutoLens / autolens / aggregator / aggregator.py View on Github external
max_log_likelihood_instance = samples.max_log_likelihood_instance
    galaxies = max_log_likelihood_instance.galaxies

    if phase_attributes.hyper_galaxy_image_path_dict is not None:

        for (
            galaxy_path,
            galaxy,
        ) in max_log_likelihood_instance.path_instance_tuples_for_class(al.Galaxy):
            if galaxy_path in phase_attributes.hyper_galaxy_image_path_dict:
                galaxy.hyper_model_image = phase_attributes.hyper_model_image
                galaxy.hyper_galaxy_image = phase_attributes.hyper_galaxy_image_path_dict[
                    galaxy_path
                ]

    return al.Tracer.from_galaxies(galaxies=galaxies)
github Jammy2211 / PyAutoLens / howtolens / simulators / chapter_5 / lens_sersic_sie__source_sersic.py View on Github external
),
)

source_galaxy = al.Galaxy(
    redshift=1.0,
    light=al.lp.EllipticalSersic(
        centre=(0.0, 0.0),
        elliptical_comps=(0.2, 0.1),
        intensity=0.2,
        effective_radius=0.2,
        sersic_index=2.5,
    ),
)

"""Use these galaxies to setup a tracer, which will generate the image for the simulated _Imaging_ dataset."""
tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])

"""
We can now pass this simulator a tracer, which creates the ray-traced image plotted above and simulates it as an
imaging dataset.
"""
imaging = simulator.from_tracer_and_grid(tracer=tracer, grid=grid)

"""Finally, lets output our simulated dataset to the dataset path as .fits files"""
imaging.output_to_fits(
    image_path=f"{dataset_path}/image.fits",
    psf_path=f"{dataset_path}/psf.fits",
    noise_map_path=f"{dataset_path}/noise_map.fits",
    overwrite=True,
)