Feature/psuedo isothermal test#246
Merged
Jammy2211 merged 13 commits intoPyAutoLabs:mainfrom Oct 15, 2025
Merged
Conversation
…erical problem(eg. divided by zero)
Jammy2211
approved these changes
Oct 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is based on the C-language source code of Lenstool (
lenstool/src/e_grad.c,lenstool/src/e_grad2.c,lenstool/src/e_gcpx.c,lenstool/src/e_g2cpx.c). The PIEMD (case (8)) and dPIEMD (case (81)) profiles have been faithfully translated into Python and integrated into PyAutoGalaxy, with details as follows:PIEMD and dPIEMD adopt the full elliptical expressions as in Lenstool, following Kassiola & Kovner (1993), and make use of the complex variable$I^*$ defined in their Equation 2.3.8. Under this formulation, ellipticity is introduced in the mass distribution rather than the potential. While the latter is mathematically convenient, it can result in unphysical "peanut-shaped" two-dimensional mass distributions at high ellipticity. The profiles implemented in this submission avoid such issues.
All computations are fully analytic, without reliance on special functions or numerical integration, ensuring computational efficiency.
Each step of the derivation has been worked out in detail on paper, and key results and computational steps are annotated in the corresponding sections of the code to ensure readability. The original complex arithmetic has been appropriately simplified using NumPy.
Most of the variable names and function names from Lenstool have been retained for easy cross-reference and comparison.
To distinguish from the existing dPIE in PyAutoLens, in new version it's renamed as dPIEP, indicating its use of pseudo-ellipticity in the potential rather than in the mass density. For consistency, the original lens strength parameter
kappa_scalehas been replaced byb0(see in-code comments for justification). Under this reparameterization, a long-standing numerical issue in the original profile for vanishing core radii (ra = 0) has also been resolved.I have thoroughly tested these profiles, and the following validations have been completed:
When the ellipticity is set to zero, dPIEMD yields identical deflection angles, kappa maps, and lensed images as dPIEP. As ellipticity increases, the differences become more apparent: dPIEP shows a peanut-shaped kappa map, while dPIEMD retains an elliptical shape (
convergence_2d_via_jacobian_from()).In the limiting case of$r_a = 0, r_s = 10^8$ , dPIEMD degenerates to SIE, and shows nearly identical behavior to
al.mp.Isothermalin terms of deflection angles, kappa maps, lensed images, and magnification maps.In the limiting case of$r_s = 10^8$ , dPIEMD degenerates to PIEMD, with consistent results across all diagnostics.
dPIEMDSph adopts a simplified and more efficient computational form (see code comments), and matches the behavior of SIS in comparative tests.
Remaining Issue:
The Hessians of PIEMD, dPIEMD, and dPIEMDSph are also analytically computed in Lenstool. In this update, I implemented these calculations via a function called
analytical_hessian_2d_from(). However, this function has not replaced the defaulthessian_frommethod, as I am currently uncertain which implementation is preferable — there are some subtle differences between them.