Exemplo n.º 1
0
    def test__max_log_likelihood_tracer__multiple_image_positions_of_source_plane_centres_and_separations(
        self, imaging_7x7, mask_7x7
    ):

        lens = al.Galaxy(
            redshift=0.5,
            mass=al.mp.EllipticalIsothermal(
                centre=(0.001, 0.001),
                einstein_radius=1.0,
                elliptical_comps=(0.0, 0.111111),
            ),
        )

        source = al.Galaxy(
            redshift=1.0,
            light=al.lp.SphericalSersic(centre=(0.0, 0.0), intensity=2.0),
            light1=al.lp.SphericalSersic(centre=(0.0, 0.1), intensity=2.0),
            pixelization=al.pix.Rectangular((3, 3)),
            regularization=al.reg.Constant(coefficient=1.0),
        )

        tracer = al.Tracer.from_galaxies(galaxies=[lens, source])

        samples = mock.MockSamples(max_log_likelihood_instance=tracer)

        phase_dataset_7x7 = al.PhaseImaging(
            search=mock.MockSearch("test_phase_2", samples=samples)
        )

        result = phase_dataset_7x7.run(
            dataset=imaging_7x7, mask=mask_7x7, results=mock.MockResults()
        )

        mask = al.Mask2D.unmasked(
            shape_native=(100, 100), pixel_scales=0.05, sub_size=1
        )

        result.analysis.masked_dataset.mask = mask

        multiple_images = (
            result.image_plane_multiple_image_positions_of_source_plane_centres
        )

        grid = al.Grid2D.from_mask(mask=mask)

        solver = al.PositionsSolver(grid=grid, pixel_scale_precision=0.001)

        multiple_images_manual = solver.solve(
            lensing_obj=tracer,
            source_plane_coordinate=result.source_plane_inversion_centre[0],
        )

        assert multiple_images.in_list[0] == multiple_images_manual.in_list[0]
Exemplo n.º 2
0
    def test__multi_plane_position_solving(self):

        grid = al.Grid2D.uniform(shape_native=(100, 100),
                                 pixel_scales=0.05,
                                 sub_size=1)

        g0 = al.Galaxy(redshift=0.5,
                       mass=al.mp.SphIsothermal(einstein_radius=1.0))
        g1 = al.Galaxy(redshift=1.0,
                       point_0=al.ps.PointSource(centre=(0.1, 0.1)))
        g2 = al.Galaxy(redshift=2.0,
                       point_1=al.ps.PointSource(centre=(0.1, 0.1)))

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

        positions = al.Grid2DIrregular([(0.0, 0.0), (3.0, 4.0)])
        noise_map = al.ValuesIrregular([0.5, 1.0])

        positions_solver = al.PositionsSolver(grid=grid,
                                              pixel_scale_precision=0.01)

        fit_0 = al.FitPositionsImage(
            name="point_0",
            positions=positions,
            noise_map=noise_map,
            tracer=tracer,
            positions_solver=positions_solver,
        )

        fit_1 = al.FitPositionsImage(
            name="point_1",
            positions=positions,
            noise_map=noise_map,
            tracer=tracer,
            positions_solver=positions_solver,
        )

        scaling_factor = al.util.cosmology.scaling_factor_between_redshifts_from(
            redshift_0=0.5,
            redshift_1=1.0,
            redshift_final=2.0,
            cosmology=tracer.cosmology,
        )

        assert fit_0.model_positions[0, 0] == pytest.approx(
            scaling_factor * fit_1.model_positions[0, 0], 1.0e-1)
        assert fit_0.model_positions[0, 1] == pytest.approx(
            scaling_factor * fit_1.model_positions[0, 1], 1.0e-1)
    def test__positions_found_for_simple_mass_profiles(self):

        grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=0.05)

        sis = al.mp.SphIsothermal(centre=(0.0, 0.0), einstein_radius=1.0)

        solver = al.PositionsSolver(grid=grid, pixel_scale_precision=0.01)

        positions = solver.solve(lensing_obj=sis,
                                 source_plane_coordinate=(0.0, 0.11))

        assert positions[0] == pytest.approx(np.array([0.003125, -0.890625]),
                                             1.0e-4)
        assert positions[3] == pytest.approx(np.array([-0.003125, 1.109375]),
                                             1.0e-4)

        grid = al.Grid2D.uniform(shape_native=(100, 100),
                                 pixel_scales=0.05,
                                 sub_size=1)

        g0 = al.Galaxy(
            redshift=0.5,
            mass=al.mp.EllIsothermal(
                centre=(0.001, 0.001),
                einstein_radius=1.0,
                elliptical_comps=(0.0, 0.111111),
            ),
        )

        g1 = al.Galaxy(redshift=1.0)

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

        solver = pos.PositionsSolver(grid=grid, pixel_scale_precision=0.01)

        coordinates = solver.solve(lensing_obj=tracer,
                                   source_plane_coordinate=(0.0, 0.0))

        assert coordinates.in_list[0] == pytest.approx((1.028125, -0.003125),
                                                       1.0e-4)
        assert coordinates.in_list[1] == pytest.approx((0.009375, -0.95312),
                                                       1.0e-4)
        assert coordinates.in_list[2] == pytest.approx((0.009375, 0.95312),
                                                       1.0e-4)
        assert coordinates.in_list[3] == pytest.approx((-1.028125, -0.003125),
                                                       1.0e-4)
point_dict = al.PointDict.from_json(
    file_path=path.join(dataset_path, "point_dict.json"))

visuals_2d = aplt.Visuals2D(positions=point_dict.positions_list)

array_plotter = aplt.Array2DPlotter(array=imaging.image, visuals_2d=visuals_2d)
array_plotter.figure_2d()
"""
__PositionsSolver__

Define the position solver used for the point source fitting.
"""
grid = al.Grid2D.uniform(shape_native=imaging.shape_native,
                         pixel_scales=imaging.pixel_scales)

positions_solver = al.PositionsSolver(grid=grid, pixel_scale_precision=0.025)
"""
__Model__

We now compose the lens model. For clusters there could be many hundreds of galaxies in the model. Whereas previous 
examples explicitly wrote the model out via Python code, for cluster modeling we opt to write it in .json files which
are loaded in this script.

The code below loads a model from the .json file `clusters/modeling/models/lens_x3__source_x1.py`. This model includes
all three lens galaxies where the priors on the centres have been paired to thei brightest pixels in the observed image,
alongside a source galaxy which is modeled as a point source.
"""
model_path = path.join("scripts", "clusters", "modeling", "models")
model_file = path.join(model_path, "lens_x3__source_x1.json")

model = af.Collection.from_json(file=model_file)
Exemplo n.º 5
0
mass_profile_model.einstein_radius = af.UniformPrior(lower_limit=0.3, upper_limit=2.0)

light_profile_model = af.PriorModel(al.lp.EllipticalExponential)
light_profile_model.centre.centre_0 = af.UniformPrior(lower_limit=-1.0, upper_limit=1.0)
light_profile_model.centre.centre_1 = af.UniformPrior(lower_limit=-1.0, upper_limit=1.0)
light_profile_model.elliptical_comps.elliptical_comps_0 = 0.2
light_profile_model.elliptical_comps.elliptical_comps_1 = 0.0
light_profile_model.intensity = 0.05
light_profile_model.effective_radius = 0.2

iters = 50

"""Use a `PositionsSolver` which does not use grid upscaling."""

solver = al.PositionsSolver(
    grid=grid, use_upscaling=True, pixel_scale_precision=0.0001, upscale_factor=2
)

for i in range(iters):

    """Make a random `MassProfile` instance from the priors defined above."""

    mass_profile = mass_profile_model.random_instance()

    """
    Only the `LightProfile` centre is used by the position solver, but a light profile is used to visalize the
    lensed source.
    """

    light_profile = light_profile_model.random_instance()
Exemplo n.º 6
0
mass_profile_model = af.PriorModel(al.mp.EllipticalIsothermal)
mass_profile_model.centre.centre_0 = 0.0
mass_profile_model.centre.centre_1 = 0.0
mass_profile_model.elliptical_comps.elliptical_comps_0 = af.UniformPrior(
    lower_limit=-1.0, upper_limit=1.0
)
mass_profile_model.elliptical_comps.elliptical_comps_1 = af.UniformPrior(
    lower_limit=-1.0, upper_limit=1.0
)
mass_profile_model.einstein_radius = af.UniformPrior(lower_limit=0.3, upper_limit=2.0)

iters = 50

"""Use a `PositionsSolver` which does not use grid upscaling."""

solver = al.PositionsSolver(grid=grid, use_upscaling=False, upscale_factor=2)

for i in range(iters):

    """Make a random `MassProfile` instance from the priors defined above."""

    mass_profile = mass_profile_model.random_instance()

    """
    Only the `LightProfile` centre is used by the position solver, but a light profile is used to visalize the
    lensed source.
    """

    exponential_light_profile = al.lp.EllipticalExponential(
        centre=(0.0, 0.0),
        elliptical_comps=(0.2, 0.0),
Exemplo n.º 7
0
# grid = al.Grid.from_mask(mask=mask)

grid = al.Grid.uniform(shape_2d=(2500, 2500), pixel_scales=0.0002)

mass_profile = al.mp.EllipticalPowerLaw(centre=(0.001, 0.001),
                                        elliptical_comps=(0.5, 0.5),
                                        einstein_radius=1.0,
                                        slope=1.6)

light_profile = al.lp.EllipticalExponential(centre=(0.1, 0.0),
                                            intensity=0.1,
                                            effective_radius=0.1)

solver = al.PositionsSolver(
    grid=grid,
    use_upscaling=False,
    pixel_scale_precision=0.001,
    magnification_threshold=0.0,
)

positions = solver.solve(lensing_obj=mass_profile,
                         source_plane_coordinate=light_profile.centre)

lens_galaxy = al.Galaxy(redshift=0.5, mass=mass_profile)
source_galaxy = al.Galaxy(redshift=1.0, light=light_profile)
tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])

visuals_2d = aplt.Visuals2D(positions=positions)

magnification = tracer.magnification_from_grid(grid=grid)
magnification = np.nan_to_num(magnification)
print(magnification)
"""
point_source = al.ps.PointSource(centre=(0.07, 0.07))

source_galaxy = al.Galaxy(redshift=1.0, point=point_source)

tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])
"""
For a `PointSource`, our goal is to find the (y,x) coordinates in the image-plane that directly map to the centre
of the `PointSource` in the source plane. In this example, we therefore need to compute the 4 image-plane that map
directly to the location (0.07", 0.07") in the source plane.

This is an iterative problem that requires us to use the `PositionsFinder`. 
"""
solver = al.PositionsSolver(
    grid=grid,
    pixel_scale_precision=0.001,
    upscale_factor=2,
    distance_from_source_centre=0.01,
)
"""
We now pass the `Tracer` to the solver. This will then find the image-plane coordinates that map directly to the
source-plane coordinate (0.07", 0.07").
"""
positions = solver.solve(lensing_obj=tracer,
                         source_plane_coordinate=(0.07, 0.07))

grid_plotter = aplt.Grid2DPlotter(grid=positions)
grid_plotter.figure_2d()
"""
At this point, you might be wondering why don't we use the image of the lensed source to compute our multiple images?
Can`t we just find the pixels in the image whose flux is brighter than its neighboring pixels? 
"""
tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid)
tracer_plotter.figures_2d(image=True)
"""
__Point Source__

It is common for galaxy cluster datasets to be modeled assuming that the source is a point-source. Even if it isn't,
this can be necessary due to computational run-time making it unfeasible to fit the imaging dataset outright.

We will use a `PositionSolver` to locate the multiple images, using computationally slow but robust settings to ensure w
e accurately locate the image-plane positions.
"""
solver = al.PositionsSolver(
    grid=grid,
    use_upscaling=True,
    pixel_scale_precision=0.001,
    upscale_factor=2,
    magnification_threshold=1.0,
)
"""
We now pass the `Tracer` to the solver. This will then find the image-plane coordinates that map directly to the
source-plane coordinate (0.0", 0.0").
"""
positions = solver.solve(lensing_obj=tracer,
                         source_plane_coordinate=source_galaxy.point_0.centre)

positions = al.Grid2DIrregular(grid=[
    positions.in_list[0],
    positions.in_list[2],
    positions.in_list[3],
    positions.in_list[-1],
Exemplo n.º 10
0
path = "{}".format(os.path.dirname(os.path.realpath(__file__)))
pickle_path = f"{path}/pickles"

# %%
"""The initial grid for position solver which is upscaled iteratively by the solver."""

# %%
grid = al.Grid2D.uniform(
    shape_native=(200, 200),
    pixel_scales=
    0.05,  # <- The pixel-scale describes the conversion from pixel units to arc-seconds.
)
"""Use a `PositionsSolver` which uses grid upscaling."""

solver = al.PositionsSolver(grid=grid,
                            pixel_scale_precision=0.01,
                            upscale_factor=3)

iters = 50

for i in range(iters):

    tracer = al.Tracer.load(file_path=pickle_path, filename=f"tracer_{str(i)}")

    positions = solver.solve(
        lensing_obj=tracer,
        source_plane_coordinate=tracer.source_plane.galaxies[0].light.centre,
    )

    positions_true = al.Grid2DIrregular.load(file_path=pickle_path,
                                             filename=f"positions_{str(i)}")