-
Notifications
You must be signed in to change notification settings - Fork 29
/
lens_sie__source_sersic.py
117 lines (95 loc) · 4.21 KB
/
lens_sie__source_sersic.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
import autofit as af
import autolens as al
import autolens.plot as aplt
"""
This script simulates _Imaging_ of a strong lens where:
- The lens galaxy's _MassProfile_ is a *SphericalIsothermal*.
- The source galaxy's _LightProfile_ is a *SphericalExponential*.
This dataset is used in chapter 2, tutorials 1-3.
"""
"""Setup the path to the autolens_workspace, using a relative directory name."""
from pyprojroot import here
workspace_path = str(here())
"""
The 'dataset_type' describes the type of data being simulated (in this case, _Imaging_ data) and 'dataset_name'
gives it a descriptive name. They define the folder the dataset is output to on your hard-disk:
- The image will be output to '/autolens_workspace/dataset/dataset_type/dataset_name/image.fits'.
- The noise-map will be output to '/autolens_workspace/dataset/dataset_type/dataset_name/lens_name/noise_map.fits'.
- The psf will be output to '/autolens_workspace/dataset/dataset_type/dataset_name/psf.fits'.
"""
dataset_type = "chapter_4"
dataset_name = "lens_sie__source_sersic"
"""
Create the path where the dataset will be output, which in this case is:
'/autolens_workspace/howtolens/dataset/chapter_2/lens_sis__source_exp/'
"""
dataset_path = af.util.create_path(
path=workspace_path, folders=["howtolens", "dataset", dataset_type, dataset_name]
)
"""
The grid used to simulate the image.
For simulating an image of a strong lens, we recommend using a GridIterate object. This represents a grid of (y,x)
coordinates like an ordinary Grid, but when the light-profile's image is evaluated below (using the Tracer) the
sub-size of the grid is iteratively increased (in steps of 2, 4, 8, 16, 24) until the input fractional accuracy of
99.99% is met.
This ensures that the divergent and bright central regions of the source galaxy are fully resolved when determining the
total flux emitted within a pixel.
"""
grid = al.GridIterate.uniform(
shape_2d=(100, 100),
pixel_scales=0.1,
fractional_accuracy=0.9999,
sub_steps=[2, 4, 8, 16, 24],
)
"""Simulate a simple Gaussian PSF for the image."""
psf = al.Kernel.from_gaussian(
shape_2d=(11, 11), sigma=0.1, pixel_scales=grid.pixel_scales
)
"""
To simulate the _Imaging_ dataset we first create a simulator, which defines the expoosure time, background sky,
noise levels and psf of the dataset that is simulated.
"""
simulator = al.SimulatorImaging(
exposure_time_map=al.Array.full(fill_value=300.0, shape_2d=grid.shape_2d),
psf=psf,
background_sky_map=al.Array.full(fill_value=0.1, shape_2d=grid.shape_2d),
add_noise=True,
)
"""
Setup the lens galaxy's mass (SIE+Shear) and source galaxy light (elliptical Sersic) for this simulated lens.
For lens modeling, defining ellipticity in terms of the 'elliptical_comps' improves the model-fitting procedure.
However, for simulating a strong lens you may find it more intuitive to define the elliptical geometry using the
axis-ratio of the profile (axis_ratio = semi-major axis / semi-minor axis = b/a) and position angle phi, where phi is
in degrees and defined counter clockwise from the positive x-axis.
We can use the **__PyAutoLens__** *convert* module to determine the elliptical components from the axis-ratio and phi.
"""
lens_galaxy = al.Galaxy(
redshift=0.5,
mass=al.mp.EllipticalIsothermal(
centre=(0.0, 0.0), elliptical_comps=(0.111111, 0.0), einstein_radius=1.6
),
)
source_galaxy = al.Galaxy(
redshift=1.0,
light=al.lp.EllipticalSersic(
centre=(0.0, 0.0),
elliptical_comps=(0.2, 0.1),
intensity=0.2,
effective_radius=0.2,
sersic_index=2.5,
),
)
"""Use these galaxies to setup a tracer, which will generate the image for the simulated _Imaging_ dataset."""
tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])
"""
We can now pass this simulator a tracer, which creates the ray-traced image plotted above and simulates it as an
imaging dataset.
"""
imaging = simulator.from_tracer_and_grid(tracer=tracer, grid=grid)
"""Finally, lets output our simulated dataset to the dataset path as .fits files"""
imaging.output_to_fits(
image_path=f"{dataset_path}/image.fits",
psf_path=f"{dataset_path}/psf.fits",
noise_map_path=f"{dataset_path}/noise_map.fits",
overwrite=True,
)