ó
ßČ[c           @` s(  d  Z  d d l m Z m Z m Z m Z d d l Z d d l m	 Z
 d d l m Z d d l m Z d d l m Z d d	 l m Z m Z d
 d l m Z d
 d l m Z m Z d
 d l m Z m Z d
 d l m Z d d d d d g Z d   Z d   Z  d   Z! d   Z" i  Z# e$ d d  Z% d S(   uń   
This module contains convenience functions for coordinate-related functionality.

This is generally just wrapping around the object-oriented coordinates
framework, but it is useful for some users who are used to more functional
interfaces.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   units(   t   c(   t   _erfa(   t   ascii(   t
   isiterablet   datai   (   t   SkyCoord(   t   GCRSt   PrecessedGeocentric(   t   SphericalRepresentationt   CartesianRepresentation(   t   get_jd12u   cartesian_to_sphericalu   spherical_to_cartesianu   get_sunu   concatenateu   get_constellationc         C` s   t  |  d  s |  t j }  n  t  | d  s> | t j } n  t  | d  s] | t j } n  t |  | |  } | j t  } | j | j | j f S(   uĺ  
    Converts 3D rectangular cartesian coordinates to spherical polar
    coordinates.

    Note that the resulting angles are latitude/longitude or
    elevation/azimuthal form.  I.e., the origin is along the equator
    rather than at the north pole.

    .. note::
        This function simply wraps functionality provided by the
        `~astropy.coordinates.CartesianRepresentation` and
        `~astropy.coordinates.SphericalRepresentation` classes.  In general,
        for both performance and readability, we suggest using these classes
        directly.  But for situations where a quick one-off conversion makes
        sense, this function is provided.

    Parameters
    ----------
    x : scalar, array-like, or `~astropy.units.Quantity`
        The first cartesian coordinate.
    y : scalar, array-like, or `~astropy.units.Quantity`
        The second cartesian coordinate.
    z : scalar, array-like, or `~astropy.units.Quantity`
        The third cartesian coordinate.

    Returns
    -------
    r : `~astropy.units.Quantity`
        The radial coordinate (in the same units as the inputs).
    lat : `~astropy.units.Quantity`
        The latitude in radians
    lon : `~astropy.units.Quantity`
        The longitude in radians
    u   unit(	   t   hasattrt   ut   dimensionless_unscaledR   t   represent_asR   t   distancet   latt   lon(   t   xt   yt   zt   cartt   sph(    (    s8   lib/python2.7/site-packages/astropy/coordinates/funcs.pyt   cartesian_to_spherical   s    #c         C` s   t  |  d  s |  t j }  n  t  | d  s> | t j } n  t  | d  s] | t j } n  t d |  d | d |  } | j t  } | j | j | j	 f S(   uV  
    Converts spherical polar coordinates to rectangular cartesian
    coordinates.

    Note that the input angles should be in latitude/longitude or
    elevation/azimuthal form.  I.e., the origin is along the equator
    rather than at the north pole.

    .. note::
        This is a low-level function used internally in
        `astropy.coordinates`.  It is provided for users if they really
        want to use it, but it is recommended that you use the
        `astropy.coordinates` coordinate systems.

    Parameters
    ----------
    r : scalar, array-like, or `~astropy.units.Quantity`
        The radial coordinate (in the same units as the inputs).
    lat : scalar, array-like, or `~astropy.units.Quantity`
        The latitude (in radians if array or scalar)
    lon : scalar, array-like, or `~astropy.units.Quantity`
        The longitude (in radians if array or scalar)

    Returns
    -------
    x : float or array
        The first cartesian coordinate.
    y : float or array
        The second cartesian coordinate.
    z : float or array
        The third cartesian coordinate.


    u   unitR   R   R   (
   R   R   R   t   radianR   R   R   R   R   R   (   t   rR   R   R   R   (    (    s8   lib/python2.7/site-packages/astropy/coordinates/funcs.pyt   spherical_to_cartesianN   s    #c   	   
   C` sA  t  j t |  d    \ } } | d d d d  f } | d d d d  f } | t j t j t j  } t j	 t j
 | d d d  } d t j
 | d d d d	 } t  j | | j | j d  | | |  } t d
 | | d t j d | | d t j d | | d t j  } t | d t d |   S(   u7  
    Determines the location of the sun at a given time (or times, if the input
    is an array `~astropy.time.Time` object), in geocentric coordinates.

    Parameters
    ----------
    time : `~astropy.time.Time`
        The time(s) at which to compute the location of the sun.

    Returns
    -------
    newsc : `~astropy.coordinates.SkyCoord`
        The location of the sun as a `~astropy.coordinates.SkyCoord` in the
        `~astropy.coordinates.GCRS` frame.


    Notes
    -----
    The algorithm for determining the sun/earth relative position is based
    on the simplified version of VSOP2000 that is part of ERFA. Compared to
    JPL's ephemeris, it should be good to about 4 km (in the Sun-Earth
    vector) from 1900-2100 C.E., 8 km for the 1800-2200 span, and perhaps
    250 km over the 1000-3000.

    u   tdb.i    Ni   i   t   axisi˙˙˙˙g      ŕ?R   R   R   t   framet   obstime(   i   (   .i    (   .i   (   .i   (   t   erfat   epv00R   R   t   to_valueR   t   aut   dt   npt   sqrtt   sumt   abt   reshapet   shapeR   t   AUR
   R   (	   t   timet   earth_pv_heliot   earth_pv_baryt   earth_pt   earth_vt   dsunt
   invlorentzt	   properdirt   cartrep(    (    s8   lib/python2.7/site-packages/astropy/coordinates/funcs.pyt   get_sun~   s    "!c         C` s8   t  |  d t  s t |   r. t d   n  t |   S(   u~  
    Combine multiple coordinate objects into a single
    `~astropy.coordinates.SkyCoord`.

    "Coordinate objects" here mean frame objects with data,
    `~astropy.coordinates.SkyCoord`, or representation objects.  Currently,
    they must all be in the same frame, but in a future version this may be
    relaxed to allow inhomogenous sequences of objects.

    Parameters
    ----------
    coords : sequence of coordinate objects
        The objects to concatenate

    Returns
    -------
    cskycoord : SkyCoord
        A single sky coordinate with its data set to the concatenation of all
        the elements in ``coords``
    u   isscalaru,   The argument to concatenate must be iterable(   t   getattrt   FalseR   t	   TypeErrorR
   (   t   coords(    (    s8   lib/python2.7/site-packages/astropy/coordinates/funcs.pyt   concatenate­   s    u   iauc         C` sZ  | d k r t  d   n  t sě t j d  } t j | d d d d d g } t j d	 d
 d } t g  | j d  D]) } | j d  sy | d  | d f ^ qy  } t	 j
 g  | d D] } | | ^ qź  }	 | t d <|	 t d <n t d } t d }	 |  j }
 |  j t d d   } |
 rN| j j   j } | j j   j } n | j j } | j j } t	 j t |  d t } | d k } x t |  D]k \ } } | d | k  | | d k  @| | d k @} | | | | @<| d k } t	 j |  d k rPqqWt  d j | |    | r:| d | } n
 |	 | } |
 rR| d S| Sd S(   u  
    Determines the constellation(s) a given coordinate object contains.

    Parameters
    ----------
    coord : coordinate object
        The object to determine the constellation of.
    short_name : bool
        If True, the returned names are the IAU-sanctioned abbreviated
        names.  Otherwise, full names for the constellations are used.
    constellation_list : str
        The set of constellations to use.  Currently only ``'iau'`` is
        supported, meaning the 88 "modern" constellations endorsed by the IAU.

    Returns
    -------
    constellation : str or string array
        If ``coords`` contains a scalar coordinate, returns the name of the
        constellation.  If it is an array coordinate object, it returns an array
        of names.

    Notes
    -----
    To determine which constellation a point on the sky is in, this precesses
    to B1875, and then uses the Delporte boundaries of the 88 modern
    constellations, as tabulated by
    `Roman 1987 <http://cdsarc.u-strasbg.fr/viz-bin/Cat?VI/42>`_.
    u   iauu8   only 'iau' us currently supported for constellation_listu#   data/constellation_data_roman87.datt   namesu   ralu   rauu   declu   nameu   data/constellation_names.datt   encodingu   UTF8u   
u   #i   i   u   ctableu   cnames_longt   equinoxu   B1875t   dtypei˙˙˙˙i    u0   Could not find constellation for coordinates {0}N(   t
   ValueErrort   _constellation_dataR	   t   get_pkg_data_contentsR   t   readt   dictt   splitt
   startswithR(   t   arrayt   isscalart   transform_toR   t   rat   ravelt   hourt   dect   degt   onest   lent   intt	   enumerateR*   t   format(   t   coordt
   short_namet   constellation_listt   cdatat   ctablet   cnamest   lt   cnames_short_to_longt   nmt   cnames_longRJ   t   constel_coordt   raht   decdt   constellidxt   notidedt   it   rowt   mskR>   (    (    s8   lib/python2.7/site-packages/astropy/coordinates/funcs.pyt   get_constellationË   sH    !,*


	,
(&   t   __doc__t
   __future__R    R   R   R   t   numpyR(   t    R   R   t	   constantsR   R   R#   t   ioR   t   utilsR   R	   t   sky_coordinateR
   t   builtin_framesR   R   t   representationR   R   t   builtin_frames.utilsR   t   __all__R   R   R8   R=   RC   R:   Rh   (    (    (    s8   lib/python2.7/site-packages/astropy/coordinates/funcs.pyt   <module>	   s&   "		0	0	/	