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: mat_plot_2d = aplt.MatPlot2D( title=aplt.Title(label="Hey"),
# %% aplt.Plane.plane_grid( plane=tracer.source_plane, grid=traced_grids[1], axis_limits=[-0.2, 0.2, -0.2, 0.2], plotter=aplt.Plotter(labels=aplt.Labels(title="Source-plane Grid")), ) # %% """ Lets plot the lensing quantities again. Note that, because we supplied our galaxies with redshifts and our `Tracer` with a cosmology, our unit can be converted to kiloparsecs! (This cell can take a bit of time to run) """ # %% sub_plotter = aplt.SubPlotter(units=aplt.Units(in_kpc=True)) aplt.Tracer.subplot_tracer(tracer=tracer, grid=grid, sub_plotter=sub_plotter) # %% """ In the previous example, we saw that the `Tracer` had attributes we plotted (e.g. convergence, potential, etc.). Now we've input an **AstroPy** cosmology and galaxy redshifts, the `Tracer` has attributes associated with its cosmology. We can use the `cosmology_util` module in **PyAutoLens** to compute quantities associated with this cosmology. """ # %% cosmology = tracer.cosmology print("Image-plane arcsec-per-kpc:")
mat_plot_2d = aplt.MatPlot2D(title=title, ylabel=ylabel, xlabel=xlabel) array_plotter = aplt.Array2DPlotter(array=image, mat_plot_2d=mat_plot_2d) array_plotter.figure_2d() """ If we do not manually specify a label, the name of the function used to plot the image will be used as the title and the units of the image will be used for the ylabel and xlabel. """ title = aplt.Title() ylabel = aplt.YLabel() xlabel = aplt.XLabel() mat_plot_2d = aplt.MatPlot2D(title=title, ylabel=ylabel, xlabel=xlabel) array_plotter = aplt.Array2DPlotter(array=image, mat_plot_2d=mat_plot_2d) array_plotter.figure_2d() """ The units can be manually specified. """ mat_plot_2d = aplt.MatPlot2D(units=aplt.Units(in_kpc=True, conversion_factor=5.0)) array_plotter = aplt.Array2DPlotter(array=image, mat_plot_2d=mat_plot_2d) array_plotter.figure_2d() """ Finish. """
mat_plot_2d = aplt.MatPlot2D(axis=aplt.Axis(extent=[-0.2, 0.2, -0.2, 0.2])) tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid, mat_plot_2d=mat_plot_2d) tracer_plotter.set_title("Source-plane Grid2D") tracer_plotter.figures_2d_of_planes(plane_grid=True, plane_index=1) """ __Units__ Lets plot the lensing quantities again. However, we'll now use the `Units` object of the **PyAutoLens** plotter module to set `in_kpc=True` and therefore plot the y and x axes in kiloparsecs. This conversion is performed automatically, using the galaxy redshifts and cosmology. """ mat_plot_2d = aplt.MatPlot2D(units=aplt.Units(in_kpc=True)) tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid, mat_plot_2d=mat_plot_2d) tracer_plotter.subplot_tracer() """ If you're too familiar with Cosmology, it will be unclear how exactly we converted the distance units from arcseconds to kiloparsecs. You'll need to read up on your Cosmology lecture to understand this properly. The `util.cosmology` method provides many methods for calculation different cosmological quantites, which are shown below (if you're not too familiar with cosmology don't worry that you don't know what these mean, it isn't massively important for using **PyAutoLens**). """ cosmology = tracer.cosmology
aplt.array(array=image, plotter=plotter) # The colormap of the arrays can be changed to any of the standard matplotlib colormaps. plotter = aplt.Plotter(labels=aplt.Labels(title="SLACS1430+4105 Image"), cmap=aplt.ColorMap(cmap="spring")) aplt.array(array=image, plotter=plotter) # We can change the x / y axis unit_label from arc-seconds to kiloparsec, by inputting a kiloparsec to arcsecond conversion # factor (for SLACS1430+4105, the lens galaxy is at redshift 0.285, corresponding to the conversion factor below). plotter = aplt.Plotter( labels=aplt.Labels(title="SLACS1430+4105 Image"), units=aplt.Units(in_kpc=True, conversion_factor=6.2), ) aplt.array(array=image, plotter=plotter) # The matplotlib figure can be output to the hard-disk as a png, as follows. plotter = aplt.Plotter( labels=aplt.Labels(title="SLACS1430+4105 Image"), output=aplt.Output(path=workspace_path + "/plotting/plots/", filename="arrays", format="png"), ) aplt.array(array=image, plotter=plotter)