Skip to content

Commit 05f235f

Browse files
Jammy2211Jammy2211
authored andcommitted
updoate mge model_util
1 parent 558218d commit 05f235f

1 file changed

Lines changed: 31 additions & 56 deletions

File tree

autolens/analysis/model_util.py

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
import numpy as np
2+
from typing import Tuple
23

34
import autofit as af
45
import autolens as al
56

67

7-
def mge_start_here_lens_model_from(
8+
def mge_model_from(
89
mask_radius: float,
9-
lens_total_gaussians: int = 20,
10-
source_total_gaussians: int = 20,
11-
lens_gaussian_per_basis: int = 1,
12-
source_gaussian_per_basis: int = 1,
10+
total_gaussians: int = 30,
11+
gaussian_per_basis: int = 1,
12+
centre_prior_is_uniform: bool = True,
13+
centre: Tuple[float, float] = (0.0, 0.0),
1314
) -> af.Collection:
1415
"""
15-
Construct a strong lens model using a Multi-Gaussian Expansion (MGE) for the
16-
lens and source galaxy light, and a Singular Isothermal Ellipsoid (SIE) plus
17-
external shear for the lens mass.
16+
Construct a Multi-Gaussian Expansion (MGE) for the lens or source galaxy light
1817
1918
This model is designed as a "start here" configuration for lens modeling:
19+
2020
- The lens and source light are represented by a Basis object composed of many
2121
Gaussian light profiles with fixed logarithmically spaced widths (`sigma`).
2222
- All Gaussians within each basis share common centres and ellipticity
2323
components, reducing degeneracy while retaining flexibility.
24-
- The lens mass distribution is modeled with an isothermal ellipsoid and an
25-
external shear, a common baseline for strong lensing.
24+
25+
- Users can combine with a lens mass model of their choiuce.
2626
2727
The resulting model provides a good balance of speed, flexibility, and accuracy
2828
for fitting most galaxy-scale strong lenses.
2929
30+
This code is mostly to make the API simple for new users, hiding the technical
31+
details of setting up an MGE. More advanced users may wish to customize the
32+
model further.
33+
3034
Parameters
3135
----------
3236
mask_radius
@@ -66,20 +70,31 @@ def mge_start_here_lens_model_from(
6670
"""
6771

6872
# The sigma values of the Gaussians will be fixed to values spanning 0.01 to the mask radius, 3.0".
69-
log10_sigma_list = np.linspace(-2, np.log10(mask_radius), lens_total_gaussians)
73+
log10_sigma_list = np.linspace(-2, np.log10(mask_radius), total_gaussians)
7074

7175
# By defining the centre here, it creates two free parameters that are assigned below to all Gaussians.
7276

73-
centre_0 = af.UniformPrior(lower_limit=-0.1, upper_limit=0.1)
74-
centre_1 = af.UniformPrior(lower_limit=-0.1, upper_limit=0.1)
77+
if centre_prior_is_uniform:
78+
79+
centre_0 = af.UniformPrior(
80+
lower_limit=centre[0] - 0.1, upper_limit=centre[0] + 0.1
81+
)
82+
centre_1 = af.UniformPrior(
83+
lower_limit=centre[1] - 0.1, upper_limit=centre[1] + 0.1
84+
)
85+
86+
else:
87+
88+
centre_0 = af.GaussianPrior(mean=centre[0], sigma=0.3)
89+
centre_1 = af.GaussianPrior(mean=centre[1], sigma=0.3)
7590

7691
bulge_gaussian_list = []
7792

78-
for j in range(lens_gaussian_per_basis):
93+
for j in range(gaussian_per_basis):
7994
# A list of Gaussian model components whose parameters are customized belows.
8095

8196
gaussian_list = af.Collection(
82-
af.Model(al.lp_linear.Gaussian) for _ in range(lens_total_gaussians)
97+
af.Model(al.lp_linear.Gaussian) for _ in range(total_gaussians)
8398
)
8499

85100
# Iterate over every Gaussian and customize its parameters.
@@ -98,50 +113,10 @@ def mge_start_here_lens_model_from(
98113

99114
# The Basis object groups many light profiles together into a single model component.
100115

101-
bulge = af.Model(
116+
return af.Model(
102117
al.lp_basis.Basis,
103118
profile_list=bulge_gaussian_list,
104119
)
105-
mass = af.Model(al.mp.Isothermal)
106-
shear = af.Model(al.mp.ExternalShear)
107-
lens = af.Model(al.Galaxy, redshift=0.5, bulge=bulge, mass=mass, shear=shear)
108-
109-
# Source:
110-
111-
# By defining the centre here, it creates two free parameters that are assigned to the source Gaussians.
112-
113-
centre_0 = af.GaussianPrior(mean=0.0, sigma=0.3)
114-
centre_1 = af.GaussianPrior(mean=0.0, sigma=0.3)
115-
116-
log10_sigma_list = np.linspace(-2, np.log10(1.0), source_total_gaussians)
117-
118-
bulge_gaussian_list = []
119-
120-
for j in range(source_gaussian_per_basis):
121-
gaussian_list = af.Collection(
122-
af.Model(al.lp_linear.Gaussian) for _ in range(source_total_gaussians)
123-
)
124-
125-
for i, gaussian in enumerate(gaussian_list):
126-
gaussian.centre.centre_0 = centre_0
127-
gaussian.centre.centre_1 = centre_1
128-
gaussian.ell_comps = gaussian_list[0].ell_comps
129-
gaussian.sigma = 10 ** log10_sigma_list[i]
130-
131-
bulge_gaussian_list += gaussian_list
132-
133-
source_bulge = af.Model(
134-
al.lp_basis.Basis,
135-
profile_list=bulge_gaussian_list,
136-
)
137-
138-
source = af.Model(al.Galaxy, redshift=1.0, bulge=source_bulge)
139-
140-
# Overall Lens Model:
141-
142-
model = af.Collection(galaxies=af.Collection(lens=lens, source=source))
143-
144-
return model
145120

146121

147122
def simulator_start_here_model_from():

0 commit comments

Comments
 (0)