-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtutorial_0_visualization.py
More file actions
144 lines (107 loc) · 4.68 KB
/
Copy pathtutorial_0_visualization.py
File metadata and controls
144 lines (107 loc) · 4.68 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
"""
Tutorial 0: Visualization
=========================
In this tutorial, we quickly cover visualization in **PyAutoLens** and make sure images display
clearly in your Jupyter notebook and on your computer screen.
__Contents__
- **Directories:** **PyAutoLens assumes** the working directory is `autolens_workspace` on your hard-disk.
- **Dataset:** Load and plot the strong lens dataset.
- **Subplots:** In addition to plotting individual figures, **PyAutoLens** can plot `subplots` which show multiple.
- **Plot Customization:** Does the figure display correctly on your computer screen?
- **Overlays:** Overlays such as critical curves and image positions are added using the `lines=` and `positions=`.
- **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()
"""
If the printed working directory does not match the workspace path on your computer, you can manually set it
as follows (the example below shows the path I would use on my laptop. The code is commented out so you do not
use this path in this tutorial!
"""
# workspace_path = "/Users/Jammy/Code/PyAuto/autolens_workspace"
# #%cd $workspace_path
# print(f"Working Directory has been set to `{workspace_path}`")
"""
__Dataset__
The `dataset_path` specifies where the dataset is located, which is the
directory `autolens_workspace/dataset/imaging/simple__no_lens_light`.
There are many example simulated images of strong lenses in this directory that will be used throughout the
**HowToLens** lectures.
"""
from pathlib import Path
import autolens as al
import autolens.plot as aplt
dataset_path = Path("dataset") / "imaging" / "simple__no_lens_light"
"""
We now load this dataset from .fits files and create an instance of an `Imaging` object.
"""
dataset = al.Imaging.from_fits(
data_path=dataset_path / "data.fits",
noise_map_path=dataset_path / "noise_map.fits",
psf_path=dataset_path / "psf.fits",
pixel_scales=0.1,
)
"""
We can plot an image with `aplt.plot_array()`, passing the data array and a title.
"""
aplt.plot_array(array=dataset.data, title="Dataset Image")
"""
__Subplots__
In addition to plotting individual figures, **PyAutoLens** can plot `subplots` which show multiple
views of the dataset at once.
The `aplt.subplot_imaging_dataset()` function plots the data, noise-map and PSF together.
"""
aplt.subplot_imaging_dataset(dataset=dataset)
"""
__Plot Customization__
Does the figure display correctly on your computer screen?
If not, the default matplotlib settings can be customized via the config files in:
autolens_workspace/config/visualize/
Key config entries:
- `mat_wrap.yaml` -> Figure -> figure: -> figsize
- `mat_wrap.yaml` -> YLabel -> figure: -> fontsize
- `mat_wrap.yaml` -> XLabel -> figure: -> fontsize
- `mat_wrap.yaml` -> TickParams -> figure: -> labelsize
- `mat_wrap.yaml` -> YTicks -> figure: -> labelsize
- `mat_wrap.yaml` -> XTicks -> figure: -> labelsize
For quick one-off adjustments you can pass `title=`, `colormap=`, and `use_log10=` directly:
"""
aplt.plot_array(array=dataset.data, title="Dataset Image (Log10)", use_log10=True)
"""
__Overlays__
Overlays such as critical curves and image positions are added using the `lines=` and `positions=`
keyword arguments.
For example, we can compute the critical curves of a tracer and overlay them on the image.
"""
grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=0.05)
lens_galaxy = al.Galaxy(
redshift=0.5,
mass=al.mp.Isothermal(centre=(0.0, 0.0), einstein_radius=1.6, ell_comps=(0.0, 0.0)),
)
source_galaxy = al.Galaxy(
redshift=1.0,
bulge=al.lp.SersicCoreSph(
centre=(0.0, 0.0), intensity=1.0, effective_radius=0.5, sersic_index=2.0
),
)
tracer = al.Tracer(galaxies=[lens_galaxy, source_galaxy])
tangential_critical_curve_list = al.LensCalc.from_tracer(
tracer=tracer
).tangential_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,
)
"""
__Wrap Up__
Throughout the lectures you'll see lots more visuals plotted on figures and subplots.
The key plotting functions you'll use are:
- `aplt.plot_array(array, title, ...)` — plot any 2D array.
- `aplt.plot_grid(grid, title, ...)` — plot a 2D grid of coordinates.
- `aplt.subplot_imaging_dataset(dataset)` — multi-panel dataset overview.
- `aplt.subplot_tracer(tracer, grid)` — multi-panel tracer overview.
- `aplt.subplot_fit_imaging(fit)` — multi-panel fit overview.
Great! Hopefully, visualization in **PyAutoLens** is displaying nicely for us to get on with the
**HowToLens** lecture series.
"""