Skip to content

fix(mass_stellar_dark): drop assertions, rename alpha→deflections#192

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/nfw-sph-deflection-origin-fix
May 20, 2026
Merged

fix(mass_stellar_dark): drop assertions, rename alpha→deflections#192
Jammy2211 merged 1 commit into
mainfrom
feature/nfw-sph-deflection-origin-fix

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

  • The two tutorial scripts in scripts/imaging/features/advanced/mass_stellar_dark/ (fit.py, likelihood_function.py) carried assert np.allclose(...) lines comparing a manual stellar + dark + shear deflection sum against the Tracer/Galaxy total. Asserts belong in a _test workspace, not in tutorial scripts — removed.
  • Renamed local alpha_* variables to deflections_* so the tutorial code mirrors the library's deflections_yx_2d_from API. Math-prose α(θ) notation in the docstrings is intentionally left as-is (lensing-literature convention).

Why now

The asserts were also failing on main because of a NaN at the origin pixel inside NFWSph.deflections_2d_via_analytic_from. The library fix lives in PyAutoLabs/PyAutoGalaxy#430 on the same branch name (feature/nfw-sph-deflection-origin-fix). This PR should land after PyAutoGalaxy#430.

Scripts Changed

  • scripts/imaging/features/advanced/mass_stellar_dark/fit.py — 5 alpha_*deflections_*, 5 prints updated, 1 assert removed.
  • scripts/imaging/features/advanced/mass_stellar_dark/likelihood_function.py — 4 alpha_*deflections_*, 4 prints updated, 1 assert removed.

Test plan

  • python scripts/imaging/features/advanced/mass_stellar_dark/fit.py runs end-to-end (no warnings, no AssertionError). Stellar+dark+shear summed deflection matches lens.deflections_yx_2d_from(grid) to machine precision.
  • python scripts/imaging/features/advanced/mass_stellar_dark/likelihood_function.py runs end-to-end. Manual source-plane grid matches tracer.traced_grid_2d_list_from(grid)[1] to machine precision.

🤖 Generated with Claude Code

The two `mass_stellar_dark/` scripts (`fit.py`, `likelihood_function.py`)
carried `assert np.allclose(...)` lines comparing a manual stellar +
dark + shear deflection sum against the `Tracer`/`Galaxy` total. These
asserts belong in a `_test` workspace, not in tutorial scripts.

Underlying NaN at r=0 in `NFWSph` is fixed in PyAutoGalaxy on the same
branch; this commit removes the asserts and renames the local
`alpha_*` variables to `deflections_*` so the tutorial code mirrors
the library's `deflections_yx_2d_from` API. Math-prose `α(θ)` notation
in the docstrings is intentionally left as-is (lensing literature
convention).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit cb888c5 into main May 20, 2026
6 checks passed
@Jammy2211 Jammy2211 deleted the feature/nfw-sph-deflection-origin-fix branch May 20, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant