astropy:docs

Distance

class astropy.coordinates.distances.Distance[source] [edit on github]

Bases: astropy.units.quantity.Quantity

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:

value : scalar or Quantity

The value of this distance

unit : UnitBase

The units for this distance, if value is not a Quantity. 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. Must be given as a keyword argument.

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).

distmod : float or Quantity

The distance modulus for this distance.

dtype : ~numpy.dtype, optional

See Quantity. Must be given as a keyword argument.

copy : bool, optional

See Quantity. Must be given as a keyword argument.

Raises:

astropy.units.core.UnitsError :

If the unit is not a distance.

ValueError :

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 import cosmology
>>> from astropy.cosmology import WMAP5, WMAP7
>>> cosmology.set_current(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)

Attributes Summary

distmod The distance modulus of this distance as a Quantity
z Short for self.compute_z()

Methods Summary

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

Attributes Documentation

distmod[source]

The distance modulus of this distance as a Quantity

z[source]

Short for self.compute_z()

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.

Returns:

z : float

The redshift of this distance given the provided cosmology.

Page Contents