# Distance¶

class astropy.coordinates.Distance[source]

A one-dimensional distance.

This can be initialized in one of four ways:

• A distance value (array or float) and a unit

• A Quantity object

• A redshift and (optionally) a cosmology.

• Providing a distance modulus

Parameters
valuescalar or Quantity.

The value of this distance.

unitUnitBase

The units for this distance, if value is not a Quantity. Must have dimensions of distance.

zfloat

A redshift for this distance. It will be converted to a distance by computing the luminosity distance for this redshift given the cosmology specified by cosmology. Must be given as a keyword argument.

cosmologyCosmology or None

A cosmology that will be used to compute the distance from z. If None, the current cosmology will be used (see astropy.cosmology for details).

distmodfloat or Quantity

The distance modulus for this distance. Note that if unit is not provided, a guess will be made at the unit between AU, pc, kpc, and Mpc.

parallax

The parallax in angular units.

dtypedtype, optional
copybool, optional
order{‘C’, ‘F’, ‘A’}, optional
subokbool, optional
ndminint, optional
allow_negativebool, optional

Whether to allow negative distances (which are possible is some cosmologies). Default: False.

Raises
UnitsError

If the unit is not a distance.

ValueError

If value specified is less than 0 and allow_negative=False.

If z is provided with a unit or cosmology is provided when z is not given, or value is given as well as z.

Examples

>>> from astropy import units as u
>>> from astropy.cosmology import WMAP5, WMAP7
>>> d1 = Distance(10, u.Mpc)
>>> d2 = Distance(40, unit=u.au)
>>> d3 = Distance(value=5, unit=u.kpc)
>>> d4 = Distance(z=0.23)
>>> d5 = Distance(z=0.23, cosmology=WMAP5)
>>> d6 = Distance(distmod=24.47)
>>> d7 = Distance(Distance(10 * u.Mpc))
>>> d8 = Distance(parallax=21.34*u.mas)


Attributes Summary

 distmod The distance modulus as a Quantity parallax The parallax angle as an Angle object z Short for self.compute_z()

Methods Summary

 compute_z(self[, cosmology]) The redshift for this distance assuming its physical distance is a luminosity distance.

Attributes Documentation

distmod

The distance modulus as a Quantity

parallax

The parallax angle as an Angle object

z

Short for self.compute_z()

Methods Documentation

compute_z(self, cosmology=None)[source]

The redshift for this distance assuming its physical distance is a luminosity distance.

Parameters
cosmologyCosmology or None

The cosmology to assume for this calculation, or None to use the current cosmology (see astropy.cosmology for details).

Returns
zfloat

The redshift of this distance given the provided cosmology.