diff --git a/src/tdastro/astro_utils/cosmology.py b/src/tdastro/astro_utils/cosmology.py index b36022b1..57771220 100644 --- a/src/tdastro/astro_utils/cosmology.py +++ b/src/tdastro/astro_utils/cosmology.py @@ -4,7 +4,7 @@ from tdastro.base_models import FunctionNode -def redshift_to_distance(redshift, cosmology, kind="comoving"): +def redshift_to_distance(redshift, cosmology): """Compute a source's luminosity distance given its redshift and a specified cosmology using astropy's redshift_distance(). @@ -14,9 +14,6 @@ def redshift_to_distance(redshift, cosmology, kind="comoving"): The redshift value. cosmology : `astropy.cosmology` The cosmology specification. - kind : `str` - The distance type for the Equivalency as defined by - astropy.cosmology.units.redshift_distance. Returns ------- @@ -24,7 +21,7 @@ def redshift_to_distance(redshift, cosmology, kind="comoving"): The luminosity distance (in pc) """ z = redshift * cu.redshift - distance = z.to(u.pc, cu.redshift_distance(cosmology, kind=kind)) + distance = z.to(u.pc, cu.redshift_distance(cosmology, kind="luminosity")) return distance.value @@ -45,18 +42,14 @@ class RedshiftDistFunc(FunctionNode): The function or constant providing the redshift value. cosmology : `astropy.cosmology` The cosmology specification. - kind : `str` - The distance type for the Equivalency as defined by - astropy.cosmology.units.redshift_distance. """ - def __init__(self, redshift, cosmology, kind="comoving"): + def __init__(self, redshift, cosmology): # Call the super class's constructor with the needed information. super().__init__( func=redshift_to_distance, redshift=redshift, cosmology=cosmology, - kind=kind, ) def __str__(self): diff --git a/tests/tdastro/astro_utils/test_cosmology.py b/tests/tdastro/astro_utils/test_cosmology.py index fff88c47..9ed9559e 100644 --- a/tests/tdastro/astro_utils/test_cosmology.py +++ b/tests/tdastro/astro_utils/test_cosmology.py @@ -1,13 +1,12 @@ -import pytest from astropy.cosmology import WMAP9, Planck18 from tdastro.astro_utils.cosmology import redshift_to_distance def test_redshift_to_distance(): """Test that we can convert the redshift to a distance using a given cosmology.""" - # 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) + wmap9_val = redshift_to_distance(1100, cosmology=WMAP9) + planck18_val = redshift_to_distance(1100, cosmology=Planck18) - # Try the Planck18 cosmology. - assert redshift_to_distance(1100, cosmology=Planck18) == pytest.approx(13886.327957 * 1e6) + assert abs(planck18_val - wmap9_val) > 1000.0 + assert 13.0 * 1e12 < wmap9_val < 16.0 * 1e12 + assert 13.0 * 1e12 < planck18_val < 16.0 * 1e12 diff --git a/tests/tdastro/sources/test_physical_models.py b/tests/tdastro/sources/test_physical_models.py index d05560e3..8098cf1b 100644 --- a/tests/tdastro/sources/test_physical_models.py +++ b/tests/tdastro/sources/test_physical_models.py @@ -1,4 +1,3 @@ -import pytest from astropy.cosmology import Planck18 from tdastro.sources.physical_model import PhysicalModel @@ -17,7 +16,7 @@ def test_physical_model(): assert model2.ra == 1.0 assert model2.dec == 2.0 assert model2.redshift == 1100.0 - assert model2.distance == pytest.approx(13886.327957 * 1e6) + assert 13.0 * 1e12 < model2.distance < 16.0 * 1e12 # Neither distance nor redshift are specified. model3 = PhysicalModel(ra=1.0, dec=2.0)