with_redshift#
- astropy.cosmology.units.with_redshift(cosmology: Cosmology | str | None = None, *, distance: Literal['comoving', 'lookback', 'luminosity'] = 'comoving', hubble: bool = True, Tcmb: bool = True, atzkw: Mapping[str, Any] | None = None) Equivalency [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.
- Parameters:
- cosmology
Cosmology
,python:str
, orpython:None
, optional A cosmology realization or built-in cosmology’s name (e.g. ‘Planck18’). If
None
, will use the default cosmology (controlled bydefault_cosmology
).- distance{‘comoving’, ‘lookback’, ‘luminosity’} or
python: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 isTrue
.- Tcmbbool (optional, keyword-only)
Whether to create a CMB temperature <-> redshift equivalency, using
Cosmology.Tcmb
. Default isTrue
.- atzkw
python:dict
orpython:None
(optional, keyword-only) keyword arguments for
z_at_value()
- cosmology
- Returns:
Equivalency
With equivalencies between redshift and distance / Hubble / temperature.
Examples
>>> 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>