Ejemplo n.º 1
0
        def test__within_circle__no_conversion_factor__two_profile_gal__integral_is_sum_of_individual_profiles(
                self):

            sie_0 = mp.EllipticalIsothermal(axis_ratio=0.8,
                                            phi=10.0,
                                            einstein_radius=1.0)
            sie_1 = mp.EllipticalIsothermal(axis_ratio=0.6,
                                            phi=30.0,
                                            einstein_radius=1.2)

            integral_radius = 5.5

            mass_integral = sie_0.mass_within_circle(radius=integral_radius)
            mass_integral += sie_1.mass_within_circle(radius=integral_radius)

            gal_sie = g.Galaxy(
                redshift=0.5,
                mass_profile_1=mp.EllipticalIsothermal(axis_ratio=0.8,
                                                       phi=10.0,
                                                       einstein_radius=1.0),
                mass_profile_2=mp.EllipticalIsothermal(axis_ratio=0.6,
                                                       phi=30.0,
                                                       einstein_radius=1.2))

            gal_mass_integral = gal_sie.mass_within_circle(
                radius=integral_radius)

            assert mass_integral == gal_mass_integral
def simulate():

    from autolens.data.array import grids
    from autolens.model.galaxy import galaxy as g
    from autolens.lens import ray_tracing

    psf = ccd.PSF.simulate_as_gaussian(shape=(11, 11),
                                       sigma=0.05,
                                       pixel_scale=0.05)

    image_plane_grid_stack = grids.GridStack.grid_stack_for_simulation(
        shape=(180, 180), pixel_scale=0.05, psf_shape=(11, 11))

    lens_galaxy_0 = g.Galaxy(light=lp.EllipticalSersic(centre=(0.0, -1.0),
                                                       axis_ratio=0.8,
                                                       phi=55.0,
                                                       intensity=0.1,
                                                       effective_radius=0.8,
                                                       sersic_index=2.5),
                             mass=mp.EllipticalIsothermal(centre=(1.0, 0.0),
                                                          axis_ratio=0.7,
                                                          phi=45.0,
                                                          einstein_radius=1.0))

    lens_galaxy_1 = g.Galaxy(light=lp.EllipticalSersic(centre=(0.0, 1.0),
                                                       axis_ratio=0.8,
                                                       phi=100.0,
                                                       intensity=0.1,
                                                       effective_radius=0.6,
                                                       sersic_index=3.0),
                             mass=mp.EllipticalIsothermal(centre=(-1.0, 0.0),
                                                          axis_ratio=0.8,
                                                          phi=90.0,
                                                          einstein_radius=0.8))

    source_galaxy = g.Galaxy(light=lp.SphericalExponential(
        centre=(0.05, 0.15), intensity=0.2, effective_radius=0.5))

    tracer = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy_0, lens_galaxy_1],
        source_galaxies=[source_galaxy],
        image_plane_grid_stack=image_plane_grid_stack)

    return ccd.CCDData.simulate(array=tracer.image_plane_image_for_simulation,
                                pixel_scale=0.05,
                                exposure_time=300.0,
                                psf=psf,
                                background_sky_level=0.1,
                                add_noise=True)
def pipeline():

    tools.reset_paths(test_name=test_name, output_path=output_path)

    lens_light = lp.SphericalDevVaucouleurs(centre=(0.0, 0.0),
                                            intensity=0.1,
                                            effective_radius=0.5)
    lens_mass = mp.EllipticalIsothermal(centre=(0.0, 0.0),
                                        axis_ratio=0.8,
                                        phi=80.0,
                                        einstein_radius=1.6)
    source_light = lp.EllipticalSersic(centre=(0.0, 0.0),
                                       axis_ratio=0.6,
                                       phi=90.0,
                                       intensity=1.0,
                                       effective_radius=0.5,
                                       sersic_index=1.0)

    lens_galaxy = galaxy.Galaxy(dev=lens_light, sie=lens_mass)
    source_galaxy = galaxy.Galaxy(sersic=source_light)

    tools.simulate_integration_image(test_name=test_name,
                                     pixel_scale=0.1,
                                     lens_galaxies=[lens_galaxy],
                                     source_galaxies=[source_galaxy],
                                     target_signal_to_noise=30.0)

    ccd_data = ccd.load_ccd_data_from_fits(
        image_path=path + '/data/' + test_name + '/image.fits',
        psf_path=path + '/data/' + test_name + '/psf.fits',
        noise_map_path=path + '/data/' + test_name + '/noise_map.fits',
        pixel_scale=0.1)

    pipeline = make_pipeline(test_name=test_name)
    pipeline.run(data=ccd_data)
Ejemplo n.º 4
0
        def test_1d_symmetry(self):
            isothermal_1 = mp.EllipticalIsothermal(axis_ratio=0.5,
                                                   phi=45.0,
                                                   einstein_radius=1.0)

            isothermal_2 = mp.EllipticalIsothermal(centre=(100, 0),
                                                   axis_ratio=0.5,
                                                   phi=45.0,
                                                   einstein_radius=1.0)

            gal_isothermal = g.Galaxy(redshift=0.5,
                                      mass_profile_1=isothermal_1,
                                      mass_profile_2=isothermal_2)

            assert gal_isothermal.surface_density_from_grid(
                np.array([[1.0,
                           0.0]])) == gal_isothermal.surface_density_from_grid(
                               np.array([[99.0, 0.0]]))

            assert gal_isothermal.surface_density_from_grid(
                np.array([[49.0,
                           0.0]])) == gal_isothermal.surface_density_from_grid(
                               np.array([[51.0, 0.0]]))

            assert gal_isothermal.potential_from_grid(np.array(
                [[1.0, 0.0]])) == pytest.approx(
                    gal_isothermal.potential_from_grid(np.array([[99.0,
                                                                  0.0]])),
                    1e-6)

            assert gal_isothermal.potential_from_grid(np.array(
                [[49.0, 0.0]])) == pytest.approx(
                    gal_isothermal.potential_from_grid(np.array([[51.0,
                                                                  0.0]])),
                    1e-6)

            assert gal_isothermal.deflections_from_grid(np.array([[
                1.0, 0.0
            ]])) == pytest.approx(
                gal_isothermal.deflections_from_grid(np.array([[99.0, 0.0]])),
                1e-6)

            assert gal_isothermal.deflections_from_grid(np.array([[
                49.0, 0.0
            ]])) == pytest.approx(
                gal_isothermal.deflections_from_grid(np.array([[51.0, 0.0]])),
                1e-6)
Ejemplo n.º 5
0
def perform_fit_x2_lenses_with_source_galaxy_mask_and_border(
        source_galaxy, mask, use_border):
    simulate_image_x2_lenses()
    lens_data = ld.LensData(ccd_data=ccd_data, mask=mask)
    lens_galaxy_0 = g.Galaxy(mass=mp.EllipticalIsothermal(
        centre=(1.1, 0.51), axis_ratio=0.9, phi=110.0, einstein_radius=1.07))
    lens_galaxy_1 = g.Galaxy(mass=mp.EllipticalIsothermal(
        centre=(-0.20,
                -0.35), axis_ratio=0.56, phi=16.0, einstein_radius=0.71))

    if use_border:
        border = lens_data.border
    else:
        border = None

    tracer = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy_0, lens_galaxy_1],
        source_galaxies=[source_galaxy],
        image_plane_grid_stack=lens_data.grid_stack,
        border=border)

    return lens_fit.fit_lens_data_with_tracer(lens_data=lens_data,
                                              tracer=tracer)
Ejemplo n.º 6
0
def make_no_lens_source_cuspy(sub_grid_size):

    # This source-only system has a smooth source (low Sersic Index) and simple SIE mass profile.

    lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal(centre=(0.0, 0.0), einstein_radius=1.6,
                                                        axis_ratio=0.7, phi=45.0))

    source_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.8, phi=60.0,
                                                       intensity=0.1, effective_radius=0.5, sersic_index=3.0))

    for pixel_scale, shape in zip(pixel_scales, shapes):

        simulate_image_from_galaxies_and_output_to_fits(lens_name='no_lens_source_cuspy', shape=shape,
                                                        pixel_scale=pixel_scale, sub_grid_size=sub_grid_size,
                                                        lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy])
def perform_fit_with_source_galaxy(source_galaxy):

    ccd_data = simulate()
    mask = msk.Mask.circular_annular(shape=ccd_data.shape,
                                     pixel_scale=ccd_data.pixel_scale,
                                     inner_radius_arcsec=0.5,
                                     outer_radius_arcsec=2.2)
    lens_data = ld.LensData(ccd_data=ccd_data, mask=mask)
    lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal(
        centre=(0.0, 0.0), axis_ratio=0.8, phi=135.0, einstein_radius=1.6))
    tracer = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy],
        source_galaxies=[source_galaxy],
        image_plane_grid_stack=lens_data.grid_stack,
        border=lens_data.border)
    return lens_fit.fit_lens_data_with_tracer(lens_data=lens_data,
                                              tracer=tracer)
Ejemplo n.º 8
0
def perform_fit_with_source_galaxy_mask_and_border(source_galaxy, mask,
                                                   use_border):

    ccd_data = simulate()
    lens_data = ld.LensData(ccd_data=ccd_data, mask=mask)
    lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal(
        centre=(0.0, 0.0), axis_ratio=0.8, phi=135.0, einstein_radius=1.6))

    if use_border:
        border = lens_data.border
    else:
        border = None

    tracer = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy],
        source_galaxies=[source_galaxy],
        image_plane_grid_stack=lens_data.grid_stack,
        border=border)
    return lens_fit.fit_lens_data_with_tracer(lens_data=lens_data,
                                              tracer=tracer)
Ejemplo n.º 9
0
def pipeline():

    lens_mass = mp.EllipticalIsothermal(centre=(0.01, 0.01),
                                        axis_ratio=0.8,
                                        phi=80.0,
                                        einstein_radius=1.6)

    source_bulge_0 = lp.EllipticalSersic(centre=(0.01, 0.01),
                                         axis_ratio=0.9,
                                         phi=90.0,
                                         intensity=1.0,
                                         effective_radius=1.0,
                                         sersic_index=4.0)

    source_bulge_1 = lp.EllipticalSersic(centre=(0.1, 0.1),
                                         axis_ratio=0.9,
                                         phi=90.0,
                                         intensity=1.0,
                                         effective_radius=1.0,
                                         sersic_index=4.0)

    lens_galaxy = galaxy.Galaxy(sie=lens_mass)
    source_galaxy = galaxy.Galaxy(bulge_0=source_bulge_0,
                                  bulge_1=source_bulge_1)

    tools.reset_paths(test_name=test_name, output_path=output_path)
    tools.simulate_integration_image(test_name=test_name,
                                     pixel_scale=0.1,
                                     lens_galaxies=[lens_galaxy],
                                     source_galaxies=[source_galaxy],
                                     target_signal_to_noise=30.0)

    ccd_data = ccd.load_ccd_data_from_fits(
        image_path=path + '/data/' + test_name + '/image.fits',
        psf_path=path + '/data/' + test_name + '/psf.fits',
        noise_map_path=path + '/data/' + test_name + '/noise_map.fits',
        pixel_scale=0.1)

    pipeline = make_pipeline(test_name=test_name)
    pipeline.run(data=ccd_data)
Ejemplo n.º 10
0
def make_sie_1():
    return mp.EllipticalIsothermal(axis_ratio=0.6,
                                   phi=30.0,
                                   einstein_radius=1.2)
Ejemplo n.º 11
0
def make_sie_0():
    return mp.EllipticalIsothermal(axis_ratio=0.8,
                                   phi=10.0,
                                   einstein_radius=1.0)
Ejemplo n.º 12
0
def test__simulate_lensed_source_and_fit__include_psf_blurring__chi_squared_is_0__noise_normalization_correct(
):

    psf = ccd.PSF.simulate_as_gaussian(shape=(3, 3),
                                       pixel_scale=0.2,
                                       sigma=0.75)

    grid_stack = grids.GridStack.grid_stack_for_simulation(shape=(11, 11),
                                                           pixel_scale=0.2,
                                                           psf_shape=psf.shape,
                                                           sub_grid_size=1)

    lens_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.1, 0.1),
                                                     intensity=0.1),
                           mass=mp.EllipticalIsothermal(centre=(0.1, 0.1),
                                                        einstein_radius=1.8))
    source_galaxy = g.Galaxy(
        light=lp.EllipticalExponential(centre=(0.1, 0.1), intensity=0.5))
    tracer = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy],
        source_galaxies=[source_galaxy],
        image_plane_grid_stack=grid_stack)

    ccd_simulated = ccd.CCDData.simulate(
        array=tracer.image_plane_image_for_simulation,
        pixel_scale=0.2,
        exposure_time=300.0,
        psf=psf,
        background_sky_level=None,
        add_noise=False)
    ccd_simulated.noise_map = np.ones(ccd_simulated.image.shape)

    path = "{}/data/simulate_and_fit".format(
        os.path.dirname(os.path.realpath(
            __file__)))  # Setup path so we can output the simulated image.

    try:
        shutil.rmtree(path)
    except FileNotFoundError:
        pass

    if os.path.exists(path) == False:
        os.makedirs(path)

    array_util.numpy_array_to_fits(array=ccd_simulated.image,
                                   file_path=path + '/image.fits')
    array_util.numpy_array_to_fits(array=ccd_simulated.noise_map,
                                   file_path=path + '/noise_map.fits')
    array_util.numpy_array_to_fits(array=psf, file_path=path + '/psf.fits')

    ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/image.fits',
                                           noise_map_path=path +
                                           '/noise_map.fits',
                                           psf_path=path + '/psf.fits',
                                           pixel_scale=0.2)

    mask = msk.Mask.circular(shape=ccd_data.image.shape,
                             pixel_scale=0.2,
                             radius_arcsec=0.8)

    lens_data = ld.LensData(ccd_data=ccd_data, mask=mask, sub_grid_size=1)

    tracer = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy],
        source_galaxies=[source_galaxy],
        image_plane_grid_stack=lens_data.grid_stack)

    fitter = lens_fit.LensProfileFit(lens_data=lens_data, tracer=tracer)

    assert fitter.chi_squared == pytest.approx(0.0, 1e-4)
Ejemplo n.º 13
0
galaxy_plotters.plot_potential(galaxy=galaxy_with_3_mass_profiles, grid=grid_stack.regular)

# Finally, a galaxy can take both light and mass profiles, and there is no limit to how many we pass it.
light_profile_1 = light_profiles.SphericalSersic(centre=(0.0, 0.0), intensity=1.0,
                                                 effective_radius=1.0, sersic_index=1.0)
light_profile_2 = light_profiles.SphericalSersic(centre=(1.0, 1.0), intensity=1.0,
                                                 effective_radius=2.0, sersic_index=2.0)
light_profile_3 = light_profiles.SphericalSersic(centre=(2.0, 2.0), intensity=1.0,
                                                 effective_radius=3.0, sersic_index=3.0)
light_profile_4 = light_profiles.EllipticalSersic(centre=(1.0, -1.0), axis_ratio=0.5, phi=45.0,
                                                  intensity=1.0, effective_radius=1.0, sersic_index=1.0)

mass_profile_1 = mass_profiles.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.0)
mass_profile_2 = mass_profiles.SphericalIsothermal(centre=(1.0, 1.0), einstein_radius=2.0)
mass_profile_3 = mass_profiles.SphericalIsothermal(centre=(2.0, 2.0), einstein_radius=3.0)
mass_profile_4 = mass_profiles.EllipticalIsothermal(centre=(1.0, -1.0), axis_ratio=0.5, phi=45.0,
                                                   einstein_radius=2.0)

galaxy_with_many_profiles = galaxy.Galaxy(light_1=light_profile_1, light_2=light_profile_2,
                                          light_3=light_profile_3, light_4=light_profile_4,
                                           mass_1=mass_profile_1, mass_2=mass_profile_2,
                                           mass_3=mass_profile_3, mass_4=mass_profile_4)

# Suffice to say, the galaxy's images, surface density, potential and deflections look pretty
# interesting.

galaxy_plotters.plot_intensities(galaxy=galaxy_with_many_profiles, grid=grid_stack.regular)
galaxy_plotters.plot_surface_density(galaxy=galaxy_with_many_profiles, grid=grid_stack.regular)
galaxy_plotters.plot_potential(galaxy=galaxy_with_many_profiles, grid=grid_stack.regular)
galaxy_plotters.plot_deflections_y(galaxy=galaxy_with_many_profiles, grid=grid_stack.regular)
galaxy_plotters.plot_deflections_x(galaxy=galaxy_with_many_profiles, grid=grid_stack.regular)
    mass_in_ellipse_SLACS = lens_galaxy_slacs.mass_within_ellipse_in_units(
        major_axis=slacs['b_SIE'][i] / np.sqrt(slacs['q_SIE'][i]),
        unit_mass='solMass',
        redshift_source=slacs['z_source'][i],
        cosmology=cosmo)

    mass_in_ellipse = lens_galaxy.mass_within_ellipse_in_units(
        major_axis=einstein_radius_autolens / np.sqrt(axis_ratio_autolens),
        unit_mass='solMass',
        redshift_source=slacs['z_source'][i],
        cosmology=cosmo)

    sie = mp.EllipticalIsothermal(
        centre=(results.loc[lens[i]]['param']['centre_0'],
                results.loc[lens[i]]['param']['centre_1']),
        axis_ratio=slacs['q_SIE'][i],
        phi=slacs['PA'][i],
        einstein_radius=slacs['b_SIE'][i])

    ## appending einstein mass results
    M_Ein.append(einstein_mass)
    M_Ein_error_hi.append(einstein_mass_error_hi)
    M_Ein_error_low.append(einstein_mass_error_low)
    M_Ein_rescaled.append(einstein_mass_rescaled)
    q_autolens.append(axis_ratio_autolens)
    r_autolens.append(einstein_radius_autolens)
    r_rescaled.append(einstein_radius_rescaled)
    M_ellipse.append(mass_in_ellipse)
    radius_from_area.append(Rad_area)

    q_error_hi.append(q_upper_error)
    pipeline_path='/howtolens/c3_t3_complex_source/')
pipeline_complex_source.run(data=ccd_data)

# Okay, so with 4 sources, we still couldn't get a good a fit to the source that didn't leave residuals. The thing is,
# I did infact simulate the lens with 4 sources. This means that there is a 'perfect fit', somewhere in that parameter
# space, that we unfortunately missed using the pipeline above.
#
# Lets confirm this, by manually fitting the ccd data with the true input model.

lens_data = ld.LensData(ccd_data=ccd_data,
                        mask=msk.Mask.circular(
                            shape=ccd_data.shape,
                            pixel_scale=ccd_data.pixel_scale,
                            radius_arcsec=3.0))

lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal(
    centre=(0.0, 0.0), axis_ratio=0.8, phi=135.0, einstein_radius=1.6))
source_galaxy_0 = g.Galaxy(light=lp.EllipticalSersic(centre=(0.1, 0.1),
                                                     axis_ratio=0.8,
                                                     phi=90.0,
                                                     intensity=0.2,
                                                     effective_radius=1.0,
                                                     sersic_index=1.5))
source_galaxy_1 = g.Galaxy(light=lp.EllipticalSersic(centre=(-0.25, 0.25),
                                                     axis_ratio=0.7,
                                                     phi=45.0,
                                                     intensity=0.1,
                                                     effective_radius=0.2,
                                                     sersic_index=3.0))
source_galaxy_2 = g.Galaxy(light=lp.EllipticalSersic(centre=(0.45, -0.35),
                                                     axis_ratio=0.6,
                                                     phi=90.0,
        lens_plane_source_model_image.append(model_image)
    else:
        slacs = slacs.drop([lens_name[i]], axis=0)

#array_plotters.plot_array(array=image, title='slacs2303+1422')
#array_plotters.plot_array(array=model_image, title='slacs2303+1422 source model image plane')

for i in range(len(SLACS_image)):
    ## galaxies without external shear component
    grid = al.Grid.uniform(shape_2d=lens_plane_source_model_image[i].shape,
                           pixel_scales=0.03,
                           sub_size=4)

    sie = mp.EllipticalIsothermal(
        centre=(results.loc[lens[i]]['param']['centre_0'],
                results.loc[lens[i]]['param']['centre_1']),
        axis_ratio=results.loc[lens[i]]['param']['axis_ratio'],
        phi=results.loc[lens[i]]['param']['phi'],
        einstein_radius=results.loc[lens[i]]['param']['einstein_radius'])

    critical_curves = sie.critical_curves_from_grid(grid=grid)
    caustics = sie.caustics_from_grid(grid=grid)

    critical_curve_tan, critical_curve_rad = critical_curves[
        0], critical_curves[1]
    caustic_tan, caustic_rad = caustics[0], caustics[1]

    # naming for x and y for plotting
    xcritical_tan, ycritical_tan = critical_curve_tan[:,
                                                      1], critical_curve_tan[:,
                                                                             0]
    #    xcritical_rad, ycritical_rad = critical_curve_rad_grid[:,1], critical_curve_rad_grid[:,0]
from autolens.model.profiles import mass_profiles
from autolens.array import grids
from autolens.model.profiles.plotters import profile_plotters

grid = al.Grid.from_shape_pixel_scale_and_sub_size(shape=(100, 100),
                                                   pixel_scale=0.05,
                                                   sub_size=4)

sis_mass_profile = mass_profiles.EllipticalIsothermal(centre=(1.0, 1.0),
                                                      einstein_radius=1.6,
                                                      axis_ratio=0.7)

profile_plotters.plot_convergence(
    mass_profile=sis_mass_profile,
    grid=grid,
    plot_critical_curves=False,
    plot_caustics=False,
)

# galaxy = al.Galaxy(mass=sis_mass_profile, redshift=1)
#
# galaxy_plotters.plot_convergence(
#     galaxy=galaxy,
#     grid=grid,
#     plot_critical_curves=False,
#     plot_caustics=True,
# )
Ejemplo n.º 18
0
sub_grid_size = 4
radius_arcsec = 3.0
psf_shape = (21, 21)

print('sub grid size = ' + str(sub_grid_size))
print('circular mask radius = ' + str(radius_arcsec) + '\n')
print('psf shape = ' + str(psf_shape) + '\n')

lens_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.0, 0.0),
                                                 axis_ratio=0.9,
                                                 phi=45.0,
                                                 intensity=0.5,
                                                 effective_radius=0.8,
                                                 sersic_index=4.0),
                       mass=mp.EllipticalIsothermal(centre=(0.0, 0.0),
                                                    einstein_radius=1.6,
                                                    axis_ratio=0.7,
                                                    phi=45.0))

source_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.0, 0.0),
                                                   axis_ratio=0.8,
                                                   phi=60.0,
                                                   intensity=0.4,
                                                   effective_radius=0.5,
                                                   sersic_index=1.0))

for image_type in ['LSST', 'Euclid', 'HST', 'HST_Up', 'AO']:

    ccd_data = tools.load_profiling_ccd_data(
        image_type=image_type,
        lens_name='lens_and_source_smooth',
        psf_shape=psf_shape)
Ejemplo n.º 19
0
from autolens.model.profiles import mass_profiles as mp
from autolens.array import grids
from autolens.array.util import grid_util
from autolens.lens import plane as pl
from autolens.model.galaxy import galaxy as g

import matplotlib.pyplot as plt
import numpy as np

# setting up grid and mass profile
sie = mp.EllipticalIsothermal(centre=(0.0, 0.0),
                              einstein_radius=1.4,
                              axis_ratio=0.7,
                              phi=40.0)

grid = al.Grid.uniform(shape_2d=(100, 100), pixel_scales=0.05, sub_size=1)

# loading convergence, critical curves, and caustics
kappa = sie.convergence_from_grid(grid=grid, return_in_2d=True)
critical_curves = sie.critical_curves_from_grid(grid=grid)
caustics = sie.caustics_from_grid(grid=grid)

# naming tangential and radial critical curves
critical_curve_tan, critical_curve_rad = critical_curves[0], critical_curves[1]
caustic_tan, caustic_rad = caustics[0], caustics[1]

# converting to pixel grid (incapable of plotting convergence in arcseconds -_________- )
critical_curve_tan_grid = grid_util.grid_arcsec_1d_to_grid_pixels_1d(
    grid_arcsec_1d=critical_curve_tan,
    shape_2d=(100, 100),
    pixel_scales=(0.05, 0.05),
Ejemplo n.º 20
0
print('Grid')
print(lens_data.grid_stack.regular)

# The image, noise-map and grids are masked using the mask and mapped to 1D arrays for fast calcuations.
print(lens_data.image.shape) # This is the original 2D image
print(lens_data.image_1d.shape)
print(lens_data.noise_map_1d.shape)
print(lens_data.grid_stack.regular.shape)

# To fit an image, we need to create an image-plane image using a tracer.
# Lets use the same tracer we simulated the ccd data with (thus, our fit should be 'perfect').

# Its worth noting that below, we use the lens_data's grid-stack to setup the tracer. This ensures that our image-plane
# image will be the same resolution and alignment as our image-data, as well as being masked appropriately.

lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal(centre=(0.0, 0.0), einstein_radius=1.6, axis_ratio=0.7, phi=45.0))
source_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.1, 0.1), axis_ratio=0.8, phi=45.0,
                                                        intensity=1.0, effective_radius=1.0, sersic_index=2.5))
tracer = ray_tracing.TracerImageSourcePlanes(lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy],
                                             image_plane_grid_stack=lens_data.grid_stack)
ray_tracing_plotters.plot_image_plane_image(tracer=tracer)

# To fit the image, we pass the lens data and tracer to the fitting module. This performs the following:

# 1) Blurs the tracer's image-plane image with the lens data's PSF, ensuring that the telescope optics are
#    accounted for by the fit. This creates the fit's 'model_image'.

# 2) Computes the difference between this model_image and the observed image-data, creating the fit's 'residual_map'.

# 3) Divides the residuals by the noise-map and squaring each value, creating the fit's 'chi_squared_map'.
print(image_plane_grid_stack.sub.shape) # Every regular-pixel is sub-gridded by 4x4, so the sub-grid has x16 more coordinates.

# Next, lets setup a lens galaxy. In the previous tutorial, we set up each profile one line at a time. This made
# code long and cumbersome to read. This time we'll setup easy galaxy using one block of code.

# To help us, we've imported the 'light_profiles' and 'mass_profiles' modules as 'lp' and 'mp', and the
# 'galaxy' module as 'g'.

# We'll also give the lens galaxy some attributes we didn't in the last tutorial:

# 1) A light-profile, meaning its light will appear in the image-plane image.
# 2) An external shear, which accounts for the deflection of light due to line-of-sight structures.
# 3) A redshift, which the tracer will use to convert arc second coordinates to kpc.
lens_galaxy = g.Galaxy(light=lp.SphericalSersic(centre=(0.0, 0.0), intensity=2.0, effective_radius=0.5,
                                                sersic_index=2.5),
                       mass=mp.EllipticalIsothermal(centre=(0.0, 0.0), axis_ratio=0.8, phi=90.0, einstein_radius=1.6),
                       shear=mp.ExternalShear(magnitude=0.05, phi=45.0),
                       redshift=0.5)
print(lens_galaxy)

# Lets also create a small satellite galaxy nearby the lens galaxy and at the same redshift.
lens_satellite = g.Galaxy(light=lp.SphericalDevVaucouleurs(centre=(1.0, 0.0), intensity=2.0, effective_radius=0.2),
                          mass=mp.SphericalIsothermal(centre=(1.0, 0.0), einstein_radius=0.4),
                          redshift=0.5)
print(lens_satellite)

# Lets have a quick look at the appearance of our lens galaxy and its satellite
galaxy_plotters.plot_intensities(galaxy=lens_galaxy, grid=image_plane_grid_stack.regular, title='Lens Galaxy')
galaxy_plotters.plot_intensities(galaxy=lens_satellite, grid=image_plane_grid_stack.regular, title='Lens Satellite')

# And their deflection angles - note that the satellite doesn't contribute as much to the deflections
Ejemplo n.º 22
0
print('sub grid size = ' + str(sub_grid_size))
print('circular mask radius = ' + str(radius_arcsec) + '\n')

for image_type in ['LSST', 'Euclid', 'HST', 'HST_Up', 'AO']:

    ccd_data = tools.load_profiling_ccd_data(image_type=image_type, lens_name='no_lens_source_smooth', psf_shape=(3,3))
    mask = msk.Mask.circular(shape=ccd_data.shape, pixel_scale=ccd_data.pixel_scale, radius_arcsec=radius_arcsec)
    lens_data = ld.LensData(ccd_data=ccd_data, mask=mask, sub_grid_size=sub_grid_size)

    print('Deflection angle run times for image type ' + image_type + '\n')
    print('Number of points = ' + str(lens_data.grid_stack.sub.shape[0]) + '\n')
    
    
    ### EllipticalIsothermal ###
    
    mass_profile = mp.EllipticalIsothermal(centre=(0.0, 0.0), axis_ratio=0.8, phi=45.0, einstein_radius=1.0)
    
    start = time.time()
    mass_profile.deflections_from_grid(grid=lens_data.grid_stack.sub)
    diff = time.time() - start
    print("EllipticalIsothermal time = {}".format(diff))
    
    
    ### SphericalIsothermal ###
    
    mass_profile = mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.0)
    
    start = time.time()
    mass_profile.deflections_from_grid(grid=lens_data.grid_stack.sub)
    diff = time.time() - start
    print("SphericalIsothermal time = {}".format(diff))