示例#1
0
def test__via_fit_imaging_from(fit_imaging_x2_plane_7x7, grid_2d_7x7):

    visuals_2d = aplt.Visuals2D(origin=(1.0, 1.0), vectors=2)
    include_2d = aplt.Include2D(
        origin=True,
        mask=True,
        border=True,
        light_profile_centres=True,
        mass_profile_centres=True,
        critical_curves=True,
    )

    get_visuals = GetVisuals2D(include=include_2d, visuals=visuals_2d)

    visuals_2d_via = get_visuals.via_fit_imaging_from(
        fit=fit_imaging_x2_plane_7x7)

    assert visuals_2d_via.origin == (1.0, 1.0)
    assert (visuals_2d_via.mask == fit_imaging_x2_plane_7x7.mask).all()
    assert (visuals_2d_via.border ==
            fit_imaging_x2_plane_7x7.mask.border_grid_sub_1.binned).all()
    assert visuals_2d_via.light_profile_centres.in_list == [(0.0, 0.0)]
    assert visuals_2d_via.mass_profile_centres.in_list == [(0.0, 0.0)]
    assert (visuals_2d_via.critical_curves[0] == fit_imaging_x2_plane_7x7.
            tracer.critical_curves_from(grid=grid_2d_7x7)[0]).all()
    assert visuals_2d_via.vectors == 2

    include_2d = aplt.Include2D(
        origin=False,
        mask=False,
        border=False,
        light_profile_centres=False,
        mass_profile_centres=False,
        critical_curves=False,
    )

    get_visuals = GetVisuals2D(include=include_2d, visuals=visuals_2d)

    visuals_2d_via = get_visuals.via_fit_imaging_from(
        fit=fit_imaging_x2_plane_7x7)

    assert visuals_2d_via.origin == (1.0, 1.0)
    assert visuals_2d_via.mask is None
    assert visuals_2d_via.border is None
    assert visuals_2d_via.light_profile_centres is None
    assert visuals_2d_via.mass_profile_centres is None
    assert visuals_2d_via.critical_curves is None
    assert visuals_2d_via.vectors == 2

"""
Next, we'll use the magnification based source to fit this data.
"""
source_magnification = al.Galaxy(
    redshift=1.0,
    pixelization=al.pix.DelaunayMagnification(shape=(30, 30)),
    regularization=al.reg.Constant(coefficient=3.3),
)

fit = fit_imaging_with_source_galaxy(imaging=imaging,
                                     source_galaxy=source_magnification)

include_2d = aplt.Include2D(mask=True,
                            mapper_data_pixelization_grid=True,
                            mapper_source_pixelization_grid=True)

fit_imaging_plotter = aplt.FitImagingPlotter(fit=fit, include_2d=include_2d)
fit_imaging_plotter.subplot_fit_imaging()
fit_imaging_plotter.figures_2d_of_planes(plane_image=True, plane_index=1)
"""
Okay, so the inversion`s fit looks just like it did in the previous tutorials. Lets quickly remind ourselves that 
the effective regularization weight of each source pixel is our input coefficient value of 3.3.
"""
inversion_plotter = fit_imaging_plotter.inversion_plotter_of_plane(
    plane_index=1)
inversion_plotter.figures_2d_of_mapper(mapper_index=0,
                                       regularization_weights=True)
"""
__Adaptive Regularization__
"""
__Borders__

So, what is a border? In the image-plane, a border is the set of exterior pixels in a mask that are at its border.

Lets plot the image with a circular circular and tell our `ImagingPlotter` to plot the border.
"""
mask_circular = al.Mask2D.circular(
    shape_native=imaging.shape_native,
    pixel_scales=imaging.pixel_scales,
    sub_size=2,
    radius=2.5,
)
imaging = imaging.apply_mask(mask=mask_circular)

include_2d = aplt.Include2D(border=True)

imaging_plotter = aplt.ImagingPlotter(imaging=imaging, include_2d=include_2d)
imaging_plotter.subplot_imaging()
"""
As you can see, for a circular mask the border *is* the edge of the mask (the ring of black dots we're used to 
seeing whenever we plot a mask. 

For an annular mask, pixels on its inner edge are not a part of the border, whereas those on its outer edge are.
"""
mask_annular = al.Mask2D.circular_annular(
    shape_native=imaging.shape_native,
    pixel_scales=imaging.pixel_scales,
    sub_size=2,
    inner_radius=0.8,
    outer_radius=2.5,
image_path = path.join(dataset_path, "image.fits")
image = al.Array2D.from_fits(file_path=image_path, hdu=0, pixel_scales=0.03)
"""
We will also need a mask whose border we will plot on the figure, which we associate with the image.
"""
mask = al.Mask2D.circular_annular(
    shape_native=image.shape_native,
    pixel_scales=image.pixel_scales,
    inner_radius=0.3,
    outer_radius=3.0,
)
masked_image = al.Array2D.manual_mask(array=image.native, mask=mask)
"""
The `Array2D` includes a its border as an internal property, meaning we can plot it via an `Include2D` object.
"""
include_2d = aplt.Include2D(border=True)
array_plotter = aplt.Array2DPlotter(array=masked_image, include_2d=include_2d)
array_plotter.figure_2d()
"""
The appearance of the border is customized using a `BorderScatter` object.

To plot the border this object wraps the following matplotlib method:

 https://matplotlib.org/3.2.2/api/_as_gen/matplotlib.pyplot.scatter.html
"""
border_scatter = aplt.BorderScatter(marker="o", c="r", s=50)

mat_plot_2d = aplt.MatPlot2D(border_scatter=border_scatter)

array_plotter = aplt.Array2DPlotter(array=masked_image,
                                    mat_plot_2d=mat_plot_2d,
示例#5
0
import autolens as al
import autolens.plot as aplt

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

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

aplt.MassProfile.figure_convergence(
    mass_profile=sis_mass_profile,
    grid=grid,
    include=aplt.Include2D(critical_curves=True, caustics=True),
)

# galaxy = al.Galaxy(mass=sis_mass_profile, redshift=1)
#
# aplt.Galaxy.convergence(
#     galaxy=galaxy,
#     grid=grid,
#     include_critical_curves=False,
#     include_caustics=True,
# )
imaging_plotter.figures_2d(image=True)
"""
Before we can fit the imaging data we need to apply the mask to it, which is done using the `apply_mask` method. 

In addition to removing the regions of the image we do not want to fit, this also creates a new grid in the imaging 
data that consists only of image-pixels that are not masked. This grid is used for performing ray-tracing calculations
when we fit the data.
"""
imaging = imaging.apply_mask(mask=mask)
"""
Now the mask is an attribute of the imaging data we can plot it using the `Include2D` object.

Because it is an attribute, the `mask` now also automatically `zooms` our plot around the masked region only. This 
means that if our image is very large, we focus-in on the lens and source galaxies.
"""
include_2d = aplt.Include2D(mask=True)

imaging_plotter = aplt.ImagingPlotter(imaging=imaging, include_2d=include_2d)
imaging_plotter.figures_2d(image=True)
"""
By printing its attributes, we can see that the imaging contains everything we need to fit: a mask, the masked image, 
masked noise-map and psf.
"""
print("Mask2D")
print(imaging.mask)
print()
print("Masked Image:")
print(imaging.image)
print()
print("Masked Noise-Map:")
print(imaging.noise_map)
    galaxies=[lens_galaxy, al.Galaxy(redshift=1.0)])

source_plane_grid = tracer.traced_grids_of_planes_from_grid(
    grid=masked_imaging.grid)[1]

# %%
"""
we'll use another rectangular `Pixelization` and `Mapper` to perform the reconstruction.
"""

# %%
rectangular = al.pix.Rectangular(shape=(25, 25))

mapper = rectangular.mapper_from_grid_and_sparse_grid(grid=source_plane_grid)

include_2d = aplt.Include2D(mask=True, mapper_source_full_grid=True)

mapper_plotter = aplt.MapperPlotter(mapper=mapper, include_2d=include_2d)
mapper_plotter.subplot_image_and_mapper(image=masked_imaging.image)

# %%
"""
And now, finally, we're going to use our `Mapper` to invert the image using an `Inversion`. I'll explain how this 
works in a second - but lets just go ahead and use the `Inversion` first. (Ignore the `regularization` input below for 
now, we'll cover this in the next tutorial).
"""

# %%
inversion = al.Inversion(
    masked_dataset=masked_imaging,
    mapper=mapper,
    shear=al.mp.ExternalShear(elliptical_comps=(0.05, 0.05)),
)

tracer = al.Tracer.from_galaxies(
    galaxies=[lens_galaxy, al.Galaxy(redshift=1.0)])

source_plane_grid = tracer.traced_grids_of_planes_from_grid(
    grid=imaging.grid)[1]
"""
we again use the rectangular pixelization to create the mapper.
"""
rectangular = al.pix.Rectangular(shape=(25, 25))

mapper = rectangular.mapper_from_grid_and_sparse_grid(grid=source_plane_grid)

include_2d = aplt.Include2D(mask=True, mapper_source_grid_slim=True)

mapper_plotter = aplt.MapperPlotter(mapper=mapper, include_2d=include_2d)
mapper_plotter.subplot_image_and_mapper(image=imaging.image)
"""
__Inversion__

Finally, we can now use the `Mapper` to reconstruct the source via an `Inversion`. I'll explain how this works in a 
second, but lets just go ahead and create the inversion first. (Ignore the regularization input below for now, 
we will cover this in the next tutorial).
"""
inversion = al.Inversion(dataset=imaging,
                         mapper=mapper,
                         regularization=al.reg.Constant(coefficient=1.0))
"""
The inversion has reconstructed the source's light on the rectangular pixel grid, which is called the 
"""
__Figures__

We now pass the array to an `Array2DPlotter` and call the `figure` method.
"""
array_plotter = aplt.Array2DPlotter(array=image)
array_plotter.figure_2d()
"""
__Include__

An `Array2D` contains the following attributes which can be plotted automatically via the `Include2D` object.

(By default, an `Array2D` does not contain a `Mask2D`, we therefore manually created an `Array2D` with a mask to illustrate
plotting its mask and border below).
"""
include_2d = aplt.Include2D(origin=True, mask=True, border=True)

mask = al.Mask2D.circular_annular(
    shape_native=image.shape_native,
    pixel_scales=image.pixel_scales,
    inner_radius=0.3,
    outer_radius=3.0,
)
masked_image = al.Array2D.manual_mask(array=image.native, mask=mask)

array_plotter = aplt.Array2DPlotter(array=masked_image, include_2d=include_2d)
array_plotter.figure_2d()
"""
Finish.
"""
fit_imaging_plotter.subplot_fit_imaging()
"""
We can also use a `Pixelization` and `Regularization` (which combined create an `Inversion`. to reconstruct the
source galaxy.

we'll reconstruct the source on a 30 x 30 `Rectangular` source-plane `Pixelization`.
"""
pixelization = al.pix.Rectangular(shape=(30, 30))
"""
A `Mapper` maps the source-pixels to image-pixels, as shown in the figure below. These mappings are used when 
reconstructing the source galaxy's light.
"""
mapper = pixelization.mapper_from_grid_and_sparse_grid(grid=source_plane_grid)

visuals_2d = aplt.Visuals2D(pixelization_indexes=[[312], [314], [350], [370]])
include_2d = aplt.Include2D(grid=True)

mapper_plotter = aplt.MapperPlotter(mapper=mapper,
                                    visuals_2d=visuals_2d,
                                    include_2d=include_2d)

mapper_plotter.subplot_image_and_mapper(image=imaging.image)
"""
We can now use a `Mapper` to perform the `Inversion` and reconstruct the source galaxy's light. 

To perform this `Inverison` we must also input a `Regularization`, which is a prior on how much we smooth the 
source galaxy's light. Try increasing / decreasing the coefficient value to see what effect this has.
"""
regularization = al.reg.Constant(coefficient=1.0)

inversion = al.Inversion(dataset=imaging,
示例#11
0
    v_wavelengths=True,
    uv_wavelengths=True,
    amplitudes_vs_uv_distances=True,
    phases_vs_uv_distances=True,
)
"""
The `InterferometerPlotter` may also plot a subplot of all of these attributes.
"""
interferometer_plotter.subplot_interferometer()
"""
The dirty images of the interferometer dataset can also be plotted, which use the transformer of the interferometer 
to map the visibilities, noise-map or other quantity to a real-space image.
"""
interferometer_plotter.figures_2d(
    dirty_image=True,
    dirty_noise_map=True,
    dirty_signal_to_noise_map=True,
    dirty_inverse_noise_map=True,
)
interferometer_plotter.subplot_dirty_images()
"""
The `Interferometer` contains the following attributes which can be plotted automatically via the `Include2D` object.
"""
include_2d = aplt.Include2D()
interferometer_plotter = aplt.InterferometerPlotter(
    interferometer=interferometer, include_2d=include_2d)
interferometer_plotter.subplot_interferometer()
"""
Finish.
"""
Furthermore, using the `MatPLot2D`, `Visuals2D` and `Include2D` objects visualize any aspect of a fit we're interested 
in and fully customize the figure. 

Before beginning chapter 2 of **HowToLens**, you should checkout the package `autolens_workspace/plot`. This provides a 
full API reference of every plotting option in **PyAutoLens**, allowing you to create your own fully customized 
figures of strong lenses with minimal effort!
"""
mat_plot_2d = aplt.MatPlot2D(
    title=aplt.Title(label="This is the title", color="r", fontsize=20),
    ylabel=aplt.YLabel(label="Label of Y", color="b", fontsize=5, position=(0.2, 0.5)),
    xlabel=aplt.XLabel(label="Label of X", color="g", fontsize=10),
    cmap=aplt.Cmap(cmap="cool", norm="linear"),
)

include_2d = aplt.Include2D(
    origin=True, mask=True, border=True, light_profile_centres=True
)

visuals_2d = aplt.Visuals2D(critical_curves=tracer.critical_curves_from(grid=fit.grid))

light_profile_plotter = aplt.LightProfilePlotter(
    light_profile=fit.tracer.source_plane.galaxies[0].bulge,
    grid=source_plane_grid,
    mat_plot_2d=mat_plot_2d,
    include_2d=include_2d,
    visuals_2d=visuals_2d,
)
light_profile_plotter.set_title("Bulge Image")
light_profile_plotter.figures_2d(image=True)

"""
for `plane_index=1` this is the source-plane image)
"""
fit_imaging_plotter.figures_2d_of_planes(plane_index=0)
fit_imaging_plotter.figures_2d_of_planes(plane_index=1)
"""
A subplot of a plane, showing the above 3 figures,can also be plotted.
"""
fit_imaging_plotter.subplot_of_planes(plane_index=1)
"""`
`FitImaging` contains the following attributes which can be plotted automatically via the `Include2D` object.
"""
include_2d = aplt.Include2D(
    origin=True,
    mask=True,
    border=True,
    light_profile_centres=True,
    mass_profile_centres=True,
    critical_curves=True,
    caustics=True,
)
fit_plotter = aplt.FitImagingPlotter(fit=fit, include_2d=include_2d)
fit_plotter.subplot_fit_imaging()
fit_plotter.subplot_of_planes(plane_index=0)
fit_plotter.subplot_of_planes(plane_index=1)
"""
We can also plot a `FitImaging` which uses an `Inversion`.
"""
source_galaxy = al.Galaxy(
    redshift=1.0,
    pixelization=al.pix.VoronoiMagnification(shape=(25, 25)),
    regularization=al.reg.Constant(coefficient=1.0),
        )

        in_positions_true = util.check_if_positions_in_positions_true(
            positions_true=positions_true, positions=positions, threshold=0.1
        )

        positions_plot = al.Grid2DIrregular(
            coordinates=[
                positions.in_grouped_list[0],
                positions_true.in_grouped_list[0],
            ]
        )

    else:

        minimum_separations = None
        in_positions_true = None

        positions_plot = al.Grid2DIrregular(
            coordinates=[positions_true.in_grouped_list[0]]
        )

    print(positions)

    aplt.Tracer.figures_2d(
        tracer=tracer,
        grid=grid,
        positions=positions_plot,
        include=aplt.Include2D(origin=False, critical_curves=True, caustics=False),
    )
示例#15
0
"""
mapper_plotter = aplt.MapperPlotter(mapper=mapper)
mapper_plotter.subplot_image_and_mapper(image=imaging.image)
"""
The Indexes of `Mapper` plots can be highlighted to show how certain image pixels map to the source plane.
"""
visuals_2d = aplt.Visuals2D(indexes=[0, 1, 2, 3, 4],
                            pix_indexes=[[10, 11], [12, 13, 14]])

mapper_plotter = aplt.MapperPlotter(mapper=mapper, visuals_2d=visuals_2d)
mapper_plotter.subplot_image_and_mapper(image=imaging.image)
"""
__Include__

A `Mapper` contains the following attributes which can be plotted automatically via the `Include2D` object.
"""
include_2d = aplt.Include2D(
    origin=True,
    mask=True,
    border=True,
    mapper_data_pixelization_grid=True,
    mapper_source_pixelization_grid=True,
    mapper_source_grid_slim=True,
)

mapper_plotter = aplt.MapperPlotter(mapper=mapper, include_2d=include_2d)
mapper_plotter.subplot_image_and_mapper(image=imaging.image)
"""
Finish.
"""
示例#16
0
The first traced grid corresponds to the image-plane grid (i.e. before lensing), whereas the second grid is that of
the source-plane.
"""
print("grid image-plane (y,x) coordinate 1")
print(traced_grids[0].native[0, 0])
print("grid image-plane (y,x) coordinate 2")
print(traced_grids[0].native[0, 1])
print("grid source-plane (y,x) coordinate 1")
print(traced_grids[1].native[0, 0])
print("grid source-plane (y,x) coordinate 2")
print(traced_grids[1].native[0, 1])

"""
We can use the `TracerPlotter` to plot these planes and grids.
"""
include_2d = aplt.Include2D(grid=True)

tracer_plotter = aplt.TracerPlotter(
    tracer=tracer, grid=image_plane_grid, include_2d=include_2d
)
tracer_plotter.figures_2d_of_planes(plane_image=True, plane_grid=True, plane_index=0)
tracer_plotter.figures_2d_of_planes(plane_image=True, plane_grid=True, plane_index=1)

"""
A ray-tracing subplot plots the following:

 1) The image, computed by ray-tracing the source-galaxy's light from the source-plane to the image-plane.
 2) The source-plane image, showing the source-galaxy's intrinsic appearance (i.e. if it were not lensed).
 3) The image-plane convergence, computed using the lens galaxy's total mass distribution.
 4) The image-plane gravitational potential, computed using the lens galaxy's total mass distribution.
 5) The image-plane deflection angles, computed using the lens galaxy's total mass distribution.
"""
rectangular = al.pix.Rectangular(shape=(25, 25))
"""
By itself, a pixelization does not tell us much. It has no grid of $(y,x)$ coordinates, no image, and no information
about the lens we are fitting. This information comes when we use the pixelization to create up a `Mapper`, which we
perform below using the (traced) source-plane grid that we created above.
"""
mapper = rectangular.mapper_from_grid_and_sparse_grid(grid=source_plane_grid)
"""
This `Mapper` is a `RectangularMapper`, every `Pixelization` generates it owns mapper.
"""
print(type(mapper))
"""
By plotting our mapper, we now see our `Pixelization`. Its a fairly boring grid of rectangular pixels.
"""
include_2d = aplt.Include2D(mapper_source_grid_slim=False,
                            mapper_source_pixelization_grid=False)

mapper_plotter = aplt.MapperPlotter(mapper=mapper, include_2d=include_2d)
mapper_plotter.set_title("Fairly Boring Grid2D of Rectangular Pixels")
mapper_plotter.figure_2d()
"""
However, the `Mapper` does contain lots of interesting information about our `Pixelization`, for example its 
pixelization_grid tells us where the pixel centers are located.
"""
print("Rectangular Grid2D Pixel Centre 1:")
print(mapper.source_pixelization_grid[0])
print("Rectangular Grid2D Pixel Centre 2:")
print(mapper.source_pixelization_grid[1])
print("Rectangular Grid2D Pixel Centre 3:")
print(mapper.source_pixelization_grid[2])
print("etc.")
示例#18
0
                                            potential=True,
                                            deflections_y=True,
                                            deflections_x=True)
"""
__Include__

A `Galaxy` and its `Grid2D` contains the following attributes which can be plotted automatically via 
the `Include2D` object.

(By default, a `Grid2D` does not contain a `Mask2D`, we therefore manually created a `Grid2D` with a mask to illustrate
plotting its mask and border below).
"""
include_2d = aplt.Include2D(
    origin=True,
    mask=True,
    border=True,
    light_profile_centres=True,
    mass_profile_centres=True,
    critical_curves=True,
)

mask = al.Mask2D.circular(shape_native=grid.shape_native,
                          pixel_scales=grid.pixel_scales,
                          radius=2.0)
masked_grid = al.Grid2D.from_mask(mask=mask)

galaxy_plotter = aplt.GalaxyPlotter(galaxy=galaxy,
                                    grid=masked_grid,
                                    include_2d=include_2d)
galaxy_plotter.figures_2d(image=True)
"""
__Errors__
"""
Lets create a simple uniform grid.
"""
grid = al.Grid2D.uniform(shape_native=(30, 30), pixel_scales=0.1)
"""
We now pass the grid to a `Grid2DPlotter` and call the `figure` method.
"""
grid_plotter = aplt.Grid2DPlotter(grid=grid)
grid_plotter.figure_2d()
"""
We can easily ray-trace grids using a `MassProfile` and plot them with a `Grid2DPlotter`.
"""
mass_profile = al.mp.EllIsothermal(centre=(0.0, 0.0),
                                   elliptical_comps=(0.1, 0.2),
                                   einstein_radius=1.0)
deflections = mass_profile.deflections_2d_from_grid(grid=grid)

lensed_grid = grid.grid_from_deflection_grid(deflection_grid=deflections)

grid_plotter = aplt.Grid2DPlotter(grid=lensed_grid)
grid_plotter.figure_2d()
"""
A `Grid2D` contains the following attributes which can be plotted automatically via the `Include2D` object.
"""
include_2d = aplt.Include2D(origin=True)
grid_plotter = aplt.Grid2DPlotter(grid=lensed_grid, include_2d=include_2d)
grid_plotter.figure_2d()
"""
Finish.
"""
        centre=(0.1, 0.1), intensity=0.3, effective_radius=1.0, sersic_index=2.5
    ),
)

tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])

"""
We also need the `Grid2D` that we can use to make plots of the `Tracer`'s properties.
"""
grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=0.05)


"""
The `Tracer` includes its caustics as an internal property, meaning we can plot them via an `Include2D` object.
"""
include_2d = aplt.Include2D(critical_curves=False, caustics=True)
tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid, include_2d=include_2d)
tracer_plotter.figures_2d(source_plane=True)

"""
The appearance of the caustics is customized using a `CausticsPlot` object.

To plot the caustics this object wraps the following matplotlib method:

 https://matplotlib.org/3.3.3/api/_as_gen/matplotlib.pyplot.plot.html
"""
caustics_plot = aplt.CausticsPlot(linestyle="--", linewidth=10, c="r")

mat_plot_2d = aplt.MatPlot2D(caustics_plot=caustics_plot)

tracer_plotter = aplt.TracerPlotter(
示例#21
0
def test__2d__via_tracer(tracer_x2_plane_7x7, grid_2d_7x7):

    visuals_2d = aplt.Visuals2D(vectors=2)

    include_2d = aplt.Include2D(
        origin=True,
        border=True,
        light_profile_centres=True,
        mass_profile_centres=True,
        critical_curves=True,
    )

    get_visuals = GetVisuals2D(include=include_2d, visuals=visuals_2d)

    visuals_2d_via = get_visuals.via_tracer_from(tracer=tracer_x2_plane_7x7,
                                                 grid=grid_2d_7x7,
                                                 plane_index=0)

    assert visuals_2d_via.origin.in_list == [(0.0, 0.0)]
    assert (visuals_2d_via.border == grid_2d_7x7.mask.border_grid_sub_1.binned
            ).all()
    assert visuals_2d_via.light_profile_centres.in_list == [
        tracer_x2_plane_7x7.galaxies[1].light_profile_0.centre
    ]
    assert visuals_2d_via.mass_profile_centres.in_list == [
        tracer_x2_plane_7x7.galaxies[0].mass_profile_0.centre
    ]
    assert (visuals_2d_via.critical_curves[0] == tracer_x2_plane_7x7.
            critical_curves_from(grid=grid_2d_7x7)[0]).all()
    assert visuals_2d_via.vectors == 2

    include_2d = aplt.Include2D(
        origin=True,
        border=True,
        light_profile_centres=True,
        mass_profile_centres=True,
        caustics=True,
    )

    get_visuals = GetVisuals2D(include=include_2d, visuals=visuals_2d)

    visuals_2d_via = get_visuals.via_tracer_from(tracer=tracer_x2_plane_7x7,
                                                 grid=grid_2d_7x7,
                                                 plane_index=1)

    assert visuals_2d_via.origin.in_list == [(0.0, 0.0)]
    traced_border = tracer_x2_plane_7x7.traced_grid_2d_list_from(
        grid=grid_2d_7x7.mask.border_grid_sub_1.binned)[1]
    assert (visuals_2d_via.border == traced_border).all()
    assert visuals_2d_via.light_profile_centres.in_list == [
        tracer_x2_plane_7x7.galaxies[1].light_profile_0.centre
    ]
    assert visuals_2d_via.mass_profile_centres is None
    assert (visuals_2d_via.caustics[0] == tracer_x2_plane_7x7.caustics_from(
        grid=grid_2d_7x7)[0]).all()

    include_2d = aplt.Include2D(
        origin=False,
        border=False,
        light_profile_centres=False,
        mass_profile_centres=False,
        critical_curves=False,
    )

    get_visuals = GetVisuals2D(include=include_2d, visuals=visuals_2d)

    visuals_2d_via = get_visuals.via_tracer_from(tracer=tracer_x2_plane_7x7,
                                                 grid=grid_2d_7x7,
                                                 plane_index=0)

    assert visuals_2d_via.origin is None
    assert visuals_2d_via.border is None
    assert visuals_2d_via.light_profile_centres is None
    assert visuals_2d_via.mass_profile_centres is None
    assert visuals_2d_via.critical_curves is None
    assert visuals_2d_via.vectors == 2
示例#22
0
    ),
)
tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])

"""
We also need the `Grid2D` that we can use to make plots of the `Tracer`'s properties.
"""
grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=0.05)

"""
The multiple images are an internal property of the `Tracer`, so we can plot them via an `Include2D` object.
"""
include_2d = aplt.Include2D(
    multiple_images=True,
    light_profile_centres=False,
    mass_profile_centres=False,
    critical_curves=False,
    caustics=False,
)
tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid, include_2d=include_2d)
tracer_plotter.figures_2d(image=True)

"""
The appearance of the multiple images are customized using a `MultipleImagesScatter` object.

To plot the multiple images this object wraps the following matplotlib method:

 https://matplotlib.org/3.2.2/api/_as_gen/matplotlib.pyplot.scatter.html
"""
multiple_images_scatter = aplt.MultipleImagesScatter(marker="o", c="r", s=150)
First, lets load an example Hubble Space Telescope image of a real strong lens as an `Array2D`.
"""
dataset_path = path.join("dataset", "slacs", "slacs1430+4105")
image_path = path.join(dataset_path, "image.fits")
image = al.Array2D.from_fits(file_path=image_path, hdu=0, pixel_scales=0.03)

"""
The appearance of a (y,x) `Grid2D` of coordinates is customized using `Scatter` objects. To illustrate this, we will 
customize the appearance of the (y,x) origin on a figure using an `OriginScatter` object.

To plot a (y,x) grids of coordinates (like an origin) these objects wrap the following matplotlib method:

 https://matplotlib.org/3.2.2/api/_as_gen/matplotlib.pyplot.scatter.html
"""
origin_scatter = aplt.OriginScatter(marker="o", s=50)

mat_plot_2d = aplt.MatPlot2D(origin_scatter=origin_scatter)

array_plotter = aplt.Array2DPlotter(
    array=image, include_2d=aplt.Include2D(origin=True), mat_plot_2d=mat_plot_2d
)
array_plotter.figure_2d()

"""
There are numerous (y,x) grids of coordinates that PyAutoLens plots. For example, in addition to the origin,
there are grids like the multiple images of a strong lens, a source-plane grid of traced coordinates, etc.

All of these grids are plotted using a `Scatter` object and they are described in more detail in the 
`plot/include_2d` example scripts. 
"""
示例#24
0
plotter = aplt.MatPlot2D()

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

lens_galaxy = al.Galaxy(
    redshift=0.5,
    mass=al.mp.EllipticalIsothermal(
        centre=(0.0, 0.0), einstein_radius=1.0, elliptical_comps=(0.1, 0.1)
    ),
)

source_galaxy = al.Galaxy(
    redshift=1.0,
    light=al.lp.EllipticalExponential(
        centre=(0.02, 0.01), intensity=1.0, effective_radius=0.5
    ),
)

tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])

aplt.Tracer.figures(
    tracer=tracer,
    grid=grid,
    include=aplt.Include2D(critical_curves=True),
    plotter=plotter,
)

aplt.Tracer.subplot_tracer(
    tracer=tracer, grid=grid, include=aplt.Include2D(caustics=True), plotter=plotter
)
Given the perfect symmetry of the system, every path the source's light takes around the lens galaxy is radially 
identical. Thus, nothing else but a ring of light can form!

This is called an 'Einstein Ring' and its radius is called the 'Einstein Radius', which are both named after the man 
who famously used gravitational lensing to prove his theory of general relativity.

Finally, we plot the `plane-image` of the source galaxy. This image represents how the source intrinsically appears 
in the source-plane (e.g. before it is strongly lensed). 

The source galaxy's light is highly magnified, meaning it appears brighter than otherwise possible. Many Astronomers
use strong lensing to study the most distant and faint galaxies in the Universe, which would otherwise be too faint for 
us to ever observe. Our ability to recover its light before the effects of lensing is therefore vital to studying the
source's properties.
"""
include_2d = aplt.Include2D(grid=True)

plane_plotter = aplt.PlanePlotter(plane=source_plane,
                                  grid=source_plane_grid,
                                  include_2d=include_2d)
plane_plotter.figures_2d(plane_image=True)
"""
We typically avoid plotting the soruce plane grid over a plane image because it obscures its appearance. We do this  
using the `Include2D` plotting object. 
"""
include_2d = aplt.Include2D(grid=False)

plane_plotter = aplt.PlanePlotter(plane=source_plane,
                                  grid=source_plane_grid,
                                  include_2d=include_2d)
plane_plotter.figures_2d(plane_image=True)
示例#26
0
imaging_plotter.subplot_imaging()

# %%
"""
So, what is a border? In the image-plane, a border is the set of exterior pixels in a mask that are at, well, its 
border. Lets plot the image with a circular `Mask2D`, and tell our `ImagingPlotter`.to plot the border as well.
"""

# %%
mask_circular = al.Mask2D.circular(shape_2d=imaging.shape_2d,
                                   pixel_scales=imaging.pixel_scales,
                                   sub_size=2,
                                   radius=2.5)
masked_imaging = al.MaskedImaging(imaging=imaging, mask=mask_circular)

include_2d = aplt.Include2D(border=True)

imaging_plotter = aplt.ImagingPlotter(imaging=masked_imaging,
                                      include_2d=include_2d)
imaging_plotter.subplot_imaging()

# %%
"""
As you can see, for a circular `Mask2D`, the border *is* the edge of our `Mask2D` (the ring of black dots we're used to 
seeing whenever we plot a `Mask2D`.. For an annular `Mask2D`, not every pixel on the edge of the mask is necessarily a 
part of its border!
"""

# %%
mask_annular = al.Mask2D.circular_annular(
    shape_2d=imaging.shape_2d,