/
welcome.py
170 lines (129 loc) · 6.35 KB
/
welcome.py
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
input(
"\n"
"############################################\n"
"### AUTOLENS WORKSPACE WORKING DIRECTORY ###\n"
"############################################\n\n"
"""
PyAutoLens assumes that the `autolens_workspace` directory is the Python working directory.
This means that, when you run an example script, you should run it from the `autolens_workspace`
as follows:
cd path/to/autolens_workspace (if you are not already in the autolens_workspace).
python3 scripts/imaging/modeling/start_here.py
The reasons for this are so that PyAutoLens can:
- Load configuration settings from config files in the `autolens_workspace/config` folder.
- Load example data from the `autolens_workspace/dataset` folder.
- Output the results of models fits to your hard-disk to the `autolens/output` folder.
If you have any errors relating to importing modules, loading data or outputting results it is likely because you
are not running the script with the `autolens_workspace` as the working directory!
[Press Enter to continue]"""
)
input(
"\n"
"###############################\n"
"##### MATPLOTLIB BACKEND ######\n"
"###############################\n\n"
"""
We`re now going to plot an image in PyAutoLens using Matplotlib, using the backend specified in the following
config file (the backend tells Matplotlib where to render the plot)"
autolens_workspace/config/visualize/general.yaml -> [general] -> `backend`
The default entry for this is `default` (check the config file now). This uses the default Matplotlib backend
on your computer. For most users, pushing Enter now will show the figure without error.
However, we have had reports that if the backend is set up incorrectly on your system this plot can either
raise an error or cause the `welcome.py` script to crash without a message. If this occurs after you
push Enter, the error is because the Matplotlib backend on your computer is set up incorrectly.
To fix this in PyAutoLens, try changing the backend entry in the config file to one of the following values:"
backend=TKAgg
backend=Qt5Agg
backeknd=Qt4Agg
NOTE: If a matplotlib figure window appears, you may need to close it via the X button and then press
enter to continue the script.
[Press Enter to continue]
"""
)
try:
import numba
except ModuleNotFoundError:
input(
"##################\n"
"##### NUMBA ######\n"
"##################\n\n"
"""
Numba is not currently installed.
Numba is a library which makes PyAutoLens run a lot faster. Certain functionality is disabled without numba
and will raise an exception if it is used.
If you have not tried installing numba, I recommend you try and do so now by running the following
commands in your command line / bash terminal now:
pip install --upgrade pip
pip install numba
If your numba installation raises an error and fails, you should go ahead and use PyAutoLens without numba to
decide if it is the right software for you. If it is, you should then commit time to bug-fixing the numba
installation. Feel free to raise an issue on GitHub for support with installing numba.
A warning will crop up throughout your *PyAutoLens** use until you install numba, to remind you to do so.
[Press Enter to continue]
"""
)
import autolens as al
import autolens.plot as aplt
grid = al.Grid2D.uniform(
shape_native=(50, 50),
pixel_scales=0.1, # <- The pixel-scale describes the conversion from pixel units to arc-seconds.
)
sersic_light_profile = al.lp.Exponential(
centre=(0.3, 0.2), ell_comps=(0.2, 0.0), intensity=0.05, effective_radius=1.0
)
light_profile_plotter = aplt.LightProfilePlotter(
light_profile=sersic_light_profile, grid=grid
)
light_profile_plotter.figures_2d(image=True)
input(
"\n"
"##############################\n"
"## LIGHT AND MASS PROFILES ###\n"
"##############################\n\n"
"""
The image displayed on your screen shows a `LightProfile`, the object PyAutoLens uses to represent the
luminous emission of galaxies. This emission is unlensed, which is why it looks like a fairly ordinary and
boring galaxy.
To perform ray-tracing, we need a `MassProfile`, which will be shown after you push [Enter]. The figures will
show deflection angles of the `MassProfile`, vital quantities for performing lensing calculations.
[Press Enter to continue]
"""
)
isothermal_mass_profile = al.mp.Isothermal(
centre=(0.0, 0.0), ell_comps=(0.1, 0.0), einstein_radius=1.6
)
mass_profile_plotter = aplt.MassProfilePlotter(
mass_profile=isothermal_mass_profile, grid=grid
)
mass_profile_plotter.figures_2d(deflections_y=True, deflections_x=True)
input(
"\n"
"########################\n"
"##### RAY TRACING ######\n"
"########################\n\n"
"""
By combining `LightProfile`'s and `MassProfile`'s PyAutoLens can perform ray-tracing and calculate how the
path of the source `Galaxy`'s light-rays are bent by the lens galaxy as they travel to the Earth!
Pushing [Enter] will show the `LightProfile` displayed previously gravitationally lensed by the `MassProfile`.
[Press Enter to continue]
"""
)
lens_galaxy = al.Galaxy(redshift=0.5, mass=isothermal_mass_profile)
source_galaxy = al.Galaxy(redshift=1.0, light=sersic_light_profile)
tracer = al.Tracer(galaxies=[lens_galaxy, source_galaxy])
tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid)
tracer_plotter.figures_2d(image=True)
input(
"\n"
"###########################\n"
"##### WORKSPACE TOUR ######\n"
"###########################\n\n"
"""
PyAutoLens is now set up and you can begin exploring the workspace.
We recommend new users begin by following the 'introduction.ipynb' notebook, which gives an overview
of **PyAutoLens** and the workspace.
A full description of the workspace can be found in the `autolens_workspace/README.rst` file, which you should
also give a quick read through of now!
[Press Enter to continue]
"""
)