# [AstroPy] Redshift vs. Luminosity Distance

Craig, Matthew W mcraig at mnstate.edu
Tue Jul 23 10:31:02 EDT 2019

Hi Nic,

Thanks for posting the solution you got — it is useful to see both the question and answer, and awesome when users are able to provide the answer :)

Matt Craig

schedule:  http://physics.mnstate.edu/craig
——
Professor
Department of Physics and Astronomy
1104 7th Ave S, Moorhead MN 56563

office: Hagen 307F
phone: (218) 477-2439
fax: (218) 477-2290

On Jul 22, 2019, at 7:11 PM, Nicholas Ross <npross at roe.ac.uk<mailto:npross at roe.ac.uk>> wrote:

DLs_for_axis = np.array([0.01, 500., 1000., 2000., 3000., 5000., 6000.]) * u.Mpc
redshift_ticks = [z_at_value(cosmo.luminosity_distance, DLs) for DLs in DLs_for_axis]

seems to solve this one.

Thanks,
Nic

On Jul 22, 2019, at 4:54 PM, Nicholas Ross <npross at roe.ac.uk<mailto:npross at roe.ac.uk>> wrote:

Hi,

Been struggling with this one::

import astropy.units as u
from astropy.cosmology import FlatLambdaCDM
from astropy.cosmology import z_at_value

cosmo = FlatLambdaCDM(H0=67.7, Om0=0.307)
luminosity_distances = np.array([0.0, 500., 1000., 2000., 3000., 5000., 6000.]) * u.Mpc
z_at_value(cosmo.luminosity_distance, luminosity_distances)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-0294161797b4> in <module>()
5 cosmo = FlatLambdaCDM(H0=67.7, Om0=0.307)  #Banados thesis
6 luminosity_distances = np.array([0.0, 500., 1000., 2000., 3000., 5000., 6000.]) * u.Mpc
----> 7 z_at_value(cosmo.luminosity_distance, luminosity_distances)
~/anaconda3/lib/python3.6/site-packages/astropy/cosmology/funcs.py in z_at_value(func, fval, zmin, zmax, ztol, maxfun)
116     fval_zmin = func(zmin)
117     fval_zmax = func(zmax)
--> 118     if np.sign(fval - fval_zmin) != np.sign(fval_zmax - fval):
119         warnings.warn("""\
120 fval is not bracketed by func(zmin) and func(zmax). This means either…

Is this because astropy.cosmology returns the luminosity distance — which is monotonic with
redshift in a flat/open cosmology, as
dL = dA*(1+z)^2
where dA is the non-monotonic angular diameter distance??

Thanks,
Nic

_______________________________________________
AstroPy mailing list
AstroPy at python.org<mailto:AstroPy at python.org>