示例#1
0
def test__all_individual_plotter(
    tracer_x2_plane_7x7, sub_grid_7x7, mask_7x7, include_2d_all, plot_path, plot_patch
):

    tracer_plotter = aplt.TracerPlotter(
        tracer=tracer_x2_plane_7x7,
        grid=sub_grid_7x7,
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(plot_path, format="png")),
    )

    tracer_plotter.figures(
        image=True,
        source_plane=True,
        convergence=True,
        potential=True,
        deflections_y=True,
        deflections_x=True,
        magnification=True,
    )

    assert path.join(plot_path, "image.png") in plot_patch.paths
    assert path.join(plot_path, "plane_image_of_plane_1.png") in plot_patch.paths
    assert path.join(plot_path, "convergence.png") in plot_patch.paths
    assert path.join(plot_path, "potential.png") in plot_patch.paths
    assert path.join(plot_path, "deflections_y.png") in plot_patch.paths
    assert path.join(plot_path, "deflections_x.png") in plot_patch.paths
    assert path.join(plot_path, "magnification.png") in plot_patch.paths

    tracer_x2_plane_7x7.planes[0].galaxies[0].hyper_galaxy = al.HyperGalaxy()
    tracer_x2_plane_7x7.planes[0].galaxies[0].hyper_model_image = al.Array2D.ones(
        shape_native=(7, 7), pixel_scales=0.1
    )
    tracer_x2_plane_7x7.planes[0].galaxies[0].hyper_galaxy_image = al.Array2D.ones(
        shape_native=(7, 7), pixel_scales=0.1
    )

    tracer_plotter.figures(contribution_map=True)

    assert path.join(plot_path, "contribution_map.png") in plot_patch.paths

    plot_patch.paths = []

    tracer_plotter = aplt.TracerPlotter(
        tracer=tracer_x2_plane_7x7,
        grid=sub_grid_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(plot_path, format="png")),
    )

    tracer_plotter.figures(
        image=True, source_plane=True, potential=True, magnification=True
    )

    assert path.join(plot_path, "image.png") in plot_patch.paths
    assert path.join(plot_path, "plane_image_of_plane_1.png") in plot_patch.paths
    assert path.join(plot_path, "convergence.png") not in plot_patch.paths
    assert path.join(plot_path, "potential.png") in plot_patch.paths
    assert path.join(plot_path, "deflections_y.png") not in plot_patch.paths
    assert path.join(plot_path, "deflections_x.png") not in plot_patch.paths
    assert path.join(plot_path, "magnification.png") in plot_patch.paths
def test__fit_sub_plot_real_space(
    fit_interferometer_x2_plane_7x7,
    fit_interferometer_x2_plane_inversion_7x7,
    include_2d_all,
    plot_path,
    plot_patch,
):

    fit_interferometer_plotter = aplt.FitInterferometerPlotter(
        fit=fit_interferometer_x2_plane_7x7,
        include_2d=include_2d_all,
        mat_plot_1d=aplt.MatPlot1D(output=aplt.Output(plot_path, format="png")),
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(plot_path, format="png")),
    )

    fit_interferometer_plotter.subplot_fit_real_space()
    assert path.join(plot_path, "subplot_fit_real_space.png") in plot_patch.paths

    plot_patch.paths = []

    fit_interferometer_plotter = aplt.FitInterferometerPlotter(
        fit=fit_interferometer_x2_plane_inversion_7x7,
        include_2d=include_2d_all,
        mat_plot_1d=aplt.MatPlot1D(output=aplt.Output(plot_path, format="png")),
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(plot_path, format="png")),
    )

    fit_interferometer_plotter.subplot_fit_real_space()
    assert path.join(plot_path, "subplot_fit_real_space.png") in plot_patch.paths
示例#3
0
def simulate_imaging_from_instrument(instrument, dataset_name, galaxies):

    # Simulate the imaging data, remembering that we use a special image which ensures edge-effects don't
    # degrade our modeling of the telescope optics (e.al. the PSF convolution).

    grid = instrument_util.grid_from_instrument(instrument=instrument)

    simulator = simulator_from_instrument(instrument=instrument)

    # Use the input galaxies to setup a tracer, which will generate the image for the simulated imaging data.
    tracer = al.Tracer.from_galaxies(galaxies=galaxies)

    imaging = simulator.from_tracer_and_grid(tracer=tracer, grid=grid)

    # Now, lets output this simulated imaging-data to the test_autoarray/simulator folder.
    test_path = path.join("{}".format(path.dirname(path.realpath(__file__))),
                          "..", "..")

    dataset_path = path.join(test_path, "dataset", "imaging", dataset_name,
                             instrument)

    imaging.output_to_fits(
        image_path=path.join(dataset_path, "image.fits"),
        psf_path=path.join(dataset_path, "psf.fits"),
        noise_map_path=path.join(dataset_path, "noise_map.fits"),
        overwrite=True,
    )

    plotter = aplt.MatPlot2D(
        output=aplt.Output(path=dataset_path, format="png"))
    plotter = aplt.MatPlot2D(
        output=aplt.Output(path=dataset_path, format="png"))

    aplt.Imaging.subplot_imaging(imaging=imaging, plotter=plotter)

    aplt.imaging.individual(
        imaging=imaging,
        image=True,
        noise_map=True,
        psf=True,
        signal_to_noise_map=True,
        plotter=plotter,
    )

    aplt.Tracer.subplot_tracer(tracer=tracer, grid=grid, plotter=plotter)

    aplt.Tracer.figures(
        tracer=tracer,
        grid=grid,
        image=True,
        source_plane=True,
        convergence=True,
        potential=True,
        deflections=True,
        plotter=plotter,
    )
示例#4
0
def test__subhalo_detection_fits(
    masked_imaging_fit_x2_plane_7x7,
    masked_imaging_fit_x2_plane_inversion_7x7,
    include_2d_all,
    plot_path,
    plot_patch,
):

    subhalo_plotter = aplt.SubhaloPlotter(
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(path=plot_path, format="png")),
    )

    subhalo_plotter.subplot_detection_fits(
        fit_imaging_before=masked_imaging_fit_x2_plane_7x7,
        fit_imaging_detect=masked_imaging_fit_x2_plane_7x7,
    )

    assert path.join(plot_path, "subplot_detection_fits.png") in plot_patch.paths

    subhalo_plotter.subplot_detection_fits(
        fit_imaging_before=masked_imaging_fit_x2_plane_inversion_7x7,
        fit_imaging_detect=masked_imaging_fit_x2_plane_inversion_7x7,
    )

    assert path.join(plot_path, "subplot_detection_fits.png") in plot_patch.paths
def test__figures_of_plane(
    tracer_x2_plane_7x7,
    sub_grid_2d_7x7,
    mask_2d_7x7,
    include_2d_all,
    plot_path,
    plot_patch,
):

    tracer_plotter = aplt.TracerPlotter(
        tracer=tracer_x2_plane_7x7,
        grid=sub_grid_2d_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    tracer_plotter.figures_2d_of_planes(plane_image=True, plane_grid=True)

    assert path.join(plot_path,
                     "plane_image_of_plane_0.png") in plot_patch.paths
    assert path.join(plot_path,
                     "plane_image_of_plane_1.png") in plot_patch.paths

    plot_patch.paths = []

    tracer_plotter.figures_2d_of_planes(plane_image=True, plane_index=0)

    assert path.join(plot_path,
                     "plane_image_of_plane_0.png") in plot_patch.paths
    assert path.join(plot_path,
                     "plane_image_of_plane_1.png") not in plot_patch.paths
示例#6
0
def test__subhalo_detection_sub_plot(
    masked_imaging_fit_x2_plane_7x7,
    masked_imaging_fit_x2_plane_inversion_7x7,
    include_2d_all,
    plot_path,
    plot_patch,
):
    arr = al.Array2D.manual_native(array=[[1.0, 2.0], [3.0, 4.0]], pixel_scales=1.0)

    subhalo_plotter = aplt.SubhaloPlotter(
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(path=plot_path, format="png")),
    )

    subhalo_plotter.subplot_detection_imaging(
        fit_imaging_detect=masked_imaging_fit_x2_plane_7x7,
        detection_array=arr,
        mass_array=arr,
    )

    assert path.join(plot_path, "subplot_detection_imaging.png") in plot_patch.paths

    subhalo_plotter.subplot_detection_imaging(
        fit_imaging_detect=masked_imaging_fit_x2_plane_inversion_7x7,
        detection_array=arr,
        mass_array=arr,
    )

    assert path.join(plot_path, "subplot_detection_imaging.png") in plot_patch.paths
示例#7
0
def test__fit_point_quantities_are_output(fit_point_dataset_x2_plane,
                                          include_2d_all, plot_path,
                                          plot_patch):

    fit_point_plotter = aplt.FitPointDatasetPlotter(
        fit=fit_point_dataset_x2_plane,
        include_2d=include_2d_all,
        mat_plot_1d=aplt.MatPlot1D(
            output=aplt.Output(path=plot_path, format="png")),
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    fit_point_plotter.figures_2d(positions=True, fluxes=True)

    assert path.join(plot_path,
                     "fit_point_dataset_positions.png") in plot_patch.paths
    assert path.join(plot_path,
                     "fit_point_dataset_fluxes.png") in plot_patch.paths

    plot_patch.paths = []

    fit_point_plotter.figures_2d(positions=True, fluxes=False)

    assert path.join(plot_path,
                     "fit_point_dataset_positions.png") in plot_patch.paths
    assert path.join(plot_path,
                     "fit_point_dataset_fluxes.png") not in plot_patch.paths

    plot_patch.paths = []

    fit_point_dataset_x2_plane.point_dataset.fluxes = None

    fit_point_plotter = aplt.FitPointDatasetPlotter(
        fit=fit_point_dataset_x2_plane,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    fit_point_plotter.figures_2d(positions=True, fluxes=True)

    assert path.join(plot_path,
                     "fit_point_dataset_positions.png") in plot_patch.paths
    assert path.join(plot_path,
                     "fit_point_dataset_fluxes.png") not in plot_patch.paths
def test_subplot_fit_imaging_is_output(masked_imaging_fit_x2_plane_7x7,
                                       include_2d_all, plot_path, plot_patch):

    fit_imaging_plotter = aplt.FitImagingPlotter(
        fit=masked_imaging_fit_x2_plane_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )

    fit_imaging_plotter.subplot_fit_imaging()
    assert path.join(plot_path, "subplot_fit_imaging.png") in plot_patch.paths
def test__tracer_sub_plot_output(tracer_x2_plane_7x7, sub_grid_7x7,
                                 include_2d_all, plot_path, plot_patch):
    tracer_plotter = aplt.TracerPlotter(
        tracer=tracer_x2_plane_7x7,
        grid=sub_grid_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )

    tracer_plotter.subplot_tracer()
    assert path.join(plot_path, "subplot_tracer.png") in plot_patch.paths
示例#10
0
def test__subplot_fit_point(fit_point_dataset_x2_plane, include_2d_all,
                            plot_path, plot_patch):

    fit_point_plotter = aplt.FitPointDatasetPlotter(
        fit=fit_point_dataset_x2_plane,
        include_2d=include_2d_all,
        mat_plot_1d=aplt.MatPlot1D(
            output=aplt.Output(path=plot_path, format="png")),
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    fit_point_plotter.subplot_fit_point()

    assert path.join(plot_path, "subplot_fit_point.png") in plot_patch.paths
def test__fit_quantities_are_output(masked_imaging_fit_x2_plane_7x7,
                                    include_2d_all, plot_path, plot_patch):

    fit_imaging_plotter = aplt.FitImagingPlotter(
        fit=masked_imaging_fit_x2_plane_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    fit_imaging_plotter.figures(
        image=True,
        noise_map=True,
        signal_to_noise_map=True,
        model_image=True,
        residual_map=True,
        normalized_residual_map=True,
        chi_squared_map=True,
    )

    assert path.join(plot_path, "image.png") in plot_patch.paths
    assert path.join(plot_path, "noise_map.png") in plot_patch.paths
    assert path.join(plot_path, "signal_to_noise_map.png") in plot_patch.paths
    assert path.join(plot_path, "model_image.png") in plot_patch.paths
    assert path.join(plot_path, "residual_map.png") in plot_patch.paths
    assert path.join(plot_path,
                     "normalized_residual_map.png") in plot_patch.paths
    assert path.join(plot_path, "chi_squared_map.png") in plot_patch.paths

    plot_patch.paths = []

    fit_imaging_plotter.figures(
        image=True,
        noise_map=False,
        signal_to_noise_map=False,
        model_image=True,
        chi_squared_map=True,
    )

    assert path.join(plot_path, "image.png") in plot_patch.paths
    assert path.join(plot_path, "noise_map.png") not in plot_patch.paths
    assert path.join(plot_path,
                     "signal_to_noise_map.png") not in plot_patch.paths
    assert path.join(plot_path, "model_image.png") in plot_patch.paths
    assert path.join(plot_path, "residual_map.png") not in plot_patch.paths
    assert path.join(plot_path,
                     "normalized_residual_map.png") not in plot_patch.paths
    assert path.join(plot_path, "chi_squared_map.png") in plot_patch.paths
def test__subplot_point_dataset(point_dataset, include_2d_all, plot_path,
                                plot_patch):

    point_dataset_plotter = aplt.PointDatasetPlotter(
        point_dataset=point_dataset,
        include_2d=include_2d_all,
        mat_plot_1d=aplt.MatPlot1D(
            output=aplt.Output(path=plot_path, format="png")),
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    point_dataset_plotter.subplot_point_dataset()

    assert path.join(plot_path,
                     "subplot_point_dataset.png") in plot_patch.paths
def test__figures_of_plane(masked_imaging_fit_x2_plane_7x7, include_2d_all,
                           plot_path, plot_patch):

    fit_imaging_plotter = aplt.FitImagingPlotter(
        fit=masked_imaging_fit_x2_plane_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    fit_imaging_plotter.figures_of_planes(subtracted_image=True,
                                          model_image=True,
                                          plane_image=True)

    assert path.join(plot_path,
                     "subtracted_image_of_plane_0.png") in plot_patch.paths
    assert path.join(plot_path,
                     "subtracted_image_of_plane_1.png") in plot_patch.paths
    assert path.join(plot_path,
                     "model_image_of_plane_0.png") in plot_patch.paths
    assert path.join(plot_path,
                     "model_image_of_plane_1.png") in plot_patch.paths
    assert path.join(plot_path,
                     "plane_image_of_plane_0.png") in plot_patch.paths
    assert path.join(plot_path,
                     "plane_image_of_plane_1.png") in plot_patch.paths

    plot_patch.paths = []

    fit_imaging_plotter.figures_of_planes(subtracted_image=True,
                                          model_image=True,
                                          plane_image=True,
                                          plane_index=0)

    assert path.join(plot_path,
                     "subtracted_image_of_plane_0.png") in plot_patch.paths
    assert (path.join(plot_path, "subtracted_image_of_plane_1.png")
            not in plot_patch.paths)
    assert path.join(plot_path,
                     "model_image_of_plane_0.png") in plot_patch.paths
    assert path.join(plot_path,
                     "model_image_of_plane_1.png") not in plot_patch.paths
    assert path.join(plot_path,
                     "plane_image_of_plane_0.png") in plot_patch.paths
    assert path.join(plot_path,
                     "plane_image_of_plane_1.png") not in plot_patch.paths
def test__subplot_point_dict(point_dict, include_2d_all, plot_path,
                             plot_patch):

    point_dict_plotter = aplt.PointDictPlotter(
        point_dict=point_dict,
        include_2d=include_2d_all,
        mat_plot_1d=aplt.MatPlot1D(
            output=aplt.Output(path=plot_path, format="png")),
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    point_dict_plotter.subplot_positions()

    assert path.join(plot_path,
                     "subplot_point_dict_positions.png") in plot_patch.paths

    point_dict_plotter.subplot_fluxes()

    assert path.join(plot_path,
                     "subplot_point_dict_fluxes.png") in plot_patch.paths
def test__subplot_of_planes(masked_imaging_fit_x2_plane_7x7, include_2d_all,
                            plot_path, plot_patch):

    fit_imaging_plotter = aplt.FitImagingPlotter(
        fit=masked_imaging_fit_x2_plane_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )

    fit_imaging_plotter.subplot_of_planes()

    assert path.join(plot_path, "subplot_of_plane_0.png") in plot_patch.paths
    assert path.join(plot_path, "subplot_of_plane_1.png") in plot_patch.paths

    plot_patch.paths = []

    fit_imaging_plotter.subplot_of_planes(plane_index=0)
    assert path.join(plot_path, "subplot_of_plane_0.png") in plot_patch.paths
    assert path.join(plot_path,
                     "subplot_of_plane_1.png") not in plot_patch.paths
示例#16
0
Output the simulated dataset to the dataset path as .fits files.
"""
imaging.output_to_fits(
    image_path=path.join(dataset_path, "image.fits"),
    psf_path=path.join(dataset_path, "psf.fits"),
    noise_map_path=path.join(dataset_path, "noise_map.fits"),
    overwrite=True,
)
"""
__Visualize__

Output a subplot of the simulated dataset, the image and the tracer's quantities to the dataset path as .png files.
"""
mat_plot_2d = aplt.MatPlot2D(
    title=aplt.Title(label="Vero Rubin Observator Image"),
    output=aplt.Output(path=dataset_path, format="png"),
)

imaging_plotter = aplt.ImagingPlotter(imaging=imaging, mat_plot_2d=mat_plot_2d)
imaging_plotter.subplot_imaging()
imaging_plotter.figures_2d(image=True)

tracer_plotter = aplt.TracerPlotter(tracer=tracer,
                                    grid=grid,
                                    mat_plot_2d=mat_plot_2d)
tracer_plotter.subplot_tracer()
tracer_plotter.subplot_plane_images()
"""
__Tracer Output__

Save the `Tracer` in the dataset folder as a .json file, ensuring the true light profiles, mass profiles and galaxies
import autolens as al
import autolens.plot as aplt

plotter = aplt.MatPlot2D()
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,
    light=al.lp.SphericalExponential(centre=(0.0, 0.0), intensity=1.0),
    light_1=al.lp.SphericalExponential(centre=(1.0, 1.0), intensity=1.0),
    light_2=al.lp.SphericalExponential(centre=(-1.0, 0.5), intensity=1.0),
)

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.LightProfile.figures(light_profile=lens_galaxy.light, grid=grid)
aplt.galaxy.image(galaxy=lens_galaxy, grid=grid)
aplt.plane.image(plane=tracer.image_plane, grid=grid)

aplt.Tracer.figures(
    tracer=tracer,
    grid=grid,
示例#18
0
Output the profiling run time of the entire fit.
"""
filename = f"{instrument}_fit_time.json"

if os.path.exists(path.join(file_path, filename)):
    os.remove(path.join(file_path, filename))

with open(path.join(file_path, filename), "w") as outfile:
    json.dump(fit_time, outfile)

"""
Output an image of the fit, so that we can inspect that it fits the data as expected.
"""
mat_plot_2d = aplt.MatPlot2D(
    output=aplt.Output(
        path=file_path, filename=f"{instrument}_subplot_fit_imaging", format="png"
    )
)
fit_imaging_plotter = aplt.FitImagingPlotter(fit=fit, mat_plot_2d=mat_plot_2d)
fit_imaging_plotter.subplot_fit_imaging()

mat_plot_2d = aplt.MatPlot2D(
    output=aplt.Output(
        path=file_path, filename=f"{instrument}_subplot_of_plane_1", format="png"
    )
)
fit_imaging_plotter = aplt.FitImagingPlotter(fit=fit, mat_plot_2d=mat_plot_2d)
fit_imaging_plotter.subplot_of_planes(plane_index=1)

"""
The `info_dict` contains all the key information of the analysis which describes its run times.
示例#19
0
fluxes_0 = [flux * np.abs(magnification) for magnification in magnifications_0]
fluxes_0 = al.ValuesIrregular(values=fluxes_0)
fluxes_1 = [flux * np.abs(magnification) for magnification in magnifications_1]
fluxes_1 = al.ValuesIrregular(values=fluxes_1)
"""
We now output the image of this strong lens to `.fits` which can be used for visualize when performing point-source 
modeling and to `.png` for general inspection.
"""
visuals_2d = aplt.Visuals2D(multiple_images=[positions_0, positions_1])

tracer_plotter = aplt.TracerPlotter(tracer=tracer,
                                    grid=grid,
                                    visuals_2d=visuals_2d)
tracer_plotter.figures_2d(image=True)

mat_plot_2d = aplt.MatPlot2D(
    output=aplt.Output(path=dataset_path, filename="image_2d", format="fits"))

tracer_plotter = aplt.TracerPlotter(tracer=tracer,
                                    grid=grid,
                                    mat_plot_2d=mat_plot_2d)
tracer_plotter.figures_2d(image=True)

mat_plot_2d = aplt.MatPlot2D(
    output=aplt.Output(path=dataset_path, format="png"))

tracer_plotter = aplt.TracerPlotter(tracer=tracer,
                                    grid=grid,
                                    mat_plot_2d=mat_plot_2d)
tracer_plotter.subplot_tracer()
tracer_plotter.subplot_plane_images()
"""
"""
We can customize the colorbar using the `Colorbar` matplotlib wrapper object which wraps the following method(s):

 https://matplotlib.org/3.3.2/api/_as_gen/matplotlib.pyplot.colorbar.html
"""
cb = aplt.Colorbar(
    fraction=0.047,
    shrink=5.0,
    aspect=1.0,
    pad=0.01,
    anchor=(0.0, 0.5),
    panchor=(1.0, 0.0),
)

mat_plot_2d = aplt.MatPlot2D(colorbar=cb)

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

"""
The labels of the `Colorbar` can also be customized. 

This uses the `cb.ax.set_yticklabels` to manually override the tick locations and labels:
 
 https://matplotlib.org/3.3.3/api/_as_gen/matplotlib.axes.Axes.set_yticklabels.html
 
The input parameters of both the above methods can be passed into the `Colorbar` object.
"""
cb = aplt.Colorbar(manual_tick_labels=[1.0, 2.0], manual_tick_values=[0.0, 0.25])
print(mapper.source_grid_slim[0])
print("Source Grid2D Pixel 2")
print(source_plane_grid[1])
print(mapper.source_grid_slim[1])
print("etc.")
"""
We can over-lay this grid on the figure, which is starting to look a bit less boring now!
"""
include_2d = aplt.Include2D(mapper_source_grid_slim=True,
                            mapper_source_pixelization_grid=True)

mapper_plotter = aplt.MapperPlotter(mapper=mapper, include_2d=include_2d)
mapper_plotter.set_title("Even less Boring Grid2D of Rectangular Pixels")
mapper_plotter.figure_2d()

mat_plot_2d = aplt.MatPlot2D(axis=aplt.Axis(extent=[-0.3, 0.3, -0.3, 0.3]))

mapper_plotter = aplt.MapperPlotter(mapper=mapper,
                                    mat_plot_2d=mat_plot_2d,
                                    include_2d=include_2d)
mapper_plotter.set_title("Zoomed Grid2D of Rectangular Pixels")
mapper_plotter.figure_2d()
"""
Finally, the mapper`s `pixeliation_grid` has lots of information about the pixelization, for example, the arc-second 
size and dimensions.
"""
print(mapper.source_pixelization_grid.shape_native_scaled)
print(mapper.source_pixelization_grid.scaled_maxima)
print(mapper.source_pixelization_grid.scaled_minima)
"""
__Wrap Up__
imaging_plotter.subplot_imaging()
"""
Output the simulated dataset to the dataset path as .fits files.
"""
imaging.output_to_fits(
    image_path=path.join(dataset_path, "image.fits"),
    psf_path=path.join(dataset_path, "psf.fits"),
    noise_map_path=path.join(dataset_path, "noise_map.fits"),
    overwrite=True,
)
"""
Output a subplot of the simulated dataset, the image and a subplot of the `Tracer`'s quantities to the dataset path 
as .png files.
"""
mat_plot_2d = aplt.MatPlot2D(
    title=aplt.Title(label="Hubble Space Telescope Image"),
    output=aplt.Output(path=dataset_path, format="png"),
)

imaging_plotter = aplt.ImagingPlotter(imaging=imaging, mat_plot_2d=mat_plot_2d)
imaging_plotter.subplot_imaging()
imaging_plotter.figures(image=True)

tracer_plotter = aplt.TracerPlotter(tracer=tracer,
                                    grid=grid,
                                    mat_plot_2d=mat_plot_2d)
tracer_plotter.subplot_tracer()
"""
Pickle the `Tracer` in the dataset folder, ensuring the true `Tracer` is safely stored and available if we need to 
check how the dataset was simulated in the future. 

This will also be accessible via the `Aggregator` if a model-fit is performed using the dataset.
示例#23
0
imaging_plotter.subplot_imaging()
"""
Output the simulated dataset to the dataset path as .fits files.
"""
imaging.output_to_fits(
    image_path=path.join(dataset_path, "image.fits"),
    psf_path=path.join(dataset_path, "psf.fits"),
    noise_map_path=path.join(dataset_path, "noise_map.fits"),
    overwrite=True,
)
"""
Output a subplot of the simulated dataset, the image and a subplot of the `Tracer`'s quantities to the dataset path 
as .png files.
"""
mat_plot_2d = aplt.MatPlot2D(
    title=aplt.Title(label="Keck Adaptive Optics Image"),
    output=aplt.Output(path=dataset_path, format="png"),
)

imaging_plotter = aplt.ImagingPlotter(imaging=imaging, mat_plot_2d=mat_plot_2d)
imaging_plotter.subplot_imaging()
imaging_plotter.figures(image=True)

tracer_plotter = aplt.TracerPlotter(tracer=tracer,
                                    grid=grid,
                                    mat_plot_2d=mat_plot_2d)
tracer_plotter.subplot_tracer()
"""
Pickle the `Tracer` in the dataset folder, ensuring the true `Tracer` is safely stored and available if we need to 
check how the dataset was simulated in the future. 

This will also be accessible via the `Aggregator` if a model-fit is performed using the dataset.
If you use this tool for your own dataset, you *must* double check this pixel scale is correct!
"""
pixel_scales = 0.1
"""
First, load the `Imaging` dataset, so that the lens light centres can be plotted over the strong lens image.
"""
image = al.Array2D.from_fits(file_path=path.join(dataset_path, "image.fits"),
                             pixel_scales=pixel_scales)
"""
Now, create a lens light centre, which is a Coordinate object of (y,x) values.
"""
light_centre = al.Grid2DIrregular(grid=[(0.0, 0.0)])
"""
Now lets plot the image and lens light centre, so we can check that the centre overlaps the lens light.
"""
mat_plot_2d = aplt.MatPlot2D()
visuals_2d = aplt.Visuals2D(light_profile_centres=light_centre)

array_plotter = aplt.Array2DPlotter(array=image,
                                    visuals_2d=visuals_2d,
                                    mat_plot_2d=mat_plot_2d)
array_plotter.figure_2d()
"""
Now we`re happy with the lens light centre(s), lets output them to the dataset folder of the lens, so that we can 
load them from a .json file in our pipelines!
"""
light_centre.output_to_json(file_path=path.join(dataset_path,
                                                "light_centre.json"),
                            overwrite=True)
"""
The workspace also includes a GUI for drawing lens light centres, which can be found at 
示例#25
0
"""
__Imaging__

We can now pass this simulator a tracer, which creates the ray-traced image plotted above and simulates it as an
imaging dataset.
"""
imaging = simulator.via_tracer_from(tracer=tracer, grid=grid)
"""
Lets plot the simulated `Imaging` dataset before we output it to fits, including the (y,x) coordinates of the multiple
images in the image-plane.
"""
visuals_2d = aplt.Visuals2D(multiple_images=positions)

imaging_plotter = aplt.ImagingPlotter(imaging=imaging,
                                      visuals_2d=visuals_2d,
                                      mat_plot_2d=aplt.MatPlot2D())
imaging_plotter.subplot_imaging()
"""
Output the simulated dataset to the dataset path as .fits files.
"""
imaging.output_to_fits(
    image_path=path.join(dataset_path, "image.fits"),
    psf_path=path.join(dataset_path, "psf.fits"),
    noise_map_path=path.join(dataset_path, "noise_map.fits"),
    overwrite=True,
)
"""
__Visualize__

Output a subplot of the simulated dataset, the image and the tracer's quantities to the dataset path as .png files.
"""
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. 
"""
示例#27
0
The benefit of inspecting fits using the aggregator, rather than the files outputs to the hard-disk, is that we can 
customize the plots using the PyAutoLens mat_plot_2d.

Below, we create a new function to apply as a generator to do this. However, we use a convenience method available 
in the PyAutoLens aggregator package to set up the fit.
"""
fit_agg = al.agg.FitImagingAgg(aggregator=agg)
fit_imaging_gen = fit_agg.max_log_likelihood_gen()

for fit in fit_imaging_gen:

    mat_plot_2d = aplt.MatPlot2D(
        figure=aplt.Figure(figsize=(12, 12)),
        title=aplt.Title(label="Custom Image", fontsize=24),
        yticks=aplt.YTicks(fontsize=24),
        xticks=aplt.XTicks(fontsize=24),
        cmap=aplt.Cmap(norm="log", vmax=1.0, vmin=1.0),
        colorbar_tickparams=aplt.ColorbarTickParams(labelsize=20),
        units=aplt.Units(in_kpc=True),
    )

    fit_imaging_plotter = aplt.FitImagingPlotter(fit=fit,
                                                 mat_plot_2d=mat_plot_2d)
    fit_imaging_plotter.figures_2d(normalized_residual_map=True)
"""
Making this plot for a paper? You can output it to hard disk.
"""
fit_agg = al.agg.FitImagingAgg(aggregator=agg)
fit_imaging_gen = fit_agg.max_log_likelihood_gen()

for fit in fit_imaging_gen:
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(
    tracer=tracer, grid=grid, include_2d=include_2d, mat_plot_2d=mat_plot_2d
)
tracer_plotter.figures_2d(source_plane=True)

"""
By specifying two colors to the `CausticsPlot` object the radial and tangential caustics
will be plotted in different colors.

By default, PyAutoLens uses the same alternating colors for the caustics and caustics, so they 
appear the same color on image-plane and source-plane figures.
"""
caustics_plot = aplt.CausticsPlot(c=["r", "w"])
"""
source_plane_grid = image_plane.traced_grid_from(grid=image_plane_grid)

print("Traced source-plane coordinates of `Grid2D` pixel 0:")
print(source_plane_grid.native[0, 0, :])
print("Traced source-plane coordinates of `Grid2D` pixel 1:")
print(source_plane_grid.native[0, 1, :])
"""
We now have grid of coordinates in the source-plane, so we can set up the source-plane as a `Plane` object.
"""
source_plane = al.Plane(galaxies=[source_galaxy])
"""
If its not yet clear what is going on, the figure below should explain below. Lets again plot our `image_plane_grid`,
which we know is a boring uniform grid of $(y,x)$ coordinates, but also plot the source-plane grid.
"""
mat_plot_2d = aplt.MatPlot2D(title=aplt.Title(label="Image-plane Grid"))

plane_plotter = aplt.PlanePlotter(plane=image_plane,
                                  grid=image_plane_grid,
                                  mat_plot_2d=mat_plot_2d)
plane_plotter.figures_2d(plane_grid=True)

mat_plot_2d = aplt.MatPlot2D(title=aplt.Title(label="Source-plane Grid"))

plane_plotter = aplt.PlanePlotter(plane=source_plane,
                                  grid=source_plane_grid,
                                  mat_plot_2d=mat_plot_2d)
plane_plotter.figures_2d(plane_grid=True)
"""
The source-plane looks very interesting! We can see it is not regular, not uniform, and has an aestetically pleasing
visual appearance. Remember that every coordinate on this source-plane grid (e.g. every black dot) corresponds to a 
示例#30
0
    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)

mat_plot_2d = aplt.MatPlot2D(multiple_images_scatter=multiple_images_scatter)

tracer_plotter = aplt.TracerPlotter(
    tracer=tracer, grid=grid, include_2d=include_2d, mat_plot_2d=mat_plot_2d
)
tracer_plotter.figures_2d(image=True)

"""
By specifying two colors to the `MultipleImagesScatter` object the multiple images of each `LightProfile`
would be plotted in different colors (note how the `Galaxy` objects we created above had different redshifts and
each therefore had its own `Plane` in the `Tracer`).
"""
multiple_images_scatter = aplt.MultipleImagesScatter(c=["r", "w"], s=150)

mat_plot_2d = aplt.MatPlot2D(multiple_images_scatter=multiple_images_scatter)