Skip to content

Add luminosity_distance to LensingCosmology#289

Merged
Jammy2211 merged 1 commit intomainfrom
feature/luminosity_distance
Mar 5, 2026
Merged

Add luminosity_distance to LensingCosmology#289
Jammy2211 merged 1 commit intomainfrom
feature/luminosity_distance

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

  • Adds luminosity_distance(z, xp=np) to LensingCosmology in autogalaxy/cosmology/model.py
  • Formula: D_L(z) = (1 + z)^2 * D_A(0, z), returns Mpc matching astropy's convention
  • Fixes AttributeError: 'FlatLambdaCDM' object has no attribute 'luminosity_distance' raised by workspace scripts (e.g. autolens_workspace/scripts/guides/units/mass_to_light_ratio_units.py)

Test plan

  • test_autogalaxy/cosmology/test_model.py::test__luminosity_distance — verifies value against known D_A for Planck15 at z=0.1
  • All 9 cosmology tests pass

Note: the calling script also used .value (an astropy Quantity attribute) on the return value — that fix lives in autolens_workspace and is handled separately.

🤖 Generated with Claude Code

Implements D_L(z) = (1+z)^2 * D_A(0,z) returning Mpc, matching
astropy's convention. Fixes AttributeError in workspace scripts
that call cosmo.luminosity_distance().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a luminosity_distance(z, xp=np) helper to LensingCosmology to provide an astropy-compatible luminosity distance (returned as a unitless float in Mpc) for the project’s custom JAX/NumPy cosmology implementation, addressing downstream workspace scripts that expect this API.

Changes:

  • Implement LensingCosmology.luminosity_distance(z, xp=np) using (D_L(z) = (1+z)^2 D_A(0,z)), converting kpc → Mpc.
  • Add a regression test validating luminosity_distance for Planck15 at z=0.1.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
autogalaxy/cosmology/model.py Adds luminosity_distance method returning Mpc using the existing angular-diameter distance implementation and xp backend.
test_autogalaxy/cosmology/test_model.py Adds a unit test to validate the new luminosity distance value for Planck15 at low redshift.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Jammy2211 Jammy2211 merged commit 0d528a1 into main Mar 5, 2026
12 checks passed
@Jammy2211 Jammy2211 deleted the feature/luminosity_distance branch April 2, 2026 11:43
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.

2 participants