astropy.cosmology.units.with_redshift(cosmology=None, *, distance='comoving', hubble=True, Tcmb=True, atzkw=None)[source]

Convert quantities between measures of cosmological distance.

Note: by default all equivalencies are on and must be explicitly turned off. Care should be taken to not misinterpret a relativistic, gravitational, etc redshift as a cosmological one.

cosmologyCosmology, str, or None, optional

A cosmology realization or built-in cosmology’s name (e.g. ‘Planck18’). If None, will use the default cosmology (controlled by default_cosmology).

distance{‘comoving’, ‘lookback’, ‘luminosity’} or None (optional, keyword-only)

The type of distance equivalency to create or None. Default is ‘comoving’.

hubblebool (optional, keyword-only)

Whether to create a Hubble parameter <-> redshift equivalency, using Cosmology.H. Default is True.

Tcmbbool (optional, keyword-only)

Whether to create a CMB temperature <-> redshift equivalency, using Cosmology.Tcmb. Default is True.

atzkwdict or None (optional, keyword-only)

keyword arguments for z_at_value()


With equivalencies between redshift and distance / Hubble / temperature.


>>> import astropy.units as u
>>> import astropy.cosmology.units as cu
>>> from astropy.cosmology import WMAP9
>>> equivalency = cu.with_redshift(WMAP9)
>>> z = 1100 * cu.redshift

Redshift to (comoving) distance:

>>> z.to(u.Mpc, equivalency)  
<Quantity 14004.03157418 Mpc>

Redshift to the Hubble parameter:

>>> z.to(u.km / u.s / u.Mpc, equivalency)  
<Quantity 1565637.40154275 km / (Mpc s)>
>>> z.to(cu.littleh, equivalency)  
<Quantity 15656.37401543 littleh>

Redshift to CMB temperature:

>>> z.to(u.K, equivalency)
<Quantity 3000.225 K>