Exemplo n.º 1
0
def pipeline():

    lens_mass = mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.6)
    lens_subhalo = mp.SphericalIsothermal(centre=(1.0, 1.0),
                                          einstein_radius=0.0)
    source_light = lp.SphericalSersic(centre=(0.0, 0.0),
                                      intensity=1.0,
                                      effective_radius=0.5,
                                      sersic_index=1.0)

    lens_galaxy = galaxy.Galaxy(mass=lens_mass, subhalo=lens_subhalo)
    source_galaxy = galaxy.Galaxy(light=source_light)

    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)
    result = pipeline.run(data=ccd_data)

    print(dir(result))
Exemplo n.º 2
0
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 = g.Galaxy(mass=mp.EllipticalIsothermal(
        centre=(0.0, 0.0), axis_ratio=0.8, phi=135.0, einstein_radius=1.6))

    source_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0., 0.),
                                                       axis_ratio=0.8,
                                                       phi=90.0,
                                                       intensity=0.2,
                                                       effective_radius=1.0,
                                                       sersic_index=1.5))

    tracer = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy],
        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)
Exemplo n.º 3
0
        def test__same_as_above__multiple_galaxies(self, grid_stack_0,
                                                   grid_stack_1):

            # Overwrite one value so intensity in each pixel is different
            grid_stack_0.blurring[1] = np.array([2.0, 2.0])
            grid_stack_1.blurring[1] = np.array([2.0, 2.0])

            g0 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=1.0))
            g1 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=2.0))

            g0_image_grid_0 = galaxy_util.intensities_of_galaxies_from_grid(
                grid_stack_0.blurring, galaxies=[g0])
            g1_image_grid_0 = galaxy_util.intensities_of_galaxies_from_grid(
                grid_stack_0.blurring, galaxies=[g1])

            plane_stack = pl_stack.PlaneStack(
                galaxies=[g0, g1], grid_stacks=[grid_stack_0, grid_stack_1])

            assert (plane_stack.image_plane_blurring_images_1d[0] ==
                    g0_image_grid_0 + g1_image_grid_0).all()

            g0_image_grid_1 = galaxy_util.intensities_of_galaxies_from_grid(
                grid_stack_1.blurring, galaxies=[g0])
            g1_image_grid_1 = galaxy_util.intensities_of_galaxies_from_grid(
                grid_stack_1.blurring, galaxies=[g1])

            plane_stack = pl_stack.PlaneStack(
                galaxies=[g0, g1], grid_stacks=[grid_stack_0, grid_stack_1])

            assert (plane_stack.image_plane_blurring_images_1d[1] ==
                    g0_image_grid_1 + g1_image_grid_1).all()
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)
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.1,
                                       pixel_scale=0.1)

    image_plane_grid_stack = grids.GridStack.grid_stack_for_simulation(
        shape=(130, 130), pixel_scale=0.1, psf_shape=(11, 11))

    lens_galaxy = g.Galaxy(
        mass=mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.6))
    source_galaxy = g.Galaxy(light=lp.SphericalExponential(
        centre=(0.0, 0.0), intensity=0.2, effective_radius=0.2))
    tracer = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy],
        source_galaxies=[source_galaxy],
        image_plane_grid_stack=image_plane_grid_stack)

    ccd_simulated = ccd.CCDData.simulate(
        array=tracer.image_plane_image_for_simulation,
        pixel_scale=0.1,
        exposure_time=300.0,
        psf=psf,
        background_sky_level=0.1,
        add_noise=True)

    return ccd_simulated
Exemplo n.º 6
0
    def test__tracer_and_tracer_sensitive_are_identical__added__likelihood_is_noise_term(
            self, lens_data_blur):

        g0 = g.Galaxy(mass_profile=mp.SphericalIsothermal(einstein_radius=1.0))
        g1 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=2.0))

        tracer = ray_tracing.TracerImageSourcePlanes(
            lens_galaxies=[g0],
            source_galaxies=[g1],
            image_plane_grid_stack=lens_data_blur.grid_stack)

        fit = sensitivity_fit.SensitivityProfileFit(lens_data=lens_data_blur,
                                                    tracer_normal=tracer,
                                                    tracer_sensitive=tracer)

        assert (fit.fit_normal.image == lens_data_blur.image).all()
        assert (fit.fit_normal.noise_map == lens_data_blur.noise_map).all()

        model_image_1d = util.blurred_image_1d_from_1d_unblurred_and_blurring_images(
            unblurred_image_1d=tracer.image_plane_image_1d,
            blurring_image_1d=tracer.image_plane_blurring_image_1d,
            convolver=lens_data_blur.convolver_image)

        model_image = lens_data_blur.map_to_scaled_array(
            array_1d=model_image_1d)

        assert (fit.fit_normal.model_image == model_image).all()

        residual_map = fit_util.residual_map_from_data_mask_and_model_data(
            data=lens_data_blur.image,
            mask=lens_data_blur.mask,
            model_data=model_image)
        assert (fit.fit_normal.residual_map == residual_map).all()

        chi_squared_map = fit_util.chi_squared_map_from_residual_map_noise_map_and_mask(
            residual_map=residual_map,
            mask=lens_data_blur.mask,
            noise_map=lens_data_blur.noise_map)

        assert (fit.fit_normal.chi_squared_map == chi_squared_map).all()

        assert (fit.fit_sensitive.image == lens_data_blur.image).all()
        assert (fit.fit_sensitive.noise_map == lens_data_blur.noise_map).all()
        assert (fit.fit_sensitive.model_image == model_image).all()
        assert (fit.fit_sensitive.residual_map == residual_map).all()
        assert (fit.fit_sensitive.chi_squared_map == chi_squared_map).all()

        chi_squared = fit_util.chi_squared_from_chi_squared_map_and_mask(
            chi_squared_map=chi_squared_map, mask=lens_data_blur.mask)
        noise_normalization = fit_util.noise_normalization_from_noise_map_and_mask(
            mask=lens_data_blur.mask, noise_map=lens_data_blur.noise_map)
        assert fit.fit_normal.likelihood == -0.5 * (chi_squared +
                                                    noise_normalization)
        assert fit.fit_sensitive.likelihood == -0.5 * (chi_squared +
                                                       noise_normalization)

        assert fit.figure_of_merit == 0.0
Exemplo n.º 7
0
    def test___same_as_above__use_galaxies_to_make_plane_images(self):

        mask = msk.Mask(array=np.array([[True, True,
                                         True], [True, False, True],
                                        [True, True, True]]),
                        pixel_scale=1.0)

        padded_grid_stack = grids.GridStack.padded_grid_stack_from_mask_sub_grid_size_and_psf_shape(
            mask=mask, sub_grid_size=1, psf_shape=(3, 3))

        psf_0 = im.PSF(array=(np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                        [0.0, 0.0, 0.0]])),
                       pixel_scale=1.0)

        psf_1 = im.PSF(array=(np.array([[0.0, 3.0, 0.0], [0.0, 1.0, 2.0],
                                        [0.0, 0.0, 0.0]])),
                       pixel_scale=1.0)

        g0 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.1))
        g1 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.2))

        tracer = ray_tracing_stack.TracerImagePlaneStack(
            lens_galaxies=[g0, g1],
            image_plane_grid_stacks=[padded_grid_stack, padded_grid_stack])

        manual_blurred_image_00 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            0][0]
        manual_blurred_image_00 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_00)
        manual_blurred_image_00 = psf_0.convolve(array=manual_blurred_image_00)

        manual_blurred_image_01 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            0][1]
        manual_blurred_image_01 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_01)
        manual_blurred_image_01 = psf_0.convolve(array=manual_blurred_image_01)

        manual_blurred_image_10 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            1][0]
        manual_blurred_image_10 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_10)
        manual_blurred_image_10 = psf_1.convolve(array=manual_blurred_image_10)

        manual_blurred_image_11 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            1][1]
        manual_blurred_image_11 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_11)
        manual_blurred_image_11 = psf_1.convolve(array=manual_blurred_image_11)

        unmasked_blurred_image_of_datas_and_planes = \
            stack_util.unmasked_blurred_image_of_datas_and_planes_from_padded_grid_stacks_and_psf(
                planes=tracer.planes, padded_grid_stacks=[padded_grid_stack, padded_grid_stack], psfs=[psf_0, psf_1])

        assert unmasked_blurred_image_of_datas_and_planes[0][0] == \
                pytest.approx(manual_blurred_image_00[1:4, 1:4] + manual_blurred_image_01[1:4, 1:4], 1.0e-4)
        assert unmasked_blurred_image_of_datas_and_planes[1][0] == \
                pytest.approx(manual_blurred_image_10[1:4, 1:4] + manual_blurred_image_11[1:4, 1:4], 1.0e-4)
Exemplo n.º 8
0
    def test_model_instance_sum_priority(self):
        instance_1 = mm.ModelInstance()
        galaxy_1 = g.Galaxy()
        instance_1.galaxy = galaxy_1

        instance_2 = mm.ModelInstance()
        galaxy_2 = g.Galaxy()
        instance_2.galaxy = galaxy_2

        assert (instance_1 + instance_2).galaxy == galaxy_2
Exemplo n.º 9
0
        def test__plane_has_no_border__still_returns_mapper(
                self, grid_stack_0):
            galaxy_pix = g.Galaxy(pixelization=MockPixelization(value=1),
                                  regularization=MockRegularization(value=0))
            galaxy_no_pix = g.Galaxy()

            plane_stack = pl_stack.PlaneStack(
                galaxies=[galaxy_no_pix, galaxy_pix],
                grid_stacks=[grid_stack_0])

            assert plane_stack.mapper == 1
Exemplo n.º 10
0
        def test__2_galaxies_in_plane__1_has_pixelization__extracts_reconstructor(
                self, grid_stack_0):
            galaxy_pix = g.Galaxy(pixelization=MockPixelization(value=1),
                                  regularization=MockRegularization(value=0))
            galaxy_no_pix = g.Galaxy()

            plane_stack = pl_stack.PlaneStack(
                galaxies=[galaxy_no_pix, galaxy_pix],
                grid_stacks=[grid_stack_0],
                borders=[MockBorders()])

            assert plane_stack.regularization.value == 0
Exemplo n.º 11
0
    def test__tracer_for_instance__includes_cosmology(self, ccd_data):
        lens_galaxy = g.Galaxy()
        source_galaxy = g.Galaxy()

        phase = ph.LensPlanePhase(lens_galaxies=[lens_galaxy],
                                  cosmology=cosmo.FLRW,
                                  phase_name='test_phase')
        analysis = phase.make_analysis(ccd_data)
        instance = phase.constant
        tracer = analysis.tracer_for_instance(instance)
        padded_tracer = analysis.padded_tracer_for_instance(instance)

        assert tracer.image_plane.galaxies[0] == lens_galaxy
        assert tracer.cosmology == cosmo.FLRW
        assert padded_tracer.image_plane.galaxies[0] == lens_galaxy
        assert padded_tracer.cosmology == cosmo.FLRW

        phase = ph.LensSourcePlanePhase(lens_galaxies=[lens_galaxy],
                                        source_galaxies=[source_galaxy],
                                        cosmology=cosmo.FLRW,
                                        phase_name='test_phase')
        analysis = phase.make_analysis(ccd_data)
        instance = phase.constant
        tracer = analysis.tracer_for_instance(instance)
        padded_tracer = analysis.padded_tracer_for_instance(instance)

        assert tracer.image_plane.galaxies[0] == lens_galaxy
        assert tracer.source_plane.galaxies[0] == source_galaxy
        assert tracer.cosmology == cosmo.FLRW
        assert padded_tracer.image_plane.galaxies[0] == lens_galaxy
        assert padded_tracer.source_plane.galaxies[0] == source_galaxy
        assert padded_tracer.cosmology == cosmo.FLRW

        galaxy_0 = g.Galaxy(redshift=0.1)
        galaxy_1 = g.Galaxy(redshift=0.2)
        galaxy_2 = g.Galaxy(redshift=0.3)

        phase = ph.MultiPlanePhase(galaxies=[galaxy_0, galaxy_1, galaxy_2],
                                   cosmology=cosmo.WMAP7,
                                   phase_name='test_phase')
        analysis = phase.make_analysis(ccd_data)
        instance = phase.constant
        tracer = analysis.tracer_for_instance(instance)
        padded_tracer = analysis.padded_tracer_for_instance(instance)

        assert tracer.planes[0].galaxies[0] == galaxy_0
        assert tracer.planes[1].galaxies[0] == galaxy_1
        assert tracer.planes[2].galaxies[0] == galaxy_2
        assert tracer.cosmology == cosmo.WMAP7
        assert padded_tracer.planes[0].galaxies[0] == galaxy_0
        assert padded_tracer.planes[1].galaxies[0] == galaxy_1
        assert padded_tracer.planes[2].galaxies[0] == galaxy_2
        assert padded_tracer.cosmology == cosmo.WMAP7
Exemplo n.º 12
0
        def test__2_galaxies_in_plane__both_have_pixelization__raises_error(
                self, grid_stack_0):
            galaxy_pix_0 = g.Galaxy(pixelization=MockPixelization(value=1),
                                    regularization=MockRegularization(value=0))
            galaxy_pix_1 = g.Galaxy(pixelization=MockPixelization(value=2),
                                    regularization=MockRegularization(value=0))

            plane_stack = pl_stack.PlaneStack(
                galaxies=[galaxy_pix_0, galaxy_pix_1],
                grid_stacks=[grid_stack_0],
                borders=[MockBorders()])

            with pytest.raises(exc.PixelizationException):
                plane_stack.regularization
Exemplo n.º 13
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])
Exemplo n.º 14
0
        def test__total_images(self, grid_stack_0):

            plane_stack = pl_stack.PlaneStack(galaxies=[g.Galaxy()],
                                              grid_stacks=[grid_stack_0])
            assert plane_stack.total_grid_stacks == 1

            plane_stack = pl_stack.PlaneStack(
                galaxies=[g.Galaxy()],
                grid_stacks=[grid_stack_0, grid_stack_0])
            assert plane_stack.total_grid_stacks == 2

            plane_stack = pl_stack.PlaneStack(
                galaxies=[g.Galaxy()],
                grid_stacks=[grid_stack_0, grid_stack_0, grid_stack_0])
            assert plane_stack.total_grid_stacks == 3
Exemplo n.º 15
0
def pipeline():

    sersic = lp.EllipticalSersic(centre=(0.0, 0.0),
                                 axis_ratio=0.8,
                                 phi=90.0,
                                 intensity=1.0,
                                 effective_radius=1.3,
                                 sersic_index=3.0)

    lens_galaxy = galaxy.Galaxy(light_profile=sersic)

    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=[],
                                     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)
Exemplo n.º 16
0
def make_galaxy_light():
    return g.Galaxy(light_profile=lp.EllipticalSersic(centre=(0.1, 0.1),
                                                      axis_ratio=1.0,
                                                      phi=0.0,
                                                      intensity=1.0,
                                                      effective_radius=0.6,
                                                      sersic_index=4.0))
Exemplo n.º 17
0
def phase():

    pixel_scale = 0.1
    image_shape = (150, 150)

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

    grid_stack = grids.GridStack.from_shape_pixel_scale_and_sub_grid_size(shape=image_shape, pixel_scale=pixel_scale,
                                                                          sub_grid_size=4)

    galaxy = g.Galaxy(mass=mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.0))

    deflections = galaxy_util.deflections_of_galaxies_from_grid(galaxies=[galaxy], grid=grid_stack.sub)
    deflections_y = grid_stack.regular.scaled_array_from_array_1d(array_1d=deflections[:,0])
    deflections_x = grid_stack.regular.scaled_array_from_array_1d(array_1d=deflections[:,1])

    noise_map = scaled_array.ScaledSquarePixelArray(array=np.ones(deflections_y.shape), pixel_scale=pixel_scale)

    data_y = gd.GalaxyData(image=deflections_y, noise_map=noise_map, pixel_scale=pixel_scale)
    data_x = gd.GalaxyData(image=deflections_x, noise_map=noise_map, pixel_scale=pixel_scale)

    phase = ph.GalaxyFitPhase(galaxies=dict(gal=gm.GalaxyModel(light=mp.SphericalIsothermal)), use_deflections=True,
                              sub_grid_size=4,
                              optimizer_class=nl.MultiNest, phase_name=test_name+'/')

    phase.run(galaxy_data=[data_y, data_x])
Exemplo n.º 18
0
        def test__circle__one_profile_gal__integral_is_same_as_individual_profile(
                self):

            sersic = lp.EllipticalSersic(axis_ratio=1.0,
                                         phi=0.0,
                                         intensity=3.0,
                                         effective_radius=2.0,
                                         sersic_index=1.0)

            integral_radius = 5.5

            intensity_integral = sersic.luminosity_within_circle(
                radius=integral_radius)

            gal_sersic = g.Galaxy(redshift=0.5,
                                  light_profile_1=lp.EllipticalSersic(
                                      axis_ratio=1.0,
                                      phi=0.0,
                                      intensity=3.0,
                                      effective_radius=2.0,
                                      sersic_index=1.0))

            gal_intensity_integral = gal_sersic.luminosity_within_circle(
                radius=integral_radius)

            assert intensity_integral == gal_intensity_integral
Exemplo n.º 19
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
Exemplo n.º 20
0
def phase():

    pixel_scale = 0.1
    image_shape = (150, 150)

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

    grid_stack = grids.GridStack.from_shape_pixel_scale_and_sub_grid_size(
        shape=image_shape, pixel_scale=pixel_scale, sub_grid_size=4)

    galaxy = g.Galaxy(mass=lp.SphericalExponential(
        centre=(0.0, 0.0), intensity=1.0, effective_radius=0.5))

    intensities = galaxy_util.intensities_of_galaxies_from_grid(
        galaxies=[galaxy], grid=grid_stack.sub)
    intensities = grid_stack.regular.scaled_array_from_array_1d(
        array_1d=intensities)

    noise_map = scaled_array.ScaledSquarePixelArray(array=np.ones(
        intensities.shape),
                                                    pixel_scale=pixel_scale)

    data = gd.GalaxyData(image=intensities,
                         noise_map=noise_map,
                         pixel_scale=pixel_scale)

    phase = ph.GalaxyFitPhase(
        galaxies=dict(gal=gm.GalaxyModel(light=lp.SphericalExponential)),
        use_intensities=True,
        sub_grid_size=4,
        optimizer_class=nl.MultiNest,
        phase_name=test_name + '/')

    phase.run(galaxy_data=[data])
Exemplo n.º 21
0
    def test__setup_pixelization__galaxy_has_pixelization__returns_grids_with_pix_grid(
            self):

        ma = mask.Mask(np.array([[False, False, False], [False, False, False],
                                 [False, True, False]]),
                       pixel_scale=1.0)

        grid_stack = grids.GridStack.grid_stack_from_mask_sub_grid_size_and_psf_shape(
            mask=ma, sub_grid_size=1, psf_shape=(1, 1))

        galaxy = g.Galaxy(
            pixelization=pixelizations.AdaptiveMagnification(shape=(3, 3)),
            regularization=regularization.Constant())

        image_plane_pix_grids = \
            pixelizations.setup_image_plane_pixelization_grid_from_galaxies_and_grid_stack(galaxies=[galaxy, galaxy],
                                                                                           grid_stack=grid_stack)

        assert (image_plane_pix_grids.regular == grid_stack.regular).all()
        assert (image_plane_pix_grids.sub == grid_stack.sub).all()
        assert (image_plane_pix_grids.blurring == grid_stack.blurring).all()
        assert image_plane_pix_grids.pix == pytest.approx(
            np.array([[1.0, -1.0], [1.0, 0.0], [1.0, 1.0], [0.0, -1.0],
                      [0.0, 0.0], [0.0, 1.0], [-1.0, -1.0], [-1.0, 1.0]]),
            1.0e-4)
Exemplo n.º 22
0
    def test_constants_work(self):
        name = "const_float"
        test_name = "/const_float"

        integration_util.reset_paths(test_name, output_path)

        sersic = al.EllipticalSersic(
            centre=(0.0, 0.0),
            axis_ratio=0.8,
            phi=90.0,
            intensity=1.0,
            effective_radius=1.3,
            sersic_index=3.0,
        )

        lens_galaxy = galaxy.Galaxy(redshift=0.5, light_profile=sersic)

        simulate_integration_image(test_name=test_name,
                                   pixel_scale=0.5,
                                   galaxies=[lens_galaxy])
        path = "{}/".format(os.path.dirname(os.path.realpath(
            __file__)))  # Setup path so we can output the simulated image.

        imaging_data = al.load_imaging_data_from_fits(
            image_path=path + "/test_files/data/" + test_name + "/image.fits",
            psf_path=path + "/test_files/data/" + test_name + "/psf.fits",
            noise_map_path=path + "/test_files/data/" + test_name +
            "/noise_map.fits",
            pixel_scale=0.1,
        )

        class MMPhase(al.PhaseImaging):
            def customize_priors(self, results):
                self.galaxies.lens.sersic.axis_ratio = 0.2
                self.galaxies.lens.sersic.phi = 90.0
                self.galaxies.lens.sersic.intensity = 1.0
                self.galaxies.lens.sersic.effective_radius = 1.3
                self.galaxies.lens.sersic.sersic_index = 3.0

        phase = MMPhase(
            galaxies=dict(lens=al.GalaxyModel(
                redshift=0.5, sersic=al.light_profiles.EllipticalSersic)),
            optimizer_class=af.MultiNest,
            phase_name="{}/phase1".format(name),
        )

        phase.optimizer.n_live_points = 20
        phase.optimizer.sampling_efficiency = 0.8

        phase.make_analysis(data=imaging_data)

        sersic = phase.variable.galaxies[0].sersic

        assert isinstance(sersic, af.PriorModel)

        assert isinstance(sersic.axis_ratio, float)
        assert isinstance(sersic.phi, float)
        assert isinstance(sersic.intensity, float)
        assert isinstance(sersic.effective_radius, float)
        assert isinstance(sersic.sersic_index, float)
Exemplo n.º 23
0
        def test__no_mass_profile__returns_none(self):

            gal = g.Galaxy(redshift=0.5, light=lp.SphericalSersic())

            assert gal.mass_within_circle(radius=1.0,
                                          conversion_factor=1.0) == None
            assert gal.mass_within_ellipse(major_axis=1.0,
                                           conversion_factor=1.0) == None
Exemplo n.º 24
0
def test_pipeline():

    bulge_0 = lp.EllipticalSersic(centre=(-1.0, -1.0),
                                  axis_ratio=0.9,
                                  phi=90.0,
                                  intensity=1.0,
                                  effective_radius=1.0,
                                  sersic_index=4.0)
    disk_0 = lp.EllipticalSersic(centre=(-1.0, -1.0),
                                 axis_ratio=0.6,
                                 phi=90.0,
                                 intensity=20.0,
                                 effective_radius=2.5,
                                 sersic_index=1.0)
    bulge_1 = lp.EllipticalSersic(centre=(1.0, 1.0),
                                  axis_ratio=0.9,
                                  phi=90.0,
                                  intensity=1.0,
                                  effective_radius=1.0,
                                  sersic_index=4.0)
    disk_1 = lp.EllipticalSersic(centre=(1.0, 1.0),
                                 axis_ratio=0.6,
                                 phi=90.0,
                                 intensity=20.0,
                                 effective_radius=2.5,
                                 sersic_index=1.0)

    lens_galaxy_0 = galaxy.Galaxy(bulge=bulge_0, disk=disk_0)
    lens_galaxy_1 = galaxy.Galaxy(bulge=bulge_1, disk=disk_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_0, lens_galaxy_1],
        source_galaxies=[],
        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)
Exemplo n.º 25
0
        def test__ensure_index_of_plane_image_has_negative_arcseconds_at_start(
                self, grid_stack_0):
            # The grid coordinates -2.0 -> 2.0 mean a plane of shape (5,5) has arc second coordinates running over
            # -1.6, -0.8, 0.0, 0.8, 1.6. The origin -1.6, -1.6 of the model_galaxy means its brighest pixel should be
            # index 0 of the 1D grid and (0,0) of the 2d plane datas_.

            msk = mask.Mask(array=np.full((5, 5), False), pixel_scale=1.0)

            grid_stack_0.regular = grids.RegularGrid(np.array([[-2.0, -2.0],
                                                               [2.0, 2.0]]),
                                                     mask=msk)

            g0 = g.Galaxy(light_profile=lp.EllipticalSersic(centre=(1.6, -1.6),
                                                            intensity=1.0))
            plane_stack = pl_stack.PlaneStack(galaxies=[g0],
                                              grid_stacks=[grid_stack_0])

            assert plane_stack.plane_images[0].shape == (5, 5)
            assert np.unravel_index(plane_stack.plane_images[0].argmax(),
                                    plane_stack.plane_images[0].shape) == (0,
                                                                           0)

            g0 = g.Galaxy(light_profile=lp.EllipticalSersic(centre=(1.6, 1.6),
                                                            intensity=1.0))
            plane_stack = pl_stack.PlaneStack(galaxies=[g0],
                                              grid_stacks=[grid_stack_0])
            assert np.unravel_index(plane_stack.plane_images[0].argmax(),
                                    plane_stack.plane_images[0].shape) == (0,
                                                                           4)

            g0 = g.Galaxy(light_profile=lp.EllipticalSersic(
                centre=(-1.6, -1.6), intensity=1.0))
            plane_stack = pl_stack.PlaneStack(galaxies=[g0],
                                              grid_stacks=[grid_stack_0])
            assert np.unravel_index(plane_stack.plane_images[0].argmax(),
                                    plane_stack.plane_images[0].shape) == (4,
                                                                           0)

            g0 = g.Galaxy(light_profile=lp.EllipticalSersic(centre=(-1.6, 1.6),
                                                            intensity=1.0))
            plane_stack = pl_stack.PlaneStack(galaxies=[g0],
                                              grid_stacks=[grid_stack_0])
            assert np.unravel_index(plane_stack.plane_images[0].argmax(),
                                    plane_stack.plane_images[0].shape) == (4,
                                                                           4)
Exemplo n.º 26
0
        def test__no_galaxies_with_pixelizations_in_plane__returns_none(
                self, grid_stack_0):
            galaxy_no_pix = g.Galaxy()

            plane_stack = pl_stack.PlaneStack(galaxies=[galaxy_no_pix],
                                              grid_stacks=[grid_stack_0],
                                              borders=[MockBorders()])

            assert plane_stack.regularization is None
Exemplo n.º 27
0
    def test__3_galaxies_reordered_in_ascending_redshift(self):
        galaxies = [
            g.Galaxy(redshift=2.0),
            g.Galaxy(redshift=1.0),
            g.Galaxy(redshift=0.1)
        ]

        ordered_plane_redshifts = lens_util.ordered_plane_redshifts_from_galaxies(
            galaxies=galaxies)

        assert ordered_plane_redshifts == [0.1, 1.0, 2.0]

        ordered_galaxies = lens_util.galaxies_in_redshift_ordered_planes_from_galaxies(
            galaxies=galaxies, plane_redshifts=ordered_plane_redshifts)

        assert ordered_galaxies[0][0].redshift == 0.1
        assert ordered_galaxies[1][0].redshift == 1.0
        assert ordered_galaxies[2][0].redshift == 2.0
Exemplo n.º 28
0
        def test__1_galaxy_in_plane__it_has_pixelization__returns_mapper(
                self, grid_stack_0):
            galaxy_pix = g.Galaxy(pixelization=MockPixelization(value=1),
                                  regularization=MockRegularization(value=0))

            plane_stack = pl_stack.PlaneStack(galaxies=[galaxy_pix],
                                              grid_stacks=[grid_stack_0],
                                              borders=[MockBorders()])

            assert plane_stack.regularization.value == 0
Exemplo n.º 29
0
        def test__image_plane_image_of_galaxies__use_multiple_grids__get_multiple_images(
                self, grid_stack_0, grid_stack_1):

            # Overwrite one value so intensity in each pixel is different
            grid_stack_0.sub[5] = np.array([2.0, 2.0])

            g0 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=1.0))
            g1 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=2.0))

            plane_stack = pl_stack.PlaneStack(
                galaxies=[g0, g1], grid_stacks=[grid_stack_0, grid_stack_1])

            g0_image_grid_0 = galaxy_util.intensities_of_galaxies_from_grid(
                grid_stack_0.sub, galaxies=[g0])
            g1_image_grid_0 = galaxy_util.intensities_of_galaxies_from_grid(
                grid_stack_0.sub, galaxies=[g1])

            assert plane_stack.image_plane_images_1d[0] == pytest.approx(
                g0_image_grid_0 + g1_image_grid_0, 1.0e-4)
            assert (plane_stack.image_plane_images[0] ==
                    grid_stack_0.regular.scaled_array_from_array_1d(
                        plane_stack.image_plane_images_1d[0])).all()

            assert (plane_stack.image_plane_images_1d_of_galaxies[0][0] ==
                    g0_image_grid_0).all()
            assert (plane_stack.image_plane_images_1d_of_galaxies[0][1] ==
                    g1_image_grid_0).all()

            g0_image_grid_1 = galaxy_util.intensities_of_galaxies_from_grid(
                grid_stack_1.sub, galaxies=[g0])
            g1_image_grid_1 = galaxy_util.intensities_of_galaxies_from_grid(
                grid_stack_1.sub, galaxies=[g1])

            assert plane_stack.image_plane_images_1d[1] == pytest.approx(
                g0_image_grid_1 + g1_image_grid_1, 1.0e-4)
            assert (plane_stack.image_plane_images[1] ==
                    grid_stack_0.regular.scaled_array_from_array_1d(
                        plane_stack.image_plane_images_1d[1])).all()

            assert (plane_stack.image_plane_images_1d_of_galaxies[1][0] ==
                    g0_image_grid_1).all()
            assert (plane_stack.image_plane_images_1d_of_galaxies[1][1] ==
                    g1_image_grid_1).all()
Exemplo n.º 30
0
    def test_3_galaxies_two_same_redshift_planes_redshift_order_is_size_2_with_redshifts(
            self):
        galaxies = [
            g.Galaxy(redshift=1.0),
            g.Galaxy(redshift=1.0),
            g.Galaxy(redshift=0.1)
        ]

        ordered_plane_redshifts = lens_util.ordered_plane_redshifts_from_galaxies(
            galaxies=galaxies)

        assert ordered_plane_redshifts == [0.1, 1.0]

        ordered_galaxies = lens_util.galaxies_in_redshift_ordered_planes_from_galaxies(
            galaxies=galaxies, plane_redshifts=ordered_plane_redshifts)

        assert ordered_galaxies[0][0].redshift == 0.1
        assert ordered_galaxies[1][0].redshift == 1.0
        assert ordered_galaxies[1][1].redshift == 1.0