diff --git a/autogalaxy/cosmology/model.py b/autogalaxy/cosmology/model.py index 419c8eb5c..6c28bacb9 100644 --- a/autogalaxy/cosmology/model.py +++ b/autogalaxy/cosmology/model.py @@ -62,6 +62,27 @@ def kpc_per_arcsec_from(self, redshift: float, xp=np) -> float: """ return self.kpc_proper_per_arcsec(z=redshift, xp=xp) + def luminosity_distance(self, z: float, xp=np) -> float: + """ + Luminosity distance to redshift z in Mpc. + + For a flat universe: + + D_L(z) = (1 + z)^2 * D_A(0, z) + + where D_A(0, z) is the angular diameter distance from Earth. + + Returns Mpc, matching the convention of astropy.cosmology.FlatLambdaCDM.luminosity_distance(z).value. + + Parameters + ---------- + z + Redshift at which the luminosity distance is calculated. + """ + D_A_kpc = self.angular_diameter_distance_to_earth_in_kpc_from(redshift=z, xp=xp) + D_A_Mpc = D_A_kpc / xp.asarray(1.0e3) + return (xp.asarray(1.0) + xp.asarray(z)) ** 2 * D_A_Mpc + def angular_diameter_distance_to_earth_in_kpc_from( self, redshift: float, xp=np ) -> float: diff --git a/test_autogalaxy/cosmology/test_model.py b/test_autogalaxy/cosmology/test_model.py index 2ced0faf6..8d981bba3 100644 --- a/test_autogalaxy/cosmology/test_model.py +++ b/test_autogalaxy/cosmology/test_model.py @@ -115,6 +115,17 @@ def test__scaling_factor_between_redshifts_from(): assert scaling_factor == pytest.approx(0.6739452581456, 1e-4) +def test__luminosity_distance(): + + cosmology = ag.cosmology.Planck15() + + # D_A(0, 0.1) = 392840 kpc = 392.840 Mpc (verified by test__angular_diameter_distances) + # D_L(0.1) = (1 + 0.1)^2 * 392.840 = 1.21 * 392.840 = 475.3364 Mpc + luminosity_distance = cosmology.luminosity_distance(z=0.1) + + assert luminosity_distance == pytest.approx(475.336, 1e-4) + + def test__velocity_dispersion_from(): cosmology = ag.cosmology.Planck15()