From bc4848a54696bd4d243e4486b464106fb6f7d069 Mon Sep 17 00:00:00 2001 From: Jeremy Kubica <104161096+jeremykubica@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:43:08 -0400 Subject: [PATCH] Address PR comments. --- src/tdastro/astro_utils/cosmology.py | 4 ++-- src/tdastro/sources/physical_model.py | 6 +++--- tests/tdastro/astro_utils/test_cosmology.py | 5 ++++- tests/tdastro/sources/test_physical_models.py | 9 ++++----- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/tdastro/astro_utils/cosmology.py b/src/tdastro/astro_utils/cosmology.py index 1beecf70..b36022b1 100644 --- a/src/tdastro/astro_utils/cosmology.py +++ b/src/tdastro/astro_utils/cosmology.py @@ -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 @@ -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)) diff --git a/src/tdastro/sources/physical_model.py b/src/tdastro/sources/physical_model.py index c463bb70..fb4cb3de 100644 --- a/src/tdastro/sources/physical_model.py +++ b/src/tdastro/sources/physical_model.py @@ -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` @@ -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: diff --git a/tests/tdastro/astro_utils/test_cosmology.py b/tests/tdastro/astro_utils/test_cosmology.py index 14a500e2..fff88c47 100644 --- a/tests/tdastro/astro_utils/test_cosmology.py +++ b/tests/tdastro/astro_utils/test_cosmology.py @@ -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 @@ -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) diff --git a/tests/tdastro/sources/test_physical_models.py b/tests/tdastro/sources/test_physical_models.py index cd91e3e3..d05560e3 100644 --- a/tests/tdastro/sources/test_physical_models.py +++ b/tests/tdastro/sources/test_physical_models.py @@ -1,5 +1,5 @@ import pytest -from astropy.cosmology import WMAP9 +from astropy.cosmology import Planck18 from tdastro.sources.physical_model import PhysicalModel @@ -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)