Skip to content

Commit

Permalink
Address PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Jul 15, 2024
1 parent 2b2230a commit bc4848a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/tdastro/astro_utils/cosmology.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def redshift_to_distance(redshift, cosmology, kind="comoving"):
"""Compute a source's distance given its redshift and a
"""Compute a source's luminosity distance given its redshift and a
specified cosmology using astropy's redshift_distance().
Parameters
Expand All @@ -21,7 +21,7 @@ def redshift_to_distance(redshift, cosmology, kind="comoving"):
Returns
-------
distance : `float`
The distance (in pc)
The luminosity distance (in pc)
"""
z = redshift * cu.redshift
distance = z.to(u.pc, cu.redshift_distance(cosmology, kind=kind))
Expand Down
6 changes: 3 additions & 3 deletions src/tdastro/sources/physical_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PhysicalModel(ParameterizedNode):
redshift : `float`
The object's redshift.
distance : `float`
The object's distance (in pc). If the distance is not provided and
The object's luminosity distance (in pc). If no value is provided and
a ``cosmology`` parameter is given, the model will try to derive from
the redshift and the cosmology.
background : `PhysicalModel`
Expand All @@ -40,8 +40,8 @@ def __init__(self, ra=None, dec=None, redshift=None, distance=None, background=N
self.add_parameter("dec", dec)
self.add_parameter("redshift", redshift)

# If the distance is provided, use that. Otherwise try the redshift value
# using the cosmology (if given). Finally, default to None.
# If the luminosity distance is provided, use that. Otherwise try the
# redshift value using the cosmology (if given). Finally, default to None.
if distance is not None:
self.add_parameter("distance", distance)
elif redshift is not None and kwargs.get("cosmology", None) is not None:
Expand Down
5 changes: 4 additions & 1 deletion tests/tdastro/astro_utils/test_cosmology.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from astropy.cosmology import WMAP9
from astropy.cosmology import WMAP9, Planck18
from tdastro.astro_utils.cosmology import redshift_to_distance


Expand All @@ -8,3 +8,6 @@ def test_redshift_to_distance():
# Use the example from:
# https://docs.astropy.org/en/stable/api/astropy.cosmology.units.redshift_distance.html
assert redshift_to_distance(1100, cosmology=WMAP9) == pytest.approx(14004.03157418 * 1e6)

# Try the Planck18 cosmology.
assert redshift_to_distance(1100, cosmology=Planck18) == pytest.approx(13886.327957 * 1e6)
9 changes: 4 additions & 5 deletions tests/tdastro/sources/test_physical_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from astropy.cosmology import WMAP9
from astropy.cosmology import Planck18
from tdastro.sources.physical_model import PhysicalModel


Expand All @@ -12,13 +12,12 @@ def test_physical_model():
assert model1.distance == 3.0
assert model1.redshift == 0.0

# Derive the distance from the redshift using the example from:
# https://docs.astropy.org/en/stable/api/astropy.cosmology.units.redshift_distance.html
model2 = PhysicalModel(ra=1.0, dec=2.0, redshift=1100.0, cosmology=WMAP9)
# Derive the distance from the redshift:
model2 = PhysicalModel(ra=1.0, dec=2.0, redshift=1100.0, cosmology=Planck18)
assert model2.ra == 1.0
assert model2.dec == 2.0
assert model2.redshift == 1100.0
assert model2.distance == pytest.approx(14004.03157418 * 1e6)
assert model2.distance == pytest.approx(13886.327957 * 1e6)

# Neither distance nor redshift are specified.
model3 = PhysicalModel(ra=1.0, dec=2.0)
Expand Down

0 comments on commit bc4848a

Please sign in to comment.