-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtutorial_8_summary.py
More file actions
207 lines (156 loc) · 7.98 KB
/
Copy pathtutorial_8_summary.py
File metadata and controls
207 lines (156 loc) · 7.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
"""
Tutorial 9: Summary
===================
In this chapter, we have learnt that:
1) **PyAutoLens** uses Cartesian `Grid2D`'s of $(y,x)$ coordinates to perform ray-tracing.
2) These grids are combined with light and mass profiles to compute images, deflection angles and other quantities.
3) Profiles are grouped together 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 its units to kiloparsecs.
7) The tracer's image can be used to simulate strong lens `Imaging` like it was observed with a real telescope.
8) This data can be fitted, so to as quantify how well a model strong lens system represents the observed image.
In this summary, we'll go over all the different Python objects introduced throughout this chapter and consider how
they come together as one.
__Contents__
- **Start:** Below, we do all the steps we have learned this chapter, making profiles, galaxies, a tracer, etc.
- **Object Composition:** Lets now consider how all of the objects we've covered throughout this chapter (`LightProfile`'s.
- **Visualization:** Furthermore, using the `MatPLot2D` and `lines=`/`positions=` overlays objects we can visualize any.
- **Code Design:** To end, I want to quickly talk about the **PyAutoLens** code-design and structure, which was really.
- **Source Code:** If you do enjoy code, variables, functions, and parameters, you may want to dig deeper into the.
- **Wrap Up:** Summary of the script and next steps.
"""
from autoconf import jax_wrapper # Sets JAX environment before other imports
# from autoconf import setup_notebook; setup_notebook()
from pathlib import Path
import autolens as al
import autolens.plot as aplt
"""
__Start__
Below, we do all the steps we have learned this chapter, making profiles, galaxies, a tracer, etc.
Note that in this tutorial, we omit the lens galaxy's light and include two light profiles in the source representing a
`bulge` and `disk`.
"""
grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=0.05)
lens = al.Galaxy(
redshift=0.5,
mass=al.mp.Isothermal(
centre=(0.0, 0.0), einstein_radius=1.6, ell_comps=(0.17647, 0.0)
),
)
source = al.Galaxy(
redshift=1.0,
bulge=al.lp.SersicCore(
centre=(0.1, 0.1),
ell_comps=(0.0, 0.111111),
intensity=1.0,
effective_radius=1.0,
sersic_index=4.0,
),
disk=al.lp.SersicCore(
centre=(0.1, 0.1),
ell_comps=(0.0, 0.111111),
intensity=1.0,
effective_radius=1.0,
sersic_index=1.0,
),
)
tracer = al.Tracer(galaxies=[lens, source])
"""
__Object Composition__
Lets now consider how all of the objects we've covered throughout this chapter (`LightProfile`'s, `MassProfile`'s,
`Galaxy`'s, `Plane`'s, `Tracer`'s) come together.
The `Tracer`, which contains planes of `Galaxies`, which contains the `Galaxy`'s which contains the `Profile`'s:
"""
print(tracer)
print()
print(tracer.planes[0])
print()
print(tracer.planes[1])
print()
print(tracer.planes[0])
print()
print(tracer.planes[1])
print()
print(tracer.planes[0][0].mass)
print()
print(tracer.planes[1][0].bulge)
print()
print(tracer.planes[1][0].disk)
print()
"""
Once we have a tracer we can therefore use any of the plotting function objects throughout this chapter to plot
any specific aspect, whether it be a profile, galaxy, galaxies or tracer.
For example, if we want to plot the image of the source galaxy's bulge and disk, we can do this in a variety of
different ways.
"""
aplt.plot_array(array=tracer.image_2d_from(grid=grid), title="Image")
source_plane_grid = tracer.traced_grid_2d_list_from(grid=grid)[1]
"""
Understanding how these objects decompose into the different components of a strong lens is important for general
**PyAutoLens** use.
As the strong lens systems that we analyse become more complex, it is useful to know how to decompose their light
profiles, mass profiles, galaxies and planes to extract different pieces of information about the strong lens. For
example, we made our source-galaxy above with two light profiles, a `bulge` and `disk`. We can plot the lensed image of
each component individually, now that we know how to break-up the different components of the tracer.
"""
aplt.plot_array(
array=tracer.planes[1][0].bulge.image_2d_from(grid=source_plane_grid),
title="Bulge Image",
)
aplt.plot_array(
array=tracer.planes[1][0].disk.image_2d_from(grid=source_plane_grid),
title="Disk Image",
)
"""
__Visualization__
Furthermore, using the `MatPLot2D` and `lines=`/`positions=` overlays objects we can visualize any aspect 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!
"""
tangential_critical_curve_list = al.LensCalc.from_tracer(
tracer=tracer
).tangential_critical_curve_list_from(grid=grid)
radial_critical_curve_list = al.LensCalc.from_tracer(
tracer=tracer
).radial_critical_curve_list_from(grid=grid)
aplt.plot_array(
array=tracer.image_2d_from(grid=grid),
title="Tracer Image with Critical Curves",
lines=tangential_critical_curve_list,
)
"""
And, we're done, not just with the tutorial, but the chapter!
__Code Design__
To end, I want to quickly talk about the **PyAutoLens** code-design and structure, which was really the main topic of
this tutorial.
Throughout this chapter, we never talk about anything like it was code. We didn`t refer to 'variables', 'parameters`'
'functions' or 'dictionaries', did we? Instead, we talked about 'galaxies', 'planes' a 'Tracer', etc. We discussed
the objects that we, as scientists, think about when we consider a strong lens system.
Software that abstracts the underlying code in this way follows an `object-oriented design`, and it is our hope
with **PyAutoLens** that we've made its interface (often called the API for short) very intuitive, whether you were
previous familiar with gravitational lensing or a complete newcomer!
__Source Code__
If you do enjoy code, variables, functions, and parameters, you may want to dig deeper into the **PyAutoLens** source
code at some point in the future. Firstly, you should note that all of the code we discuss throughout the **HowToLens**
lectures is not contained in just one project (e.g. the **PyAutoLens** GitHub repository) but in fact four repositories:
**PyAutoFit** - Everything required for lens modeling (the topic of chapter 2): https://github.com/PyAutoLabs/PyAutoFit
**PyAutoArray** - Handles all data structures and Astronomy dataset objects: https://github.com/PyAutoLabs/PyAutoArray
**PyAutoGalaxy** - Contains the light profiles, mass profiles and galaxies: https://github.com/PyAutoLabs/PyAutoGalaxy
**PyAutoLens** - Everything strong lensing: https://github.com/PyAutoLabs/PyAutoLens
Instructions on how to build these projects from source are provided here:
https://pyautolens.readthedocs.io/en/latest/installation/source.html
We take a lot of pride in our source code, so I can promise you its well written, well documented and thoroughly
tested (check out the `test` directory if you're curious how to test code well!).
__Wrap Up__
You`ve learn a lot in this chapter, but what you have not learnt is how to 'model' a real strong gravitational lens.
In the real world, we have no idea what the 'correct' combination of light profiles, mass profiles and galaxies are
that will give a good fit to a lens. Lens modeling is the process of finding the lens model which provides a good fit
and it is the topic of chapter 2 of **HowToLens**.
Finally, if you enjoyed doing the **HowToLens** tutorials please git us a star on the **PyAutoLens** GitHub
repository:
https://github.com/PyAutoLabs/PyAutoLens
Even the smallest bit of exposure via a GitHub star can help our project grow!
"""