From 3a8568d699d861e549f74dd10704857a4105bad3 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 20 Aug 2026 21:23:37 +0000 Subject: [PATCH] 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". 20 literals across 4 files get the `r` prefix. Both sweeps now return zero. Verified, not assumed: - Runtime values: 13 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 generator swaps the delimiter either way, so the diff-empty gate passes exactly. 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. --- .../tutorial_1_grids_and_galaxies.py | 10 +++++----- .../chapter_1_introduction/tutorial_3_fitting.py | 14 +++++++------- .../tutorial_1_non_linear_search.py | 2 +- .../tutorial_5_bayesian_formalism.py | 14 +++++++------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py b/scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py index 5a81a3c..d53acb6 100644 --- a/scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py +++ b/scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py @@ -1,4 +1,4 @@ -""" +r""" HowToGalaxy: Introduction ========================= @@ -147,7 +147,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: @@ -179,7 +179,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}$ @@ -199,7 +199,7 @@ print("First Ten Elliptical Coordinates:") print(eta[:10]) -""" +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. @@ -226,7 +226,7 @@ print(ell_comps) -""" +r""" __Light Profiles__ Galaxies are collections of stars, gas, dust, and other astronomical objects that emit light. Astronomers study this diff --git a/scripts/chapter_1_introduction/tutorial_3_fitting.py b/scripts/chapter_1_introduction/tutorial_3_fitting.py index 61bd7b2..ebb1d26 100644 --- a/scripts/chapter_1_introduction/tutorial_3_fitting.py +++ b/scripts/chapter_1_introduction/tutorial_3_fitting.py @@ -297,7 +297,7 @@ aplt.plot_array(array=dataset.data, title="Data") aplt.plot_array(array=fit.model_data, title="Model Image") -""" +r""" The `residual_map` is the difference 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). @@ -317,7 +317,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 ascertain if a residual value is large or small because this depends on the amount of noise in that pixel. @@ -341,7 +341,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. @@ -364,7 +364,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`. @@ -397,7 +397,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 as the logarithm of the sum of squared noise values in our data: @@ -417,7 +417,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`. @@ -433,7 +433,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. diff --git a/scripts/chapter_2_modeling/tutorial_1_non_linear_search.py b/scripts/chapter_2_modeling/tutorial_1_non_linear_search.py index bb861c0..68c530b 100644 --- a/scripts/chapter_2_modeling/tutorial_1_non_linear_search.py +++ b/scripts/chapter_2_modeling/tutorial_1_non_linear_search.py @@ -1,4 +1,4 @@ -""" +r""" Tutorial 1: Non-linear Search ============================= diff --git a/scripts/chapter_3_pixelizations/tutorial_5_bayesian_formalism.py b/scripts/chapter_3_pixelizations/tutorial_5_bayesian_formalism.py index 005819c..3ad56f8 100644 --- a/scripts/chapter_3_pixelizations/tutorial_5_bayesian_formalism.py +++ b/scripts/chapter_3_pixelizations/tutorial_5_bayesian_formalism.py @@ -302,7 +302,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 @@ -335,7 +335,7 @@ plt.show() plt.close() -""" +r""" __Curvature Matrix (F)__ The curvature matrix has dimensions `(total_mesh_pixels, total_mesh_pixels)` and is given by (WD03): @@ -359,7 +359,7 @@ plt.show() plt.close() -""" +r""" __Unregularized Solve__ The inversion seeks the mesh-pixel fluxes $s$ (a vector with one entry per mesh pixel) that minimize the @@ -383,7 +383,7 @@ plot_mapper(mapper=mapper, solution_vector=reconstruction) -""" +r""" The reconstructed mesh-pixel fluxes are a noisy, unsmooth mess -- exactly the over-fitting we saw in tutorial 4 when we lowered the regularization coefficient towards zero. The linear inversion is fitting the noise in the data, because this system of equations is ill-posed: we need a smoothness prior. @@ -459,7 +459,7 @@ aplt.plot_array(array=mapped_reconstructed_data, title="Reconstructed Image") -""" +r""" __Likelihood Function__ We now quantify the goodness-of-fit of the galaxy reconstruction, computing the quantity tutorial 4 called the @@ -494,7 +494,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 @@ -509,7 +509,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