Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions autogalaxy/cosmology/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions test_autogalaxy/cosmology/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading