Skip to content

fix: add integral-based deflection calculations to mass_via_integral scripts #16

@Jammy2211

Description

@Jammy2211

Overview

PR PyAutoLabs/PyAutoGalaxy#324 removed all deflections_2d_via_integral_from methods from PyAutoGalaxy source code, intending to preserve them as standalone reference scripts in scripts/mass_via_integral/. However, only the low-level integrand functions (deflection_func) were copied — the actual scipy.integrate.quad calculation loops were not. The scripts currently call library methods (analytic/CSE/MGE) instead of performing the integral, which defeats their purpose.

This fix adds the integral computation wrappers to each script so they actually compute deflections via numerical integration and compare against the library methods.

Plan

  • Add deflections_2d_via_integral_from(mp, grid) wrapper function to each script, using the profile object's existing transform/utility methods (no reimplementation)
  • Update test configs to compute via integral and assert agreement with library methods
  • Add missing integrand functions to gnfw.py and gnfw_virial_mass_conc.py (these were never copied from the PR)
  • All integral code is copied verbatim from the removed PR #324 methods
Detailed implementation plan

Affected Repositories

  • autolens_workspace_test (primary)

Work Classification

Workspace

Branch Survey

Repository Current Branch Dirty?
./autolens_workspace_test main yes (unrelated dataset/viz changes)

Suggested branch: feature/deflections-integral-fix

Implementation Steps

  1. gaussian.py — add deflections_2d_via_integral_from using existing deflection_func, update 4 configs to compare integral vs deflections_2d_via_analytic_from
  2. sersic.py — add wrapper, update 2 configs to compare integral vs deflections_2d_via_cse_from
  3. sersic_gradient.py — add wrapper, update 2 configs to compare integral vs deflections_2d_via_cse_from
  4. nfw.py — add deflection + potential wrappers using existing nfw_deflection_func/nfw_potential_func, update 4 configs
  5. gnfw.py — add all missing integral functions (tabulate_integral, surface_density_integrand, gnfw_deflection_func, gnfw_potential_func, deflection_integrand, deflection_func_sph), add wrappers for elliptical and spherical cases, update all configs
  6. gnfw_virial_mass_conc.py — add spherical integral functions and wrapper, update config

Key Files

  • scripts/mass_via_integral/gaussian.py
  • scripts/mass_via_integral/sersic.py
  • scripts/mass_via_integral/sersic_gradient.py
  • scripts/mass_via_integral/nfw.py
  • scripts/mass_via_integral/gnfw.py
  • scripts/mass_via_integral/gnfw_virial_mass_conc.py

Original Prompt

Click to expand starting prompt

The followng PR Was meant to move all deflections_via_integral methods out of the source code
and into the @autolens_workspace_test/scripts/mass_via_integral folder:

PyAutoLabs/PyAutoGalaxy#324

The expectation is it would move the functions themselves, including the full calculation, into this folder
so the tests there could use it.

However, it did not move the functions and their calculations themselves from the source code, meaning these tests did not
pass. Can you dig up the PR, look at its history, get the alculations and move them to this test package?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions