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
12 changes: 6 additions & 6 deletions scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
r"""
HowToLens: Introduction
=======================

Expand Down Expand Up @@ -171,7 +171,7 @@
"""
aplt.plot_grid(grid=grid_shifted, title="Grid Centered Around (0.3, 0.5)")

"""
r"""
Next, we can rotate the grid by an angle `phi` (in degrees). The rotation is counter-clockwise from the positive x-axis.

To rotate the grid:
Expand Down Expand Up @@ -203,7 +203,7 @@
"""
aplt.plot_grid(grid=grid_rotated, title="Grid Rotated 60 Degrees")

"""
r"""
Next, we convert the rotated grid to elliptical coordinates using:

$\eta = \sqrt{(x_r)^2 + (y_r)^2/q^2}$
Expand All @@ -220,7 +220,7 @@
axis_ratio = 0.5
eta = np.sqrt((grid_rotated[:, 0]) ** 2 + (grid_rotated[:, 1]) ** 2 / axis_ratio**2)

"""
r"""
Above, the angle $\phi$ (in degrees) was used to rotate the grid, and the axis-ratio $q$ was used to convert the grid
to elliptical coordinates.

Expand All @@ -247,7 +247,7 @@
print(ell_comps)


"""
r"""
__Light Profiles__

Galaxies are collections of stars, gas, dust, and other astronomical objects that emit light. Astronomers study this
Expand Down Expand Up @@ -426,7 +426,7 @@
plt.close()


"""
r"""
Since galaxy light distributions often cover a wide range of values, they are typically better visualized on a log10
scale. This approach helps highlight details in the faint outskirts of a light profile.

Expand Down
8 changes: 4 additions & 4 deletions scripts/chapter_1_introduction/tutorial_2_ray_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"""
deflections = sis_mass_profile.deflections_yx_2d_from(grid=image_plane_grid)

"""
r"""
Like grids and arrays, the deflection angles can be accessed using the `native` and `slim` attributes. These are
structured similarly to a `Grid2D` object:

Expand All @@ -151,7 +151,7 @@
"""
print(type(deflections))

"""
r"""
This structure includes a `grid`, which represents the `Grid2D` of coordinates where the deflection angles are
calculated (in this case, the `image_plane_grid` we defined earlier). It also has vector-specific methods,
such as `magnitude`, which calculates the magnitude of each deflection vector using \((x^2 + y^2)^{0.5}\).
Expand Down Expand Up @@ -229,7 +229,7 @@
use_log10=True,
)

"""
r"""
__Ray Tracing Grids__

We now have all the tools we need to perform our first ray-tracing calculation.
Expand Down Expand Up @@ -367,7 +367,7 @@
aplt.plot_grid(grid=image_plane_grid_traced, title="Image Plane Grid")
aplt.plot_grid(grid=source_plane_grid_traced, title="Source Plane Grid")

"""
r"""
__Wrap Up__

In this tutorial, you performed your first lensing calculations. Let's summarise what we've learnt:
Expand Down
6 changes: 3 additions & 3 deletions scripts/chapter_1_introduction/tutorial_4_point_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@

tracer = al.Tracer(galaxies=[lens_galaxy, source_galaxy])

"""
r"""
Note that we attached the point source to its galaxy with the name `point_0`. This name is a label that PyAutoLens
uses when fitting real data to pair each point source in the model with the dataset containing its observed image
positions. With one source the name is a formality, but group- and cluster-scale lenses can contain many point
Expand Down Expand Up @@ -270,7 +270,7 @@
title="Multiple Images and Critical Curve",
)

"""
r"""
__Magnifications__

Lensing does not just relocate a point source's light — it magnifies it. Each multiple image has its own
Expand Down Expand Up @@ -340,7 +340,7 @@
print("Time Delays relative to first image (days):")
print(time_delays - time_delays[0])

"""
r"""
__Extended Versus Point Computations__

We can now state precisely why point-source lensing works so differently from everything in tutorials 2 and 3, on
Expand Down
14 changes: 7 additions & 7 deletions scripts/chapter_1_introduction/tutorial_7_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
aplt.plot_array(array=fit.data, title="Data")
aplt.plot_array(array=fit.model_data, title="Model Image")

"""
r"""
The `residual_map` is the different between the observed image and model image, showing where in the image the fit is
good (e.g. low residuals) and where it is bad (e.g. high residuals).

Expand All @@ -348,7 +348,7 @@

aplt.plot_array(array=fit.residual_map, title="Residual Map")

"""
r"""
Are these residuals indicative of a good fit to the data? Without considering the noise in the data, it's difficult
to ascertain. That is, its hard to ascenrtain if a residual value is large or small because this depends on the
amount of noise in that pixel.
Expand All @@ -372,7 +372,7 @@

aplt.plot_array(array=fit.normalized_residual_map, title="Normalized Residual Map")

"""
r"""
Next, we define the `chi_squared_map`, which is obtained by squaring the `normalized_residual_map` and serves as a
measure of goodness of fit.

Expand All @@ -395,7 +395,7 @@

aplt.plot_array(array=fit.chi_squared_map, title="Chi Squared Map")

"""
r"""
Now, we consolidate all the information in our `chi_squared_map` into a single measure of goodness-of-fit
called `chi_squared`.

Expand Down Expand Up @@ -428,7 +428,7 @@
reduced_chi_squared = chi_squared / dataset.mask.pixels_in_mask
print("Reduced Chi-squared = ", reduced_chi_squared)

"""
r"""
Another quantity that contributes to our final assessment of the goodness-of-fit is the `noise_normalization`.

The `noise_normalization` is computed by summing, over every pixel, the logarithm of 2 pi times the squared noise value:
Expand All @@ -448,7 +448,7 @@
print("Noise Normalization = ", noise_normalization)
print("Noise Normalization via fit = ", fit.noise_normalization)

"""
r"""
From the `chi_squared` and `noise_normalization`, we can define a final goodness-of-fit measure known as
the `log_likelihood`.

Expand All @@ -464,7 +464,7 @@
print("Log Likelihood = ", log_likelihood)
print("Log Likelihood via fit = ", fit.log_likelihood)

"""
r"""
In the previous discussion, we noted that a lower \(\chi^2\) value indicates a better fit of the model to the
observed data.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
r"""
Tutorial 1: Non-linear Search
=============================

Expand Down
16 changes: 8 additions & 8 deletions scripts/chapter_3_pixelizations/tutorial_5_bayesian_formalism.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

tracer = al.Tracer(galaxies=[lens_galaxy, source_galaxy])

"""
r"""
__Ray Tracing__

Every 2D (y,x) image-plane coordinate $\theta$ is ray-traced to its source-plane coordinate $\beta$ by subtracting
Expand Down Expand Up @@ -331,7 +331,7 @@
plt.show()
plt.close()

"""
r"""
__Data Vector (D)__

We now pose the reconstruction as a linear inversion, converting the blurred mapping matrix, data and noise-map
Expand Down Expand Up @@ -363,7 +363,7 @@
plt.show()
plt.close()

"""
r"""
__Curvature Matrix (F)__

The curvature matrix has dimensions `(total_source_pixels, total_source_pixels)` and is given by (WD03):
Expand All @@ -386,7 +386,7 @@
plt.show()
plt.close()

"""
r"""
__Unregularized Solve__

The inversion seeks the source-pixel fluxes $s$ (a vector with one entry per source pixel) that minimize the
Expand All @@ -410,7 +410,7 @@

print(reconstruction)

"""
r"""
The reconstructed source-pixel fluxes are a noisy, unsmooth mess -- exactly the over-fitting we saw in tutorial 4
when we set the regularization coefficient to zero. The linear inversion is fitting the noise in the data, because
this system of equations is ill-posed: we need a smoothness prior.
Expand Down Expand Up @@ -486,7 +486,7 @@

aplt.plot_array(array=mapped_reconstructed_data, title="Reconstructed Image")

"""
r"""
__Likelihood Function__

We now quantify the goodness-of-fit of the source reconstruction, computing the quantity tutorial 4 called the
Expand Down Expand Up @@ -521,7 +521,7 @@

print(chi_squared)

"""
r"""
__Regularization Term__

The second term, $s^{T} H s$, is the $\lambda \, G_{L}$ regularization penalty evaluated at the solution: the summed
Expand All @@ -536,7 +536,7 @@

print(regularization_term)

"""
r"""
__Complexity Terms__

Up to this point, nothing has justified our choice of `regularization_coefficient=1.0`. We cannot choose it using
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
r"""
Tutorial 3: Scaling Relations
=============================

Expand Down Expand Up @@ -541,7 +541,7 @@
f"Tied galaxy {i}: relation predicts = {einstein_radius_predicted:.3f}"
)

"""
r"""
The prediction lands within a few percent of the truth: this simulated pair happens to sit almost exactly on the
Faber-Jackson relation. That is why the tied fit succeeds. Real galaxies are not always so obliging.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
r"""
Tutorial 5: Cluster Scale
=========================

Expand Down
Loading