Пример #1
0
__Masking__

We now need to mask the data, so that regions where there is no signal (e.g. the edges) are omitted from the fit.
"""
mask = al.Mask2D.circular(shape_native=imaging.shape_native,
                          pixel_scales=imaging.pixel_scales,
                          radius=3.0)
"""
The Imaging object combines the dataset with the mask.
 
Here, the Mask2D is also used to compute the `Grid2D` we used in the lensing.py tutorial to compute lensing calculations.
Note how the Grid2D has also had the mask applied to it.
"""
imaging = imaging.apply_mask(mask=mask)

grid_plotter = aplt.Grid2DPlotter(grid=imaging.grid)
grid_plotter.figure_2d()
"""
Here is what our image looks like with the mask applied, where PyAutoLens has automatically zoomed around the mask
to make the lensed source appear bigger.
"""
imaging_plotter = aplt.ImagingPlotter(imaging=imaging)
imaging_plotter.figures_2d(image=True)
"""
__Fitting__

Following the lensing.py example, we can make a tracer from a collection of `LightProfile`, `MassProfile` and `Galaxy`
objects.

The combination of `LightProfile`'s and `MassProfile`'s below is the same as those used to generate the lensed data-set,
thus it produces a tracer whose image looks exactly like the dataset. As discussed in the lensing.py tutorial, this
# %matplotlib inline
# from pyprojroot import here
# workspace_path = str(here())
# %cd $workspace_path
# print(f"Working Directory has been set to `{workspace_path}`")

import autolens as al
import autolens.plot as aplt
"""
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.
tracer_plotter.figures_2d(image=True)
"""
The `TracerPlotter` includes the `MassProfile` quantities we plotted previously, which can be plotted as a subplot 
that plots all these quantities simultaneously.
"""
tracer_plotter.subplot_tracer()
"""
The `Tracer` is composed of planes, for the system above just two planes, an image-plane (at redshift=0.5) and a 
source-plane (at redshift=1.0). When creating the image from a Tracer, the `MassProfile` is used to `ray-trace` the 
image-plane grid to the source-plane grid, via the `MassProfile`'s deflection angles.

We can use the Tracer`s traced_grid method to plot the image-plane and source-plane grids.
"""
traced_grids = tracer.traced_grid_list_from(grid=grid)

grid_plotter = aplt.Grid2DPlotter(grid=traced_grids[0])
grid_plotter.figure_2d()  # Image-plane grid.

grid_plotter = aplt.Grid2DPlotter(grid=traced_grids[1])
grid_plotter.figure_2d()  # Source-plane grid.
"""
__Extending Objects__

The PyAutoLens API has been designed such that all of the objects introduced above are extensible. `Galaxy` objects can
take many `Profile`'s and `Tracer`'s many `Galaxy`'s. 

If the galaxies are at different redshifts a strong lensing system with multiple lens planes will be created, 
performing complex multi-plane ray-tracing calculations.

To finish, lets create a `Tracer` with 3 galaxies at 3 different redshifts, forming a system with two distinct Einstein
rings! The mass distribution of the first galaxy also has separate components for its stellar mass and dark matter.
"""
We can print this dictionary to see the `name`, `positions` and `fluxes` of the dataset, as well as their noise-map values.
"""
print("Point Source Dict:")
print(point_dict)
"""
We can plot our positions dataset over the observed image.
"""
visuals_2d = aplt.Visuals2D(positions=point_dict.positions_list)

array_plotter = aplt.Array2DPlotter(array=image, visuals_2d=visuals_2d)
array_plotter.figure_2d()
"""
We can also just plot the positions, omitting the image.
"""
grid_plotter = aplt.Grid2DPlotter(grid=point_dict["point_0"].positions)
grid_plotter.figure_2d()
"""
__Model__

We compose our lens model using `Model` objects, which represent the galaxies we fit to our data. In this 
example we fit a lens model where:

 - The lens galaxy's total mass distribution is an `EllIsothermal` [5 parameters].
 - The source galaxy's light is a point `Point` [2 parameters].

The number of free parameters and therefore the dimensionality of non-linear parameter space is N=14.

__Name Pairing__

Every point-source dataset in the `PointDict` has a name, which in this example was `point_0`. This `name` pairs 
Пример #5
0
Load and plot the `PointSourceDict` dataset, which is the dataset used to perform lens modeling.
"""
point_source_dict = al.PointSourceDict.from_json(
    file_path=path.join(dataset_path, "point_source_dict.json"))

print("Point Source Multiple Image (y,x) Arc-second Coordinates:")
print(point_source_dict["point_0"].positions.in_list)
print(point_source_dict["point_1"].positions.in_list)

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

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

grid_plotter = aplt.Grid2DPlotter(grid=point_source_dict["point_0"].positions)
grid_plotter.figure_2d()
grid_plotter = aplt.Grid2DPlotter(grid=point_source_dict["point_1"].positions)
grid_plotter.figure_2d()
"""
__Paths__

The path the results of all chained searches are output:
"""
path_prefix = path.join("point_source", "chaining",
                        "single_plane_to_double_plane")
"""
__PositionsSolver__

Setup the `PositionSolver`.
"""
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? 

Although this would work, the problem is that for positional modeling we want to know the (y,x) coordinates of the 
multiple images at a significantly higher precision than the `Grid2D` we are plotting the image on. In this example, 
the `Grid2D` has a pixel scale of 0.05", however we want to determine our multiple image positions at scales of 0.01"
or less. We could increase our grid resolutin to 0.01" or below, but this will quickly become very computationally
expensive, thus a bespoke `PositionSolver` is required!
"""
    file_path=path.join("dataset", "misc", "deflections_x.fits"),
    pixel_scales=imaging.pixel_scales,
)
"""
Lets plot the deflection angles to make sure they look like what we expect!
"""
aplt.Array2DPlotter(array=deflections_y)
aplt.Array2DPlotter(array=deflections_x)
"""
Lets next load and plot the image-plane grid.
"""
grid = al.Grid2D.from_fits(
    file_path=path.join("dataset", "misc", "grid.fits"),
    pixel_scales=imaging.pixel_scales,
)
grid_plotter = aplt.Grid2DPlotter(grid=grid)
grid_plotter.figure_2d()
"""
We now create our `InputDeflections` `MassProfile`, which represents our input deflection angle map as a 
`MassProfile` in PyAutoLens so that it can be used with objects like `Galaxy`'s and `Tracer`.

This takes as input both the input deflection angles and their corresponding image-plane grid, with the latter used to
compute new sets of deflection angles from the input deflections via interpolation.
"""
image_plane_grid = al.Grid2D.uniform(shape_native=imaging.shape_native,
                                     pixel_scales=imaging.pixel_scales)
input_deflections = al.mp.InputDeflections(
    deflections_y=deflections_y,
    deflections_x=deflections_x,
    image_plane_grid=image_plane_grid,
)
Пример #8
0
In **PyAutoLens**, a `Grid2D` is a set of two-dimensional $(y,x)$ coordinates (in arc-seconds) that are deflected and 
traced by a strong lensing system.

The $(y,x)$ coordinates on the `Grid2D` are aligned with the image we analyze, such that each coordinate maps to the 
centre of each image-pixel. Lets make a `Grid2D` on a grid of 100 x 100 pixels, with a pixel scale (arcsecond-to-pixel 
conversion factor) of 0.05", giving us a 5" x 5" grid.
"""
grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=0.05)
"""
First, lets plot this `Grid2D`, which shows that it is a fairly boring uniform `Grid2D` of dots.
"""
mat_plot_2d = aplt.MatPlot2D(title=aplt.Title(
    label="Fairly Boring Uniform Grid2D Of Dots"))

grid_plotter = aplt.Grid2DPlotter(grid=grid, mat_plot_2d=mat_plot_2d)
grid_plotter.figure_2d()
"""
We can print each coordinate of this `Grid2D`, revealing that it consists of a set of arc-second coordinates (where the 
spacing between each coordinate corresponds to the `pixel_scales` of 0.05" defined above).
"""
print("(y,x) pixel 0:")
print(grid.native[0, 0])
print("(y,x) pixel 1:")
print(grid.native[0, 1])
print("(y,x) pixel 2:")
print(grid.native[0, 2])
print("(y,x) pixel 100:")
print(grid.native[1, 0])
print("etc.")
"""