コード例 #1
0
    def test__intensity_from_grid__change_geometry(self):
        exponential_0 = lp.EllipticalExponential(axis_ratio=0.5,
                                                 phi=0.0,
                                                 intensity=3.0,
                                                 effective_radius=2.0)

        exponential_1 = lp.EllipticalExponential(axis_ratio=0.5,
                                                 phi=90.0,
                                                 intensity=3.0,
                                                 effective_radius=2.0)

        assert exponential_0.intensities_from_grid(grid=np.array([[0.0, 1.0]])) == \
               exponential_1.intensities_from_grid(grid=np.array([[1.0, 0.0]]))
コード例 #2
0
    def test__intensity_at_radius__correct_value(self):
        exponential = lp.EllipticalExponential(axis_ratio=1.0,
                                               phi=0.0,
                                               intensity=1.0,
                                               effective_radius=0.6)
        assert exponential.intensities_from_grid_radii(
            grid_radii=1.0) == pytest.approx(0.3266, 1e-3)

        exponential = lp.EllipticalExponential(axis_ratio=1.0,
                                               phi=0.0,
                                               intensity=3.0,
                                               effective_radius=2.0)
        assert exponential.intensities_from_grid_radii(
            grid_radii=1.5) == pytest.approx(4.5640, 1e-3)
コード例 #3
0
def pipeline():
    bulge = lp.EllipticalSersic(centre=(0.0, 0.0),
                                axis_ratio=0.8,
                                phi=0.0,
                                intensity=1.0,
                                effective_radius=1.3,
                                sersic_index=3.0)

    disk = lp.EllipticalExponential(centre=(0.0, 0.0),
                                    axis_ratio=0.7,
                                    phi=0.0,
                                    intensity=2.0,
                                    effective_radius=2.0)

    lens_galaxy = galaxy.Galaxy(bulge=bulge, disk=disk)

    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)
コード例 #4
0
    def test__spherical_and_elliptical_match(self):
        elliptical = lp.EllipticalExponential(axis_ratio=1.0,
                                              phi=0.0,
                                              intensity=3.0,
                                              effective_radius=2.0)

        spherical = lp.SphericalExponential(intensity=3.0,
                                            effective_radius=2.0)

        assert (elliptical.intensities_from_grid(grid) ==
                spherical.intensities_from_grid(grid)).all()
コード例 #5
0
    def test__intensity_from_grid__correct_values(self):
        exponential = lp.EllipticalExponential(axis_ratio=0.5,
                                               phi=0.0,
                                               intensity=3.0,
                                               effective_radius=2.0)
        assert exponential.intensities_from_grid(
            grid=np.array([[1.0, 0.0]])) == pytest.approx(4.9047, 1e-3)

        exponential = lp.EllipticalExponential(axis_ratio=0.5,
                                               phi=90.0,
                                               intensity=2.0,
                                               effective_radius=3.0)
        assert exponential.intensities_from_grid(
            grid=np.array([[0.0, 1.0]])) == pytest.approx(4.8566, 1e-3)

        exponential = lp.EllipticalExponential(axis_ratio=0.5,
                                               phi=90.0,
                                               intensity=4.0,
                                               effective_radius=3.0)
        assert exponential.intensities_from_grid(
            grid=np.array([[0.0, 1.0]])) == pytest.approx(2.0 * 4.8566, 1e-3)
コード例 #6
0
    def test__constructor(self):
        exponential = lp.EllipticalExponential(axis_ratio=0.5,
                                               phi=0.0,
                                               intensity=1.0,
                                               effective_radius=0.6)

        assert exponential.centre == (0.0, 0.0)
        assert exponential.axis_ratio == 0.5
        assert exponential.phi == 0.0
        assert exponential.intensity == 1.0
        assert exponential.effective_radius == 0.6
        assert exponential.sersic_index == 1.0
        assert exponential.sersic_constant == pytest.approx(1.678378, 1e-3)
        assert exponential.elliptical_effective_radius == 0.6 / math.sqrt(0.5)
コード例 #7
0
    def test__grid_calculations__same_as_exponential(self):
        sersic_lp = lp.EllipticalExponential(axis_ratio=0.7,
                                             phi=1.0,
                                             intensity=1.0,
                                             effective_radius=0.6)
        sersic_mp = mp.EllipticalExponential(axis_ratio=0.7,
                                             phi=1.0,
                                             intensity=1.0,
                                             effective_radius=0.6,
                                             mass_to_light_ratio=2.0)
        sersic_lmp = lmp.EllipticalExponential(axis_ratio=0.7,
                                               phi=1.0,
                                               intensity=1.0,
                                               effective_radius=0.6,
                                               mass_to_light_ratio=2.0)

        assert (sersic_lp.intensities_from_grid(grid) ==
                sersic_lmp.intensities_from_grid(grid)).all()
        assert (sersic_mp.surface_density_from_grid(grid) ==
                sersic_lmp.surface_density_from_grid(grid)).all()
        #    assert (sersic_mp.potential_from_grid(grid) == sersic_lmp.potential_from_grid(grid)).all()
        assert (sersic_mp.deflections_from_grid(grid) ==
                sersic_lmp.deflections_from_grid(grid)).all()
コード例 #8
0
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
galaxy_plotters.plot_deflections_y(galaxy=lens_galaxy, grid=image_plane_grid_stack.regular, title='Lens Galaxy Deflections (y)')
galaxy_plotters.plot_deflections_y(galaxy=lens_satellite, grid=image_plane_grid_stack.regular, title='Lens Satellite Deflections (y)')
galaxy_plotters.plot_deflections_x(galaxy=lens_galaxy, grid=image_plane_grid_stack.regular, title='Lens Galalxy Deflections (x)')
galaxy_plotters.plot_deflections_x(galaxy=lens_satellite, grid=image_plane_grid_stack.regular, title='Lens Satellite Deflections (x)')

# Now, lets make two source galaxies at redshift 1.0. Lets not use the terms 'light' and 'mass' to setup the light and
# mass profiles. Instead, lets use more descriptive names of what we think each component represents ( e.g. a 'bulge' and 'disk').
source_galaxy_0 = g.Galaxy(bulge=lp.SphericalDevVaucouleurs(centre=(0.1, 0.2), intensity=0.3, effective_radius=0.3),
                           disk=lp.EllipticalExponential(centre=(0.1, 0.2), axis_ratio=0.8, phi=45.0, intensity=3.0,
                                                       effective_radius=2.0),
                           redshift=1.0)

source_galaxy_1 = g.Galaxy(disk=lp.EllipticalExponential(centre=(-0.3, -0.5), axis_ratio=0.6, phi=80.0, intensity=8.0,
                                                         effective_radius=1.0),
                           redshift=1.0)
print(source_galaxy_0)
print(source_galaxy_1)

# Lets look at our source galaxies (before lensing)
galaxy_plotters.plot_intensities(galaxy=source_galaxy_0, grid=image_plane_grid_stack.regular, title='Source Galaxy 0')
galaxy_plotters.plot_intensities(galaxy=source_galaxy_1, grid=image_plane_grid_stack.regular, title='Source Galaxy 1')

# Now lets pass these our 4 galaxies to the ray_tracing module, which means the following will occur:

# 1) Using every mass-profile in each lens galaxy, the deflection angles are computed.
コード例 #9
0
def make_galaxy():
    return g.Galaxy(redshift=3,
                    sersic=light_profiles.EllipticalSersic(),
                    exponential=light_profiles.EllipticalExponential(),
                    spherical=mass_profiles.SphericalIsothermal())
コード例 #10
0
    print("EllipticalGaussian time = {}".format(diff))

    ### SphericalGaussian ###

    mass_profile = lp.SphericalGaussian(centre=(0.0, 0.0), sigma=1.0)

    start = time.time()
    mass_profile.intensities_from_grid(grid=lens_data.grid_stack.sub)
    diff = time.time() - start
    print("SphericalGaussian time = {}".format(diff))

    ### EllipticalExponential ###

    profile = lp.EllipticalExponential(centre=(0.0, 0.0),
                                       axis_ratio=0.8,
                                       phi=45.0,
                                       intensity=1.0,
                                       effective_radius=1.0)

    start = time.time()
    profile.intensities_from_grid(grid=lens_data.grid_stack.sub)
    diff = time.time() - start
    print("EllipticalExponential time = {}".format(diff))

    ### SphericalExponential ###

    profile = lp.SphericalExponential(centre=(0.0, 0.0),
                                      intensity=1.0,
                                      effective_radius=1.0)

    start = time.time()
コード例 #11
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)