<jupyter_start><jupyter_text>__Summary__In this chapter, you've learnt how create and fit strong lenses with PyAutoLens. In particular, you've learnt:1) PyAutoLens uses Cartesian grids of (y,x) coordinates to perform ray-tracing.2) These grids are combined with light and mass profiles to compute images, surface-densities, potentials and deflection angles.3) Profiles are combined to make galaxies.4) Collections of galaxies (at the same redshift) form a plane.5) A tracer can make an image-plane + source-plane strong lens system.6) The Universe's cosmology can be input into this tracer to convert units to physical values.7) The tracer's image-plane image can be used to simulate strong lens imaging observed on a real telescope.8) This data can be fitted, so to as quantify how well a model strong lens system represents the observed image.<jupyter_code>%matplotlib inline

from autolens.data import ccd
from autolens.data.array import mask as ma
from autolens.lens import ray_tracing, lens_fit
from autolens.model.galaxy import galaxy as g
from autolens.lens import lens_data as li
from autolens.model.profiles import light_profiles as lp
from autolens.model.profiles import mass_profiles as mp
from autolens.data.plotters import ccd_plotters
from autolens.model.profiles.plotters import profile_plotters
from autolens.model.galaxy.plotters import galaxy_plotters
from autolens.lens.plotters import plane_plotters
from autolens.lens.plotters import ray_tracing_plotters<jupyter_output><empty_output><jupyter_text>In this summary, we'll consider how flexible the tools PyAutoLens gives you are to study every aspect of a strong lens system. Lets get a 'fit' to a strong lens, by setting up an image, mask, tracer, etc.<jupyter_code># If you are using Docker, the path you should use to output these images is (e.g. comment out this line)
# path = '/home/user/workspace/howtolens/chapter_1_introduction'

# If you arn't using docker, you need to change the path below to the chapter 2 directory and uncomment it
# path = '/path/to/user/workspace/howtolens/chapter_1_introduction'

ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/data/image.fits',
                                       noise_map_path=path+'/data/noise_map.fits',
                                       psf_path=path + '/data/psf.fits', pixel_scale=0.1)
mask = ma.Mask.circular(shape=ccd_data.shape, pixel_scale=ccd_data.pixel_scale, radius_arcsec=3.0)
lens_data = li.LensData(ccd_data=ccd_data, mask=mask)
lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal(centre=(0.0, 0.0), einstein_radius=1.6, axis_ratio=0.7, phi=45.0))
source_galaxy = g.Galaxy(bulge=lp.EllipticalSersic(centre=(0.1, 0.1), axis_ratio=0.8, phi=45.0,
                                                  intensity=1.0, effective_radius=1.0, sersic_index=4.0),
                         disk=lp.EllipticalSersic(centre=(0.1, 0.1), axis_ratio=0.8, phi=45.0,
                                                  intensity=1.0, effective_radius=1.0, sersic_index=1.0))
tracer = ray_tracing.TracerImageSourcePlanes(lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy],
                                             image_plane_grid_stack=lens_data.grid_stack)
fit = lens_fit.fit_lens_data_with_tracer(lens_data=lens_data, tracer=tracer)<jupyter_output><empty_output><jupyter_text>The fit contains our tracer, which contains our planes, which contain our grids and galaxies, which contain our profiles:<jupyter_code>print(fit)
print()
print(fit.tracer)
print()
print(fit.tracer.image_plane)
print()
print(fit.tracer.source_plane)
print()
print(fit.tracer.image_plane.galaxies[0])
print()
print(fit.tracer.source_plane.galaxies[0])
print()
print(fit.tracer.image_plane.galaxies[0].mass)
print()
print(fit.tracer.source_plane.galaxies[0].bulge)
print()
print(fit.tracer.source_plane.galaxies[0].disk)
print()<jupyter_output><autolens.lens.lens_fit.LensProfileFit object at 0x7f4d57d69cc0>

<autolens.lens.ray_tracing.TracerImageSourcePlanes object at 0x7f4d57d69ba8>

<autolens.lens.plane.Plane object at 0x7f4d57d69b00>

<autolens.lens.plane.Plane object at 0x7f4d57d16f60>

Redshift: None
Mass Profiles:
EllipticalIsothermal
centre: (0.0, 0.0)
axis_ratio: 0.7
phi: 45.0
einstein_radius: 1.6
slope: 2.0
core_radius: 0.0

Redshift: None
Light Profiles:
EllipticalSersic
centre: (0.1, 0.1)
axis_ratio: 0.8
phi: 45.0
intensity: 1.0
effective_radius: 1.0
sersic_index: 4.0
EllipticalSersic
centre: (0.1, 0.1)
axis_ratio: 0.8
phi: 45.0
intensity: 1.0
effective_radius: 1.0
sersic_index: 1.0

EllipticalIsothermal
centre: (0.0, 0.0)
axis_ratio: 0.7
phi: 45.0
einstein_radius: 1.6
slope: 2.0
core_radius: 0.0

EllipticalSersic
centre: (0.1, 0.1)
axis_ratio: 0.8
phi: 45.0
intensity: 1.0
effective_radius: 1.0
sersic_index: 4.0

EllipticalSersic
centre: (0.1, 0.1)
axis_ratio: 0.8
phi: 45.0
intensity: 1.0
effective_radius: 1.0
ser[...]<jupyter_text>Using the plotters we've used throughout this chapter, we can visualize any aspect of a fit we're interested in. For example, if we want to plot the image of the source galaxy mass profile, we can do this in a variety of different ways<jupyter_code>ray_tracing_plotters.plot_image_plane_image(tracer=fit.tracer)
plane_plotters.plot_image_plane_image(plane=fit.tracer.source_plane)
galaxy_plotters.plot_intensities(galaxy=fit.tracer.source_plane.galaxies[0], grid=fit.tracer.source_plane.grids[0].regular)<jupyter_output><empty_output><jupyter_text>However, as our fit and ray-tracing becomes more complex, it is useful to know how to decompose their different attributes to extract different things about them. For example, we made our source-galaxy above with two light profiles, a 'bulge' and 'disk. We can plot the image-plane image of each component individually, if we know how to break-up the different components of the fit and tracer.<jupyter_code>profile_plotters.plot_intensities(light_profile=fit.tracer.source_plane.galaxies[0].bulge,
                                  grid=fit.tracer.source_plane.grid_stack.regular, title='Bulge Image-Plane Image')
profile_plotters.plot_intensities(light_profile=fit.tracer.source_plane.galaxies[0].disk,
                                  grid=fit.tracer.source_plane.grid_stack.regular, title='Disk Image-Plane Image')<jupyter_output><empty_output><jupyter_text>The fit also has the lens data, so we can plot the image using the fit too, if we so desire.<jupyter_code>ccd_plotters.plot_ccd_subplot(ccd_data=lens_data.ccd_data)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09134319162045594, 'fraction_numerical': 0.02880468268638324, 'mean_word_length': 4.665794066317627, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '267560', 'license': 'MIT', 'n_tokens_mistral': 2346, 'n_tokens_neox': 2194, 'n_words': 585, 'path': 'workspace/howtolens/chapter_1_introduction/tutorial_9_summary.ipynb', 'repo_name': 'AshKelly/PyAutoLens', 'size': '6492'}