Skip to content

fix: cNFWSph deflection boundary bug and MCR validation (#451)#454

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/cnfw-boundary-fix
May 27, 2026
Merged

fix: cNFWSph deflection boundary bug and MCR validation (#451)#454
Jammy2211 merged 1 commit into
mainfrom
feature/cnfw-boundary-fix

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

Fixes two bugs in the cored NFW profile reported in #451:

  1. F_func boundary condition: cNFWSph.F_func used strict </> masks, so theta == scale_radius fell through both branches and returned zero — producing wildly wrong deflections at that exact radius. Changed to <=.

  2. Peñarrubia MCR integral crosses zero for large f_c: The MCR integral factor becomes non-positive at f_c > ~0.18 (typical concentrations), causing kappa_s to diverge and go negative. Added a runtime warning and clamp to prevent NaN/Inf propagation.

The third problem from #451 (convergence returning zeros) was already fixed in #449.

API Changes

None — internal bug fix. The warning for invalid f_c is new user-visible behaviour.

Test Plan

  • `pytest test_autogalaxy/profiles/mass/` — 406 passed, 0 failed
  • F_func boundary: cNFWSph at theta = r_s now matches MGE to 0.01% (was 320% error)
  • MCR validation: f_c=0.3 and f_c=0.5 trigger warning and clamp (were silently negative)
  • f_c to 0 convergence to NFW still works correctly

🤖 Generated with Claude Code

Fix F_func boundary condition: theta == scale_radius fell through both
branches (strict < and >) leaving F=0, producing wildly wrong deflections
at that exact radius (e.g. -0.708 instead of +0.319). Changed to <=.

Add runtime warning + clamp when Penarrubia 2012 MCR integral factor
is non-positive (f_c > ~0.18 for typical concentrations), which caused
kappa_s to diverge/go negative and deflections to flip sign.

Fixes #451.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label May 27, 2026
@Jammy2211 Jammy2211 merged commit 23a1370 into main May 27, 2026
6 checks passed
@Jammy2211 Jammy2211 deleted the feature/cnfw-boundary-fix branch May 27, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release PR queued for the next release build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant