ó
šßÈ[c           @` sz   d  Z  d d l m Z m Z m Z m Z d d l Z d d l m	 Z
 d g Z i d g d 6Z d	 e
 j f d
 „  ƒ  YZ d S(   u`   
This module contains the classes and utility functions for distance and
cartesian coordinates.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   unitsu   Distanceu   scipy.integrateu   *t   Distancec           B` s€   e  Z d  Z e j Z e Z d d d d d d e d e	 d e	 d „ Z
 e d „  ƒ Z d d „ Z e d „  ƒ Z e d „  ƒ Z RS(   uÞ	  
    A one-dimensional distance.

    This can be initialized in one of four ways:

    * A distance ``value`` (array or float) and a ``unit``
    * A `~astropy.units.Quantity` object
    * A redshift and (optionally) a cosmology.
    * Providing a distance modulus

    Parameters
    ----------
    value : scalar or `~astropy.units.Quantity`.
        The value of this distance.
    unit : `~astropy.units.UnitBase`
        The units for this distance, *if* ``value`` is not a
        `~astropy.units.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 `~astropy.units.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.
    dtype : `~numpy.dtype`, optional
        See `~astropy.units.Quantity`.
    copy : bool, optional
        See `~astropy.units.Quantity`.
    order : {'C', 'F', 'A'}, optional
        See `~astropy.units.Quantity`.
    subok : bool, optional
        See `~astropy.units.Quantity`.
    ndmin : int, optional
        See `~astropy.units.Quantity`.
    allow_negative : bool, optional
        Whether to allow negative distances (which are possible is some
        cosmologies).  Default: ``False``.

    Raises
    ------
    `~astropy.units.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 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)
    >>> d7 = Distance(Distance(10 * u.Mpc))
    i    c         C` sÑ  | d  k	 rv | d  k	 s$ | d  k	 r3 t d ƒ ‚ n  | d  k r^ d d l m } | j ƒ  } n  | j | ƒ } t } ní | d  k	 r‘ t d ƒ ‚ n  | d  k	 rH| d  k	 r¸ t d ƒ ‚ n  |  j | ƒ } | d  k r?t j	 | j
 ƒ j ƒ  } | d k rt j } q?| d k rt j } q?| d k  r3t j } q?t j } n  t } n | d  k rct d ƒ ‚ n  t t |  ƒ j |  | | d	 | d
 | d | d |	 d |
 ƒ} | rÍt j | j
 d k  ƒ rÍt d ƒ ‚ n  | S(   NuK   Should given only one of `value`, `z` or `distmod` in Distance constructor.i   (   t   default_cosmologyuH   A `cosmology` was given but `z` was not provided in Distance constructori   i   iýÿÿÿuE   None of `value`, `z`, or `distmod` were given to Distance constructort   dtypet   copyt   ordert   subokt   ndmini    uX   Distance must be >= 0.  Use the argument 'allow_negative=True' to allow negative values.(   t   Nonet
   ValueErrort	   cosmologyR   t   gett   luminosity_distancet   Falset   _distmod_to_pct   npt   log10t   valuet   meant   ut   Mpct   kpct   AUt   pct   superR   t   __new__t   any(   t   clsR   t   unitt   zR   t   distmodR   R   R	   R
   R   t   allow_negativeR   t
   meanlogvalt   distance(    (    s<   lib/python2.7/site-packages/astropy/coordinates/distances.pyR   ]   s@    		c         C` s
   |  j  ƒ  S(   u   Short for ``self.compute_z()``(   t	   compute_z(   t   self(    (    s<   lib/python2.7/site-packages/astropy/coordinates/distances.pyR!   š   s    c         C` sQ   | d k r+ d d l m } | j ƒ  } n  d d l m } | | j |  d d ƒS(   u×  
        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 (see `astropy.cosmology` for details).

        Returns
        -------
        z : float
            The redshift of this distance given the provided ``cosmology``.
        i   (   R   (   t
   z_at_valuet   ztolg»½×Ùß|Û=N(   R   R   R   R   R(   R   (   R'   R   R   R(   (    (    s<   lib/python2.7/site-packages/astropy/coordinates/distances.pyR&   Ÿ   s
    c         C` s<   d t  j |  j t j ƒ ƒ d } t j | t j d t ƒS(   u3   The distance modulus as a `~astropy.units.Quantity`g      @R   (   R   R   t   to_valueR   R   t   Quantityt   magR   (   R'   t   val(    (    s<   lib/python2.7/site-packages/astropy/coordinates/distances.pyR"   ·   s    #c         C` s:   t  j | t  j ƒ } |  d | j d d t  j d t ƒS(   Ni
   i   g      @R   (   R   R+   R,   R   R   R   (   R   t   dm(    (    s<   lib/python2.7/site-packages/astropy/coordinates/distances.pyR   ½   s    N(   t   __name__t
   __module__t   __doc__R   t   mt   _equivalent_unitt   Truet    _include_easy_conversion_membersR   R   R   t   propertyR!   R&   R"   t   classmethodR   (    (    (    s<   lib/python2.7/site-packages/astropy/coordinates/distances.pyR      s   D	;(   R1   t
   __future__R    R   R   R   t   numpyR   t    R   R   t   __all__t   __doctest_requires__t   SpecificTypeQuantityR   (    (    (    s<   lib/python2.7/site-packages/astropy/coordinates/distances.pyt   <module>   s   "	