Skip to content
Open
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 @@ -55,7 +55,7 @@ AUTO-GENERATED by PyAutoHands — do not edit by hand; regenerate with generate.
- [Tutorial 5: Fit Problems](scripts/chapter_3_pixelizations/tutorial_5_fit_problems.py): Investigate why compact sources can challenge mesh resolution and constant regularization even when the mass model is correct.
- Contents: When the best coefficient is not enough, Three progressively compact sources, Simulating the images, Reconstructing the sources, Finding the preferred regularization, Starting with the extended source, Making the source more compact, A very compact source, Why the mesh becomes a limitation, Why one regularization coefficient becomes a compromise, Why maximizing the evidence does not remove the compromise, Wrap Up
- [Tutorial 6: Adaptive Reconstruction](scripts/chapter_3_pixelizations/tutorial_6_adaptive_reconstruction.py): Combine Delaunay meshes, Hilbert brightness adaptation and adaptive Split regularization in a chained lens-model fit.
- Contents: Adaptive source reconstruction, Returning to the compact-source problem, From an image mesh to a source mesh, Constructing the Delaunay source mesh, Interpolating within a triangle, Regularization on an irregular mesh, Building an adapt image, Placing points with a Hilbert image mesh, Controlling the brightness weighting, Keeping resolution in the faint regions, Reconstructing with the Hilbert mesh, Comparing overlay and Hilbert reconstructions, Smoothing on an irregular mesh, Reconstructing with ConstantSplit, Allowing different smoothing strengths, Controlling the transition with `signal_scale`, Exploring the adaptive coefficients, Does adaptive regularization address the fit problem?, Starting the final modelling chain, Preparing adaptation and the positions likelihood penalty, Defining the adaptive Delaunay model, Running the adaptive Delaunay fit, Inspecting the source and smoothing pattern, Wrap Up
- Contents: Adaptive source reconstruction, Returning to the compact-source problem, From an image mesh to a source mesh, Constructing the Delaunay source mesh, Interpolating within a triangle, Regularization on an irregular mesh, Building an adapt image, Placing points with a Hilbert image mesh, Controlling the brightness weighting, Keeping resolution in the faint regions, The default image mesh: `HilbertSNR`, Reconstructing with the Hilbert mesh, Comparing overlay and Hilbert reconstructions, Smoothing on an irregular mesh, Reconstructing with ConstantSplit, Allowing different smoothing strengths, Controlling the transition with `signal_scale`, Exploring the adaptive coefficients, Does adaptive regularization address the fit problem?, Starting the final modelling chain, Preparing adaptation and the positions likelihood penalty, Defining the adaptive Delaunay model, Running the adaptive Delaunay fit, Inspecting the source and smoothing pattern, Wrap Up

## chapter_4_scaling_up_lensing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"- Placing points with a Hilbert image mesh\n",
"- Controlling the brightness weighting\n",
"- Keeping resolution in the faint regions\n",
"- The default image mesh: `HilbertSNR`\n",
"- Reconstructing with the Hilbert mesh\n",
"- Comparing overlay and Hilbert reconstructions\n",
"- Smoothing on an irregular mesh\n",
Expand Down Expand Up @@ -766,6 +767,68 @@
"\n",
"Because the background can cover much more area than the arcs, even a modest floor can affect the allocation substantially. We should inspect the resulting mesh rather than interpret the floor as a fixed fraction of points assigned to faint regions.\n",
"\n",
"Both `weight_power` and `weight_floor` act on weights divided by the **brightest** value in the adapt image. How the rest of the source is sampled therefore depends on how bright that single peak is.\n",
"\n",
"---\n",
"\n",
"__The default image mesh: `HilbertSNR`__\n",
"\n",
"That dependence on the peak is a problem for real data. Suppose the source contains a compact clump with a signal-to-noise (S/N) of 250, next to an arc at S/N 30. With `weight_power=3.5` and `weight_floor=0.01`, any pixel below S/N ~67 receives the floor weight, so the well-detected arc is weighted like empty sky and receives few points. Lowering the power or raising the floor spreads points more evenly, but then the mesh stops concentrating on the source at all.\n",
"\n",
"The default image mesh, `HilbertSNR`, keeps the Hilbert path but shares out the points differently:\n",
"\n",
"- 25% are spread evenly over the mask, so the background is always covered.\n",
"- 70% follow the source's **absolute** S/N through a soft curve: zero at or below S/N 2, which is noise, rising through S/N 5 and flattening out for bright pixels. Faint detected emission always receives points, and the brightest regions cannot take them all.\n",
"- 5% go to the region near the brightest S/N, giving a compact bright feature extra resolution.\n",
"- No image pixel receives more than 8 points, so a faint source does not have its points piled onto a few pixels.\n",
"\n",
"Because the weighting uses absolute S/N, it expects an S/N map rather than an image in flux units. S/N is the natural input: it is unit-free and comparable between datasets, whereas an image's values depend on its brightness units and exposure. Our dataset contains no foreground light, so its S/N map is simply the data divided by the noise map. In a lens-model fit, the S/N map of each galaxy is the data with every other galaxy's model subtracted, divided by the noise map, as we will use below."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"\n",
"snr_map = al.Array2D(\n",
" values=np.asarray(dataset.data.slim) / np.asarray(dataset.noise_map.slim),\n",
" mask=dataset.mask,\n",
")\n",
"\n",
"snr_image_mesh = al.image_mesh.HilbertSNR(pixels=hilbert_pixels)\n",
"\n",
"snr_image_plane_mesh_grid = snr_image_mesh.image_plane_mesh_grid_from(\n",
" mask=dataset.mask,\n",
" adapt_data=snr_map,\n",
")\n",
"\n",
"aplt.plot_array(array=snr_map, title=\"Signal-to-Noise Map\")\n",
"\n",
"for label, mesh_grid in [\n",
" (\"Hilbert: weight_power=1.0, weight_floor=0.05\", hilbert_image_plane_mesh_grid),\n",
" (\"HilbertSNR (default)\", snr_image_plane_mesh_grid),\n",
"]:\n",
" aplt.plot_array(\n",
" array=dataset.data,\n",
" grid=mesh_grid,\n",
" title=label,\n",
" )"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compare where the two meshes place their points across the arcs, the compact centre and the background.\n",
"\n",
"`HilbertSNR` has no `weight_power` or `weight_floor`. Its defaults were chosen on fits of HST and JWST lenses and checked on sources from a peak S/N of 5 to 1000. They can be changed (for example `background`, the evenly spread share), but in most fits they should not need to be.\n",
"\n",
"Two limits are worth knowing. A very faint source, with only a few pixels above S/N 2, receives most of its points on those pixels. A very bright source, whose detected emission is almost all past the flattening of the soft curve, receives an even spread of points across it.\n",
"\n",
"For the fixed-mass experiments in the rest of this tutorial we keep the `weight_power` mesh, so the effect of each setting stays easy to see. The modelling chain at the end uses `HilbertSNR`, as the workspace examples do.\n",
"\n",
"For our first reconstruction, we return to the mesh already constructed with `weight_power=1.0` and `weight_floor=0.05`. These are starting choices to investigate, rather than settings we have established as optimal.\n",
"\n",
"---\n",
Expand Down Expand Up @@ -1474,73 +1537,38 @@
"\n",
"__Preparing adaptation and the positions likelihood penalty__\n",
"\n",
"We now derive a new adapt image from the fitted MGE result. This replaces the image used in our fixed-mass experiments.\n",
"We now derive the adaptation inputs from the fitted MGE result. They replace the adapt image used in our fixed-mass experiments.\n",
"\n",
"For the modelling chain, we express the fitted source image in signal-to-noise units and cap it at `3.0`. This reduces the dominance of the very brightest peaks, retaining more weight for fainter detected emission.\n",
"`AdaptImages.from_result` does this in one call. It computes each galaxy's S/N map from the result (the data with every other galaxy's model subtracted, divided by the noise map), draws the image mesh of the galaxy we name from its S/N map, and gives the adaptive regularization a soft version of the same S/N map, so the mesh and the regularization adapt to one signal.\n",
"\n",
"The cap affects only the image used to guide adaptation. It does not change the observed data, noise map or image likelihood.\n",
"\n",
"Our example contains no foreground light, so the full model image is the source contribution."
"The S/N maps affect only how the mesh and regularization adapt. They do not change the observed data, noise map or image likelihood."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"\n",
"source_model_image = np.asarray(initial_model_fit.model_data.slim)\n",
"\n",
"source_model_snr = source_model_image / np.asarray(dataset.noise_map.slim)\n",
"\n",
"search_adapt_image = al.Array2D(\n",
" values=np.clip(source_model_snr, a_min=0.0, a_max=3.0),\n",
" mask=dataset.mask,\n",
")\n",
"\n",
"aplt.plot_array(\n",
" array=search_adapt_image,\n",
" title=\"Adapt Image for the Search: Capped Model Signal-to-Noise\",\n",
")"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We construct the Hilbert image mesh from this image. Its image-plane coordinates remain fixed during the next search, while their source-plane positions change as the proposed mass model changes."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"search_image_mesh = al.image_mesh.HilbertSNR(pixels=hilbert_pixels)\n",
"\n",
"search_image_mesh = al.image_mesh.Hilbert(\n",
" pixels=hilbert_pixels,\n",
" weight_power=1.0,\n",
" weight_floor=0.05,\n",
"search_adapt_images = al.AdaptImages.from_result(\n",
" result=initial_result,\n",
" image_mesh={\"source\": search_image_mesh},\n",
")\n",
"\n",
"search_image_plane_mesh_grid = search_image_mesh.image_plane_mesh_grid_from(\n",
" mask=dataset.mask,\n",
" adapt_data=search_adapt_image,\n",
"search_image_plane_mesh_grid = (\n",
" search_adapt_images.galaxy_name_image_plane_mesh_grid_dict[\"('galaxies', 'source')\"]\n",
")\n",
"\n",
"search_adapt_images = al.AdaptImages(\n",
" galaxy_name_image_dict={\n",
" \"('galaxies', 'source')\": search_adapt_image,\n",
" },\n",
" galaxy_name_image_plane_mesh_grid_dict={\n",
" \"('galaxies', 'source')\": search_image_plane_mesh_grid,\n",
" },\n",
"aplt.plot_array(\n",
" array=search_adapt_images.galaxy_name_image_dict[\"('galaxies', 'source')\"],\n",
" title=\"Adaptive Regularization Signal: Soft S/N Map\",\n",
")\n",
"\n",
"aplt.plot_array(\n",
" array=dataset.data,\n",
" grid=search_image_plane_mesh_grid,\n",
" title=\"Hilbert Image Mesh for the Model Search\",\n",
" title=\"HilbertSNR Image Mesh for the Model Search\",\n",
")"
],
"outputs": [],
Expand All @@ -1550,7 +1578,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The dictionaries identify the source by its path in the model, `galaxies.source`. This lets the analysis associate the fixed adaptation inputs with each new source-galaxy instance proposed by the search.\n",
"We named the source by its galaxy name, `\"source\"`; its full path in the model is `('galaxies', 'source')`, which is how the dictionaries store it. This lets the analysis associate the fixed adaptation inputs with each new source-galaxy instance proposed by the search. The image-mesh coordinates remain fixed during the search, while their source-plane positions change as the proposed mass model changes.\n",
"\n",
"Following Chapter 2, Tutorial 5, we also prepare the **positions likelihood penalty** from the initial result."
]
Expand Down Expand Up @@ -1846,7 +1874,7 @@
"\n",
"This tutorial addressed those limitations in stages.\n",
"\n",
"An image-plane overlay gave us source sampling that responds to the lens magnification. A Hilbert image mesh then used a fitted brightness distribution to concentrate more sampling on the source emission. Delaunay triangulation connected the traced points and provided interpolation between their brightness values.\n",
"An image-plane overlay gave us source sampling that responds to the lens magnification. A Hilbert image mesh then used a fitted brightness distribution to concentrate more sampling on the source emission, and the default `HilbertSNR` mesh did so in absolute signal-to-noise, so that a bright peak cannot starve the rest of the source. Delaunay triangulation connected the traced points and provided interpolation between their brightness values.\n",
"\n",
"Split regularization supplied local smoothing comparisons on that irregular mesh. Adaptive Split regularization allowed the strength of those comparisons to vary with the source signal.\n",
"\n",
Expand Down
Loading
Loading