How to use the autolens.lens.plane.Plane 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 / unit / lens / test_plane.py View on Github external
def test__has_mass_profile(self):
            plane = pl.Plane(galaxies=[g.Galaxy(redshift=0.5)], redshift=None)
            assert plane.has_mass_profile is False

            plane = pl.Plane(
                galaxies=[g.Galaxy(redshift=0.5, mass_profile=mp.MassProfile())],
                redshift=None,
            )
            assert plane.has_mass_profile is True

            plane = pl.Plane(
                galaxies=[
                    g.Galaxy(redshift=0.5, mass_profile=mp.MassProfile()),
                    g.Galaxy(redshift=0.5),
                ],
                redshift=None,
            )
            assert plane.has_mass_profile is True
github Jammy2211 / PyAutoLens / test / lens / test_plane.py View on Github external
def test__surface_density_from_plane__same_as_its_mass_profile__use_padded_grid_stack(self, padded_grid_stack, 
                                                                                              galaxy_mass):

            mp = galaxy_mass.mass_profiles[0]

            mp_sub_surface_density = mp.surface_density_from_grid(padded_grid_stack.sub.unlensed_grid)

            # The padded sub-grid adds 5 pixels arounds the mask from the top-left which we skip over, thus our
            # first sub-pixel index is 20.
            mp_surface_density_pixel_0 = (mp_sub_surface_density[20] + mp_sub_surface_density[21] +
                                          mp_sub_surface_density[22] + mp_sub_surface_density[23]) / 4
            mp_surface_density_pixel_1 = (mp_sub_surface_density[24] + mp_sub_surface_density[25] +
                                          mp_sub_surface_density[26] + mp_sub_surface_density[27]) / 4

            plane = pl.Plane(galaxies=[galaxy_mass], grid_stack=padded_grid_stack)

            # The padded array is trimed to the same size as the original mask (1x2).
            assert plane.surface_density[0,0] == pytest.approx(mp_surface_density_pixel_0, 1.0e-4)
            assert plane.surface_density[0,1] == pytest.approx(mp_surface_density_pixel_1, 1.0e-4)
github Jammy2211 / PyAutoLens / test / unit / lens / test_plane.py View on Github external
grid=sub_grid_7x7, return_in_2d=False, return_binned=True
            )

            g1_blurring_image_1d = g1.profile_image_from_grid(
                grid=blurring_grid_7x7, return_in_2d=False, return_binned=True
            )

            blurred_g0_image = convolver_7x7.convolve_image(
                image_array=g0_image_1d, blurring_array=g0_blurring_image_1d
            )

            blurred_g1_image = convolver_7x7.convolve_image(
                image_array=g1_image_1d, blurring_array=g1_blurring_image_1d
            )

            plane = pl.Plane(redshift=0.5, galaxies=[g0, g1])

            blurred_image_1d = plane.blurred_profile_image_from_grid_and_convolver(
                grid=sub_grid_7x7,
                preload_blurring_grid=blurring_grid_7x7,
                convolver=convolver_7x7,
            )

            assert blurred_image_1d == pytest.approx(
                blurred_g0_image + blurred_g1_image, 1.0e-4
            )

            blurred_image_1d = plane.blurred_profile_image_from_grid_and_convolver(
                grid=sub_grid_7x7, convolver=convolver_7x7
            )

            assert blurred_image_1d == pytest.approx(
github Jammy2211 / PyAutoLens / test / unit / lens / test_plane.py View on Github external
g0 = g.Galaxy(
                redshift=0.5,
                mass_profile=mp.SphericalIsothermal(
                    centre=(0.0, 0.0), einstein_radius=1.0
                ),
            )

            g1 = g.Galaxy(
                redshift=0.5,
                mass_profile=mp.SphericalIsothermal(
                    centre=(1.0, 1.0), einstein_radius=2.0
                ),
            )

            plane = pl.Plane(galaxies=[g0, g1], redshift=None)

            jacobian_binned_reg_grid = plane.lensing_jacobian_from_grid(
                grid=grid, return_in_2d=False, return_binned=True
            )
            a11_binned_reg_grid = jacobian_binned_reg_grid[0, 0]

            jacobian_sub_grid = plane.lensing_jacobian_from_grid(
                grid=grid, return_in_2d=False, return_binned=False
            )
            a11_sub_grid = jacobian_sub_grid[0, 0]

            pixel_1_reg_grid = a11_binned_reg_grid[0]
            pixel_1_from_av_sub_grid = (
                a11_sub_grid[0] + a11_sub_grid[1] + a11_sub_grid[2] + a11_sub_grid[3]
            ) / 4
github Jammy2211 / PyAutoLens / test / unit / lens / test_plane.py View on Github external
galaxy_0 = g.Galaxy(
                redshift=0.5,
                hyper_galaxy=hyper_galaxy_0,
                hyper_model_image_1d=hyper_model_image_1d,
                hyper_galaxy_image_1d=hyper_galaxy_image_1d_0,
            )

            galaxy_1 = g.Galaxy(
                redshift=0.5,
                hyper_galaxy=hyper_galaxy_1,
                hyper_model_image_1d=hyper_model_image_1d,
                hyper_galaxy_image_1d=hyper_galaxy_image_1d_1,
            )

            plane = pl.Plane(redshift=0.5, galaxies=[galaxy_0, galaxy_1])

            hyper_noise_maps_1d = plane.hyper_noise_maps_1d_of_galaxies_from_noise_map_1d(
                noise_map_1d=noise_map_1d
            )

            assert (hyper_noise_maps_1d[0] == np.array([0.0, 2.0, 3.0])).all()
            assert hyper_noise_maps_1d[1] == pytest.approx(
                np.array([0.73468, (2.0 * 0.75) ** 2.0, 3.0 ** 2.0]), 1.0e-4
            )
github Jammy2211 / PyAutoLens / test / unit / lens / test_plane.py View on Github external
+ mp1_sub_image[7, 0]
            ) / 4
            mp1_image_pixel_0y = (
                mp1_sub_image[0, 1]
                + mp1_sub_image[1, 1]
                + mp1_sub_image[2, 1]
                + mp1_sub_image[3, 1]
            ) / 4
            mp1_image_pixel_1y = (
                mp1_sub_image[4, 1]
                + mp1_sub_image[5, 1]
                + mp1_sub_image[6, 1]
                + mp1_sub_image[7, 1]
            ) / 4

            plane = pl.Plane(galaxies=[g0, g1], redshift=None)

            deflections = plane.deflections_from_grid(
                grid=sub_grid_7x7, return_in_2d=False, return_binned=True
            )

            assert deflections[0, 0] == pytest.approx(
                mp0_image_pixel_0x + mp1_image_pixel_0x, 1.0e-4
            )
            assert deflections[1, 0] == pytest.approx(
                mp0_image_pixel_1x + mp1_image_pixel_1x, 1.0e-4
            )
            assert deflections[0, 1] == pytest.approx(
                mp0_image_pixel_0y + mp1_image_pixel_0y, 1.0e-4
            )
            assert deflections[1, 1] == pytest.approx(
                mp0_image_pixel_1y + mp1_image_pixel_1y, 1.0e-4
github Jammy2211 / PyAutoLens / test / lens / test_plane.py View on Github external
def test__same_as_above__x2_galaxy_in_plane__or_galaxy_x2_sis__deflections_double(self, grid_stack,
                                                                                          galaxy_mass,
                                                                                          galaxy_mass_x2):

            plane = pl.Plane(galaxies=[galaxy_mass_x2], grid_stack=grid_stack, compute_deflections=True)

            sub_galaxy_deflections = galaxy_mass_x2.deflections_from_grid(grid_stack.sub)
            blurring_galaxy_deflections = galaxy_mass_x2.deflections_from_grid(grid_stack.blurring)

            assert plane.deflection_stack.regular == pytest.approx(np.array([[2.0 * 0.707, 2.0 * 0.707], [2.0, 0.0]]), 1e-3)
            assert (plane.deflection_stack.sub == sub_galaxy_deflections).all()
            assert (plane.deflection_stack.blurring == blurring_galaxy_deflections).all()

            plane = pl.Plane(galaxies=[galaxy_mass, galaxy_mass], grid_stack=grid_stack, compute_deflections=True)

            sub_galaxy_deflections = galaxy_mass.deflections_from_grid(grid_stack.sub)
            blurring_galaxy_deflections = galaxy_mass.deflections_from_grid(grid_stack.blurring)

            assert plane.deflection_stack.regular == pytest.approx(np.array([[2.0 * 0.707, 2.0 * 0.707], [2.0, 0.0]]), 1e-3)
            assert (plane.deflection_stack.sub == 2.0 * sub_galaxy_deflections).all()
            assert (plane.deflection_stack.blurring == 2.0 * blurring_galaxy_deflections).all()
github Jammy2211 / PyAutoLens / test / lens / test_ray_tracing.py View on Github external
def test__diffrent_galaxies_no_mass_in_each_plane__image_of_each_galaxy_is_galaxy_image(self, grid_stack):

            sersic = lp.EllipticalSersic(axis_ratio=0.5, phi=0.0, intensity=1.0, effective_radius=0.6, sersic_index=4.0)

            g0 = g.Galaxy(redshift=0.1, light_profile=sersic)
            g1 = g.Galaxy(redshift=1.0, light_profile=sersic)
            g2 = g.Galaxy(redshift=2.0, light_profile=sersic)
            g3 = g.Galaxy(redshift=0.1, light_profile=sersic)
            g4 = g.Galaxy(redshift=1.0, light_profile=sersic)

            tracer = ray_tracing.TracerMultiPlanes(galaxies=[g0, g1, g2, g3, g4],
                                                   image_plane_grid_stack=grid_stack, cosmology=cosmo.Planck15)

            plane_0 = pl.Plane(galaxies=[g0, g3], grid_stack=grid_stack, compute_deflections=True)
            plane_1 = pl.Plane(galaxies=[g1, g4], grid_stack=grid_stack, compute_deflections=True)
            plane_2 = pl.Plane(galaxies=[g2], grid_stack=grid_stack, compute_deflections=False)

            image_plane_blurring_image_1d = plane_0.image_plane_blurring_image_1d + \
                                            plane_1.image_plane_blurring_image_1d + \
                                            plane_2.image_plane_blurring_image_1d

            assert (image_plane_blurring_image_1d == tracer.image_plane_blurring_image_1d).all()
github Jammy2211 / PyAutoLens / test / unit / lens / test_plane.py View on Github external
def test__no_galaxies_with_pixelizations_in_plane__returns_none(
            self, sub_grid_7x7
        ):
            galaxy_no_pix = g.Galaxy(redshift=0.5)

            plane = pl.Plane(galaxies=[galaxy_no_pix], redshift=0.5)

            mapper = plane.mapper_from_grid_and_pixelization_grid(
                grid=sub_grid_7x7, pixelization_grid=sub_grid_7x7
            )

            assert mapper is None
github Jammy2211 / PyAutoLens / autolens / lens / plane.py View on Github external
def __init__(self, redshift=None, galaxies=None, cosmology=cosmo.Planck15):

        super(Plane, self).__init__(
            redshift=redshift, galaxies=galaxies, cosmology=cosmology
        )