Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ AUTO-GENERATED by PyAutoBuild — do not edit by hand; regenerate with generate.
- [__Log Likelihood Function: Multi Gaussian Expansion__](scripts/imaging/features/multi_gaussian_expansion/likelihood_function.py): This script provides a step-by-step guide of the `log_likelihood_function` which is used to fit `Imaging` data with a multi-Gaussian expansion (MGE), which is a superposition of multiple 2D Gaussian linear light profiles.
- Contents: Prerequisites, Dataset, Masked Image Grid, Multiple Gaussians & Linear Light Profiles, Basis, Comparison To Linear Light Profiles Example, LightProfileLinearObjFuncList, Combining Matrices, Mapping Matrix, Image Reconstruction, Likelihood Function, Chi Squared, Noise Normalization Term, Calculate The Log Likelihood, Fit, Galaxy Modeling, Wrap Up
- [Modeling Features: Multi Gaussian Expansion](scripts/imaging/features/multi_gaussian_expansion/modeling.py): A multi Gaussian expansion (MGE) decomposes the lens light into ~15-100 Gaussians, where the `intensity` of every Gaussian is solved for via a linear algebra using a process called an "inversion" (see the `linear_light_profiles.py` feature for a full description of this).
- Contents: Advantages & Disadvantages, Positive Only Solver, MGE Source Galaxy, Model, Dataset & Mask, Over Sampling, Model Cookbook, Search, Analysis, VRAM, Run Time, Result, Source MGE, Wrap Up, Description
- Contents: Advantages & Disadvantages, Positive Only Solver, MGE Source Galaxy, Model, Dataset & Mask, Over Sampling, Model Cookbook, Search, Analysis, VRAM, Run Time, Result, Source MGE, Lens Point Source, Wrap Up, Description
- [Simulator: Lens Light Asymmetric](scripts/imaging/features/multi_gaussian_expansion/simulator.py): The morphological of massive elliptical galaxies which act as strong lens are often asymmetric and irregular, with features such as isophotal twists or radially varying elliptical components.
- Contents: Model, Dataset Paths, Simulate, Ray Tracing, Output, Visualize, Tracer json
- [Multi Gaussian Expansion: SLaM](scripts/imaging/features/multi_gaussian_expansion/slam.py): This script provides an example of the Source, (Lens) Light, and Mass (SLaM) pipelines for fitting a lens model where the source is modeled using a Multi Gaussian Expansion (MGE).
Expand Down
116 changes: 116 additions & 0 deletions notebooks/imaging/features/multi_gaussian_expansion/modeling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"- **Run Time:** Profiling the expected run time of the model-fit.\n",
"- **Result:** Overview of the results of the model-fit.\n",
"- **Source MGE:** As discussed at the beginning of this tutorial, an MGE is an effective way to model the light of a.\n",
"- **Lens Point Source:** Using a compact MGE to model an unresolved point-like source (e.g. an AGN) in the foreground lens.\n",
"- **Wrap Up:** Summary of the script and next steps.\n",
"- **Description:** There is one downside to `Basis` functions, we may compose a model with too much freedom.\n",
"\n",
Expand Down Expand Up @@ -700,6 +701,121 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Lens Point Source__\n",
"\n",
"The MGE is not only suited to a galaxy's extended stellar light -- it is also an effective way to model a compact,\n",
"unresolved point-like component at the centre of the foreground lens galaxy, for example a nuclear starburst, an\n",
"active galactic nucleus (AGN) or an unresolved bulge.\n",
"\n",
"Such a component is modeled as a `Basis` of a small number of linear Gaussians (here 10) which all share the same\n",
"`centre` and elliptical components. Their `sigma` values are fixed to a set of logarithmically spaced values between\n",
"0.01\" and twice the pixel scale of the data. This keeps the basis compact relative to the resolution of the image, so\n",
"that it represents a realistic PSF-convolved point source. Fixing the sigmas and linking the centre and ellipticity\n",
"across all Gaussians keeps the parameter count low: the only free parameters are the shared (y, x) `centre` (given a\n",
"+/- 0.1\" uniform prior) and the two shared elliptical components, for N=4 in total.\n",
"\n",
"The point-source MGE is added to the lens galaxy as an additional light component alongside the extended `bulge` MGE\n",
"composed above, so the lens galaxy's light becomes the sum of its diffuse stellar emission and its compact nuclear\n",
"source. We recreate the Gaussians line-by-line below so you can copy and paste the code into your own scripts."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"# The pixel scale of the data, which sets the maximum Gaussian sigma (and therefore how compact the source is).\n",
"\n",
"pixel_scales = 0.1\n",
"\n",
"total_point_gaussians = 10\n",
"\n",
"# Sigma values span 0.01\" (10**-2) up to twice the pixel scale, keeping the basis compact and point-like.\n",
"\n",
"log10_sigma_list = np.linspace(-2, np.log10(2.0 * pixel_scales), total_point_gaussians)\n",
"\n",
"# The centre is the only free parameter, shared by every Gaussian and given a +/- 0.1\" uniform prior.\n",
"\n",
"centre_0 = af.UniformPrior(lower_limit=-0.1, upper_limit=0.1)\n",
"centre_1 = af.UniformPrior(lower_limit=-0.1, upper_limit=0.1)\n",
"\n",
"point_gaussian_list = af.Collection(\n",
" af.Model(al.lp_linear.Gaussian) for _ in range(total_point_gaussians)\n",
")\n",
"\n",
"for i, gaussian in enumerate(point_gaussian_list):\n",
" gaussian.centre.centre_0 = centre_0 # All Gaussians share the same y centre.\n",
" gaussian.centre.centre_1 = centre_1 # All Gaussians share the same x centre.\n",
" gaussian.ell_comps = point_gaussian_list[\n",
" 0\n",
" ].ell_comps # All Gaussians share the same elliptical components.\n",
" gaussian.sigma = 10 ** log10_sigma_list[i] # Fixed, log-spaced sigma values.\n",
"\n",
"# The Basis groups the Gaussians into a single compact point-source light component.\n",
"\n",
"point = af.Model(al.lp_basis.Basis, profile_list=point_gaussian_list)\n",
"\n",
"# The point-source MGE is added to the lens galaxy alongside its extended `bulge` MGE, `mass` and `shear`.\n",
"\n",
"lens = af.Model(\n",
" al.Galaxy, redshift=0.5, bulge=bulge, point=point, mass=mass, shear=shear\n",
")\n",
"\n",
"model = af.Collection(galaxies=af.Collection(lens=lens, source=source))"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Printing the model info confirms the lens galaxy now has both an extended `bulge` MGE and a compact `point` MGE."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"print(model.info)"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Recreating the Gaussians line-by-line is useful for understanding how the point-source basis is composed, but in\n",
"practice it is more convenient to use the `mge_point_model_from` helper, which builds exactly the same compact basis\n",
"in a single line. It takes the data's `pixel_scales` (which sets the maximum Gaussian `sigma` and therefore how\n",
"compact the source is), the number of Gaussians and the source `centre`:"
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"point = al.model_util.mge_point_model_from(\n",
" pixel_scales=0.1,\n",
" total_gaussians=10,\n",
" centre=(0.0, 0.0),\n",
")\n",
"\n",
"lens = af.Model(\n",
" al.Galaxy, redshift=0.5, bulge=bulge, point=point, mass=mass, shear=shear\n",
")\n",
"\n",
"model = af.Collection(galaxies=af.Collection(lens=lens, source=source))\n",
"\n",
"print(model.info)"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
83 changes: 83 additions & 0 deletions scripts/imaging/features/multi_gaussian_expansion/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- **Run Time:** Profiling the expected run time of the model-fit.
- **Result:** Overview of the results of the model-fit.
- **Source MGE:** As discussed at the beginning of this tutorial, an MGE is an effective way to model the light of a.
- **Lens Point Source:** Using a compact MGE to model an unresolved point-like source (e.g. an AGN) in the foreground lens.
- **Wrap Up:** Summary of the script and next steps.
- **Description:** There is one downside to `Basis` functions, we may compose a model with too much freedom.

Expand Down Expand Up @@ -485,6 +486,88 @@
"""
result = search.fit(model=model, analysis=analysis)

"""
__Lens Point Source__

The MGE is not only suited to a galaxy's extended stellar light -- it is also an effective way to model a compact,
unresolved point-like component at the centre of the foreground lens galaxy, for example a nuclear starburst, an
active galactic nucleus (AGN) or an unresolved bulge.

Such a component is modeled as a `Basis` of a small number of linear Gaussians (here 10) which all share the same
`centre` and elliptical components. Their `sigma` values are fixed to a set of logarithmically spaced values between
0.01" and twice the pixel scale of the data. This keeps the basis compact relative to the resolution of the image, so
that it represents a realistic PSF-convolved point source. Fixing the sigmas and linking the centre and ellipticity
across all Gaussians keeps the parameter count low: the only free parameters are the shared (y, x) `centre` (given a
+/- 0.1" uniform prior) and the two shared elliptical components, for N=4 in total.

The point-source MGE is added to the lens galaxy as an additional light component alongside the extended `bulge` MGE
composed above, so the lens galaxy's light becomes the sum of its diffuse stellar emission and its compact nuclear
source. We recreate the Gaussians line-by-line below so you can copy and paste the code into your own scripts.
"""
# The pixel scale of the data, which sets the maximum Gaussian sigma (and therefore how compact the source is).

pixel_scales = 0.1

total_point_gaussians = 10

# Sigma values span 0.01" (10**-2) up to twice the pixel scale, keeping the basis compact and point-like.

log10_sigma_list = np.linspace(-2, np.log10(2.0 * pixel_scales), total_point_gaussians)

# The centre is the only free parameter, shared by every Gaussian and given a +/- 0.1" uniform prior.

centre_0 = af.UniformPrior(lower_limit=-0.1, upper_limit=0.1)
centre_1 = af.UniformPrior(lower_limit=-0.1, upper_limit=0.1)

point_gaussian_list = af.Collection(
af.Model(al.lp_linear.Gaussian) for _ in range(total_point_gaussians)
)

for i, gaussian in enumerate(point_gaussian_list):
gaussian.centre.centre_0 = centre_0 # All Gaussians share the same y centre.
gaussian.centre.centre_1 = centre_1 # All Gaussians share the same x centre.
gaussian.ell_comps = point_gaussian_list[
0
].ell_comps # All Gaussians share the same elliptical components.
gaussian.sigma = 10 ** log10_sigma_list[i] # Fixed, log-spaced sigma values.

# The Basis groups the Gaussians into a single compact point-source light component.

point = af.Model(al.lp_basis.Basis, profile_list=point_gaussian_list)

# The point-source MGE is added to the lens galaxy alongside its extended `bulge` MGE, `mass` and `shear`.

lens = af.Model(
al.Galaxy, redshift=0.5, bulge=bulge, point=point, mass=mass, shear=shear
)

model = af.Collection(galaxies=af.Collection(lens=lens, source=source))

"""
Printing the model info confirms the lens galaxy now has both an extended `bulge` MGE and a compact `point` MGE.
"""
print(model.info)

"""
Recreating the Gaussians line-by-line is useful for understanding how the point-source basis is composed, but in
practice it is more convenient to use the `mge_point_model_from` helper, which builds exactly the same compact basis
in a single line. It takes the data's `pixel_scales` (which sets the maximum Gaussian `sigma` and therefore how
compact the source is), the number of Gaussians and the source `centre`:
"""
point = al.model_util.mge_point_model_from(
pixel_scales=0.1,
total_gaussians=10,
centre=(0.0, 0.0),
)

lens = af.Model(
al.Galaxy, redshift=0.5, bulge=bulge, point=point, mass=mass, shear=shear
)

model = af.Collection(galaxies=af.Collection(lens=lens, source=source))

print(model.info)

"""
__Wrap Up__

Expand Down
1 change: 1 addition & 0 deletions workspace_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -3503,6 +3503,7 @@
"Run Time",
"Result",
"Source MGE",
"Lens Point Source",
"Wrap Up",
"Description"
],
Expand Down
Loading