Skip to content

Commit 9098e81

Browse files
committed
maintenance: raw-string the LaTeX-carrying docstrings
Non-raw docstrings containing LaTeX are corrupted by Python's escape handling. Two distinct failure classes, and only the first is visible: warned `\s`, `\l`, `\[` ... escapes Python does NOT recognise. It leaves them literal but emits SyntaxWarning on every compile/import, and they are slated to become a SyntaxError. silent `\t` in `\theta`, `\f` in `\frac`, `\r` in `\rm`, `\b` in `\beta`. Escapes Python DOES recognise: the value is corrupted with NO diagnostic at all. `\theta_E` was literally TAB + "heta_E". 32 literals across 8 files get the `r` prefix. Both sweeps now return zero. Verified, not assumed: - Runtime values: 21 corruptions repaired, 0 other changes. Every changed literal's value was compared HEAD vs worktree; the prefix may only ever REMOVE corruption, never alter a string otherwise. - Regenerated with autohands: notebooks/, markdown/, llms-full.txt and workspace_index.json are ALL byte-identical -- the diff-empty gate passes exactly. This repo carries the defect the original prompt was filed on: chapter_4 tutorial_3_scaling_relation.py had `\theta_E` stored as TAB + "heta_E". Confirmed repaired -- the docstring value now holds a real backslash and no TAB. chapter_4 tutorial_5_cluster_scale.py has ONLY silent hits and zero warnings, so a warning-only sweep would have skipped it entirely; it is included here. Prose is untouched -- only the delimiter gains an `r`. Deliberate escapes were left alone (real newlines in print(), already-escaped LaTeX line breaks): the prefix was applied only where every backslash sits in a LaTeX context.
1 parent dcb67e9 commit 9098e81

8 files changed

Lines changed: 32 additions & 32 deletions

File tree

scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
r"""
22
HowToLens: Introduction
33
=======================
44
@@ -171,7 +171,7 @@
171171
"""
172172
aplt.plot_grid(grid=grid_shifted, title="Grid Centered Around (0.3, 0.5)")
173173

174-
"""
174+
r"""
175175
Next, we can rotate the grid by an angle `phi` (in degrees). The rotation is counter-clockwise from the positive x-axis.
176176
177177
To rotate the grid:
@@ -203,7 +203,7 @@
203203
"""
204204
aplt.plot_grid(grid=grid_rotated, title="Grid Rotated 60 Degrees")
205205

206-
"""
206+
r"""
207207
Next, we convert the rotated grid to elliptical coordinates using:
208208
209209
$\eta = \sqrt{(x_r)^2 + (y_r)^2/q^2}$
@@ -220,7 +220,7 @@
220220
axis_ratio = 0.5
221221
eta = np.sqrt((grid_rotated[:, 0]) ** 2 + (grid_rotated[:, 1]) ** 2 / axis_ratio**2)
222222

223-
"""
223+
r"""
224224
Above, the angle $\phi$ (in degrees) was used to rotate the grid, and the axis-ratio $q$ was used to convert the grid
225225
to elliptical coordinates.
226226
@@ -247,7 +247,7 @@
247247
print(ell_comps)
248248

249249

250-
"""
250+
r"""
251251
__Light Profiles__
252252
253253
Galaxies are collections of stars, gas, dust, and other astronomical objects that emit light. Astronomers study this
@@ -426,7 +426,7 @@
426426
plt.close()
427427

428428

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

scripts/chapter_1_introduction/tutorial_2_ray_tracing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"""
125125
deflections = sis_mass_profile.deflections_yx_2d_from(grid=image_plane_grid)
126126

127-
"""
127+
r"""
128128
Like grids and arrays, the deflection angles can be accessed using the `native` and `slim` attributes. These are
129129
structured similarly to a `Grid2D` object:
130130
@@ -151,7 +151,7 @@
151151
"""
152152
print(type(deflections))
153153

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

232-
"""
232+
r"""
233233
__Ray Tracing Grids__
234234
235235
We now have all the tools we need to perform our first ray-tracing calculation.
@@ -367,7 +367,7 @@
367367
aplt.plot_grid(grid=image_plane_grid_traced, title="Image Plane Grid")
368368
aplt.plot_grid(grid=source_plane_grid_traced, title="Source Plane Grid")
369369

370-
"""
370+
r"""
371371
__Wrap Up__
372372
373373
In this tutorial, you performed your first lensing calculations. Let's summarise what we've learnt:

scripts/chapter_1_introduction/tutorial_4_point_sources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161

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

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

273-
"""
273+
r"""
274274
__Magnifications__
275275
276276
Lensing does not just relocate a point source's light — it magnifies it. Each multiple image has its own
@@ -340,7 +340,7 @@
340340
print("Time Delays relative to first image (days):")
341341
print(time_delays - time_delays[0])
342342

343-
"""
343+
r"""
344344
__Extended Versus Point Computations__
345345
346346
We can now state precisely why point-source lensing works so differently from everything in tutorials 2 and 3, on

scripts/chapter_1_introduction/tutorial_7_fitting.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@
328328
aplt.plot_array(array=fit.data, title="Data")
329329
aplt.plot_array(array=fit.model_data, title="Model Image")
330330

331-
"""
331+
r"""
332332
The `residual_map` is the different between the observed image and model image, showing where in the image the fit is
333333
good (e.g. low residuals) and where it is bad (e.g. high residuals).
334334
@@ -348,7 +348,7 @@
348348

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

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

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

375-
"""
375+
r"""
376376
Next, we define the `chi_squared_map`, which is obtained by squaring the `normalized_residual_map` and serves as a
377377
measure of goodness of fit.
378378
@@ -395,7 +395,7 @@
395395

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

398-
"""
398+
r"""
399399
Now, we consolidate all the information in our `chi_squared_map` into a single measure of goodness-of-fit
400400
called `chi_squared`.
401401
@@ -428,7 +428,7 @@
428428
reduced_chi_squared = chi_squared / dataset.mask.pixels_in_mask
429429
print("Reduced Chi-squared = ", reduced_chi_squared)
430430

431-
"""
431+
r"""
432432
Another quantity that contributes to our final assessment of the goodness-of-fit is the `noise_normalization`.
433433
434434
The `noise_normalization` is computed by summing, over every pixel, the logarithm of 2 pi times the squared noise value:
@@ -448,7 +448,7 @@
448448
print("Noise Normalization = ", noise_normalization)
449449
print("Noise Normalization via fit = ", fit.noise_normalization)
450450

451-
"""
451+
r"""
452452
From the `chi_squared` and `noise_normalization`, we can define a final goodness-of-fit measure known as
453453
the `log_likelihood`.
454454
@@ -464,7 +464,7 @@
464464
print("Log Likelihood = ", log_likelihood)
465465
print("Log Likelihood via fit = ", fit.log_likelihood)
466466

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

scripts/chapter_2_lens_modeling/tutorial_1_non_linear_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
r"""
22
Tutorial 1: Non-linear Search
33
=============================
44

scripts/chapter_3_pixelizations/tutorial_5_bayesian_formalism.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175

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

178-
"""
178+
r"""
179179
__Ray Tracing__
180180
181181
Every 2D (y,x) image-plane coordinate $\theta$ is ray-traced to its source-plane coordinate $\beta$ by subtracting
@@ -331,7 +331,7 @@
331331
plt.show()
332332
plt.close()
333333

334-
"""
334+
r"""
335335
__Data Vector (D)__
336336
337337
We now pose the reconstruction as a linear inversion, converting the blurred mapping matrix, data and noise-map
@@ -363,7 +363,7 @@
363363
plt.show()
364364
plt.close()
365365

366-
"""
366+
r"""
367367
__Curvature Matrix (F)__
368368
369369
The curvature matrix has dimensions `(total_source_pixels, total_source_pixels)` and is given by (WD03):
@@ -386,7 +386,7 @@
386386
plt.show()
387387
plt.close()
388388

389-
"""
389+
r"""
390390
__Unregularized Solve__
391391
392392
The inversion seeks the source-pixel fluxes $s$ (a vector with one entry per source pixel) that minimize the
@@ -410,7 +410,7 @@
410410

411411
print(reconstruction)
412412

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

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

489-
"""
489+
r"""
490490
__Likelihood Function__
491491
492492
We now quantify the goodness-of-fit of the source reconstruction, computing the quantity tutorial 4 called the
@@ -521,7 +521,7 @@
521521

522522
print(chi_squared)
523523

524-
"""
524+
r"""
525525
__Regularization Term__
526526
527527
The second term, $s^{T} H s$, is the $\lambda \, G_{L}$ regularization penalty evaluated at the solution: the summed
@@ -536,7 +536,7 @@
536536

537537
print(regularization_term)
538538

539-
"""
539+
r"""
540540
__Complexity Terms__
541541
542542
Up to this point, nothing has justified our choice of `regularization_coefficient=1.0`. We cannot choose it using

scripts/chapter_4_scaling_up_lensing/tutorial_3_scaling_relation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
r"""
22
Tutorial 3: Scaling Relations
33
=============================
44
@@ -541,7 +541,7 @@
541541
f"Tied galaxy {i}: relation predicts = {einstein_radius_predicted:.3f}"
542542
)
543543

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

scripts/chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
r"""
22
Tutorial 5: Cluster Scale
33
=========================
44

0 commit comments

Comments
 (0)