forked from Jammy2211/autolens_workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwelcome.py
189 lines (138 loc) · 7.3 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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/mass_total__source_parametric.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
[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 installations are not working, feel free to go ahead and use PyAutoGalaxy to decide if it
is the right software for you. If it is and you are still having difficult installing numba, feel free to
raise an issue on GitHub for support with installing numba.
The following warning will crop up throughout your *PyAutoLens** use until you install numba:
[Press Enter to continue]
"""
)
import autolens as al
import autolens.plot as aplt
grid_2d = 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_2d
)
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_2d
)
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]
"""
)
from astropy import cosmology as cosmo
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.from_galaxies(galaxies=[lens_galaxy, source_galaxy])
tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid_2d)
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.
Examples are provided as both Jupyter notebooks in the 'notebooks' folder and Python scripts in the 'scripts'
folder. It is up to you how you would prefer to use PyAutoLens. With these folders, you can find the following
packages:
- howtolens: Jupyter notebook tutorials introducing beginners to strong gravitational lensing, describing how to
perform scientific analysis of lens data and detailing the PyAutoLens API. A great starting point for new users!
- overview: An overview of all PyAutoLens's main features.
- imaging: Examples for analysing and simulating CCD imaging data of a strong lens.
- interferometer: Examples for analysing and simulating interferometer data of a strong lens.
- plot: An API reference guide of all of PyAutoLens's plotting and visualization tools.
- results: Tutorials on how to use PyAutoLens's results after fitting a lens.
- misc: Miscellaneous scripts for specific lens analysis.
The `chaining` folders are for experienced users. The example scripts and HowToLens lectures will guide new users
to these modules when they have sufficient experience and familiarity with PyAutoLens.
[Press Enter to continue]
"""
)