# Distance¶

class astropy.coordinates.distances.Distance(*args, **kwargs)[source] [edit on github]

Bases: object

A one-dimensional distance.

This can be initialized in one of three ways: a distance and a unit, a Quantity object, or a redshift and (optionally) a cosmology. value and unit may be provided as positional arguments, but z and cosmology are only valid as keyword arguments (see examples).

Parameters : value : scalar or Quantity The value of this distance unit : UnitBase The units for this distance. Must have dimensions of distance. z : float 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. cosmology : Cosmology 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). UnitsError : If the unit is not a distance.

Examples

```>>> from astropy import units as u
>>> from astropy.cosmology import WMAP3
>>> 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=WMAP3)
```

Attributes Summary

 Mpc The value of this distance in megaparsecs au The value of this distance in astronomical units km The value of this distance in kilometers kpc The value of this distance in kiloparsecs lightyear The value of this distance in light years m The value of this distance in meters pc The value of this distance in parsecs z The redshift for this distance assuming its physical distance is a luminosity distance.

Methods Summary

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

Attributes Documentation

Mpc[source]

The value of this distance in megaparsecs

au[source]

The value of this distance in astronomical units

km[source]

The value of this distance in kilometers

kpc[source]

The value of this distance in kiloparsecs

lightyear[source]

The value of this distance in light years

m[source]

The value of this distance in meters

pc[source]

The value of this distance in parsecs

z[source]

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

Note

This uses the “current” cosmology to determine the appropriate distance to redshift conversions. See astropy.cosmology for details on how to change this.

Methods Documentation

compute_z(cosmology=None)[source] [edit on github]

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

Parameters : cosmology : cosmology or None The cosmology to assume for this calculation, or None to use the current cosmology.