σ
ίΘ[c           @` s0  d  Z  d d l m Z m Z m Z m Z d d l Z d d l 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 m Z m Z m Z d d l m Z d d l m Z m Z d d l m Z d d l m Z d d l  m! Z! d d d d d d d g Z" d d g Z# e d d d d e f d     Y Z$ e d d d d d   Z% e d d d d e f d      Y Z& e d d d! d"    Z' e d d d# d$    Z( e d d d% d&    Z) e d d d' e d  d(     Z* d)   Z+ d*   Z, d+   Z- d S(,   u+   Support VO Simple Cone Search capabilities.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   vos_catalog(   t	   AsyncBase(   t   ConeSearchErrort   VOSErrori   (   t   units(   t   ICRSt   BaseCoordinateFramet	   Longitudet   Latitudet   SkyCoord(   t   Quantity(   t   timefunct   RunTimePredictor(   t   AstropyUserWarning(   t
   deprecated(   t   datau   AsyncConeSearchu
   conesearchu   AsyncSearchAllu
   search_allu   list_catalogsu   predict_searchu   conesearch_timeru   2.0t   alternativeu3   astroquery.vo_conesearch.conesearch.AsyncConeSearcht   AsyncConeSearchc           B` s   e  Z d  Z d   Z RS(   uρ  Perform a Cone Search asynchronously and returns the result of the
    first successful query.

    .. note::

        See `~astropy.vo.client.vo_async.AsyncBase` for more details.

    Parameters
    ----------
    args, kwargs : see :func:`conesearch`

    Examples
    --------
    >>> from astropy import coordinates as coord
    >>> from astropy import units as u
    >>> c = coord.ICRS(6.0223 * u.degree, -72.0814 * u.degree)
    >>> async_search = conesearch.AsyncConeSearch(
    ...     c, 0.5 * u.degree,
    ...     catalog_db='The PMM USNO-A1.0 Catalogue (Monet 1997) 1')

    Check search status:

    >>> async_search.running()
    True
    >>> async_search.done()
    False

    Get search results after a 30-second wait (not to be
    confused with `astropy.utils.data.Conf.remote_timeout` that
    governs individual Cone Search queries). If search is still not
    done after 30 seconds, `TimeoutError` is raised. Otherwise,
    Cone Search result is returned and can be manipulated as in
    :ref:`Simple Cone Search Examples <vo-sec-scs-examples>`.
    If no ``timeout`` keyword given, it waits until completion:

    >>> async_result = async_search.get(timeout=30)
    >>> cone_arr = async_result.array.data
    >>> cone_arr.size
    36184

    c         O` s    t  t |   j t | |  d  S(   N(   t   superR   t   __init__t
   conesearch(   t   selft   argst   kwargs(    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyR   N   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyR   "   s   +u.   astroquery.vo_conesearch.conesearch.conesearchc   	      K` s   d d l  m } t |   \ } } t |  } t t |  } | d k rX t d   n  i | d 6| d 6| d 6| d	 6} t j | j	 d
 | | S(   uβ  Perform Cone Search and returns the result of the
    first successful query.

    Parameters
    ----------
    center : `~astropy.coordinates.SkyCoord`, `~astropy.coordinates.BaseCoordinateFrame`, or sequence of length 2
        Position of the center of the cone to search. It may be specified as an
        object from the :ref:`astropy-coordinates` package, or as a length 2
        sequence. If a sequence, it is assumed to be ``(RA, DEC)`` in the
        ICRS coordinate frame, given in decimal degrees.

    radius : float or `~astropy.units.quantity.Quantity`
        Radius of the cone to search:

            - If float is given, it is assumed to be in decimal degrees.
            - If astropy quantity is given, it is internally converted
              to degrees.

    verb : {1, 2, 3}
        Verbosity indicating how many columns are to be returned
        in the resulting table. Support for this parameter by
        a Cone Search service implementation is optional. If the
        service supports the parameter:

            1. Return the bare minimum number of columns that
               the provider considers useful in describing the
               returned objects.
            2. Return a medium number of columns between the
               minimum and maximum (inclusive) that are
               considered by the provider to most typically
               useful to the user.
            3. Return all of the columns that are available for
               describing the objects.

        If not supported, the service should ignore the parameter
        and always return the same columns for every request.

    catalog_db
        May be one of the following, in order from easiest to
        use to most control:

            - `None`: A database of
              `astropy.vo.Conf.conesearch_dbname` catalogs is
              downloaded from `astropy.vo.Conf.vos_baseurl`.  The
              first catalog in the database to successfully return a
              result is used.

            - *catalog name*: A name in the database of
              `astropy.vo.Conf.conesearch_dbname` catalogs at
              `astropy.vo.Conf.vos_baseurl` is used.  For a list of
              acceptable names, use :func:`list_catalogs`.

            - *url*: The prefix of a URL to a IVOA Service for
              `astropy.vo.Conf.conesearch_dbname`.  Must
              end in either '?' or '&'.

            - `~astropy.vo.client.vos_catalog.VOSCatalog` object: A specific
              catalog manually downloaded and selected from the database
              (see :ref:`vo-sec-client-vos`).

            - Any of the above 3 options combined in a list, in which case
              they are tried in order.

    pedantic : bool or `None`
        When `True`, raise an error when the file violates the spec,
        otherwise issue a warning. Warnings may be controlled using
        :py:mod:`warnings` module. When not provided, uses the
        configuration setting `astropy.io.votable.Conf.pedantic`,
        which defaults to `False`.

    verbose : bool
        Verbose output.

    cache : bool
        Use caching for VO Service database. Access to actual VO
        websites referenced by the database still needs internet
        connection.

    Returns
    -------
    obj : `astropy.io.votable.tree.Table`
        First table from first successful VO service request.

    Raises
    ------
    ConeSearchError
        When invalid inputs are passed into Cone Search.

    VOSError
        If VO service request fails.

    i   (   t   confi   i   u   Verbosity must be 1, 2, or 3u   RAu   DECu   SRu   VERBR   (   i   i   i   (
   t    R   t   _validate_coordt   _validate_srt   _local_conversiont   intR   R   t   call_vo_servicet   conesearch_dbname(	   t   centert   radiust   verbR   R   t   rat   dect   srR   (    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyR   R   s    _"u2   astroquery.vo_conesearch.conesearch.AsyncSearchAllt   AsyncSearchAllc           B` s   e  Z d  Z d   Z RS(   u  Perform a Cone Search asynchronously, storing all results
    instead of just the result from first successful query.

    .. note::

        See `~astropy.vo.client.vo_async.AsyncBase` for more details.

    Parameters
    ----------
    args, kwargs : see :func:`search_all`

    Examples
    --------
    >>> from astropy import coordinates as coord
    >>> from astropy import units as u
    >>> c = coord.ICRS(6.0223 * u.degree, -72.0814 * u.degree)
    >>> async_search = conesearch.AsyncSearchAll(c, 0.5 * u.degree)

    Check search status:

    >>> async_search.running()
    True
    >>> async_search.done()
    False

    Get a dictionary of all search results after a 30-second wait (not
    to be confused with `astropy.utils.data.Conf.remote_timeout` that
    governs individual Cone Search queries). If search is still not
    done after 30 seconds, `TimeoutError` is raised. Otherwise, a
    dictionary is returned and can be manipulated as in :ref:`Simple
    Cone Search Examples <vo-sec-scs-examples>`.  If no ``timeout``
    keyword given, it waits until completion:

    >>> async_allresults = async_search.get(timeout=30)
    >>> all_catalogs = list(async_allresults)
    >>> first_cone_arr = async_allresults[all_catalogs[0]].array.data
    >>> first_cone_arr.size
    36184

    c         O` s   t  j |  t | |  d  S(   N(   R   R   t
   search_all(   R   R   R   (    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyR   ο   s    (   R   R   R   R   (    (    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyR-   Δ   s   *u.   astroquery.vo_conesearch.conesearch.search_allc          O` sή   d d l  m } i  } | j d d	  } d | k rD | j d  n  | j d t  } | j d t  } t j | j | d | d | } xN | D]F \ } }	 y t	 d |	 |  |  }
 Wn t
 k
 rΘ q X|
 | |
 j <q W| S(
   u  Perform Cone Search and returns the results of
    all successful queries.

    .. warning::

        Could potentially take up significant run time and
        computing resources.

    Parameters
    ----------
    args, kwargs :
        Arguments and keywords accepted by :func:`conesearch`.

    Returns
    -------
    all_results : dict of `astropy.io.votable.tree.Table` objects
        A dictionary of tables from successful VO service requests,
        with keys being the access URLs. If none is successful,
        an empty dictionary is returned.

    Raises
    ------
    ConeSearchError
        When invalid inputs are passed into Cone Search.

    i   (   R   u
   catalog_dbu   cacheu   verboset   cachet   verboset
   catalog_dbN(   R    R   t   gett   Nonet   popt   TrueR   t   _get_catalogsR&   R   R   t   url(   R   R   R   t   all_resultsR1   R/   R0   t   catalogst   namet   catalogt   result(    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyR.   σ   s     u1   astroquery.vo_conesearch.conesearch.list_catalogsc          K` s#   d d l  m } t j | j |   S(   uo  Return the available Cone Search catalogs as a list of strings.
    These can be used for the ``catalog_db`` argument to
    :func:`conesearch`.

    Parameters
    ----------
    cache : bool
        Use caching for VO Service database. Access to actual VO
        websites referenced by the database still needs internet
        connection.

    verbose : bool
        Show download progress bars.

    pattern : str or `None`
        If given string is anywhere in a catalog name, it is
        considered a matching catalog. It accepts patterns as
        in :py:mod:`fnmatch` and is case-insensitive.
        By default, all catalogs are returned.

    sort : bool
        Sort output in alphabetical order. If not sorted, the
        order depends on dictionary hashing. Default is `True`.

    Returns
    -------
    arr : list of str
        List of catalog names.

    i   (   R   (   R    R   R   t   list_catalogsR&   (   R   R   (    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyR=   )  s    !u2   astroquery.vo_conesearch.conesearch.predict_searchc      	   O` s$  t  |  d k r! t d   n  | j d t  } d | k rI | d =n  | \ } } t |  } | d k r| t d   n  |  | d <t t | |  } d } d | }	 d	 | }
 d
 | |
 |	 } t j |	 |
 | |  } | j	 |  | j
   } | j |  } | d k  s!| d d k  rDt j d j | | d  t  n4 | t j j k rxt j d j t j j  t  n  t | j  } g  | D] } | j | j j ^ q} t j | | d  } t j |  } t t | |    } | d k  s| d d k  r(t j d j | | d  t  n  | rd d l j } d } t j | |  } | |  } | j d |  | j   \ } } | j | | d d d | j | | d d d | j  | g | g d d d d d d | j! |  | j" d  | j# d d d d  | j$   n  | | f S(    uP  Predict the run time needed and the number of objects
    for a Cone Search for the given access URL, position, and
    radius.

    Run time prediction uses `astropy.utils.timer.RunTimePredictor`.
    Baseline searches are done with starting and ending radii at
    0.05 and 0.5 of the given radius, respectively.

    Extrapolation on good data uses least-square straight line fitting,
    assuming linear increase of search time and number of objects
    with radius, which might not be accurate for some cases. If
    there are less than 3 data points in the fit, it fails.

    Warnings (controlled by :py:mod:`warnings`) are given when:

        #. Fitted slope is negative.
        #. Any of the estimated results is negative.
        #. Estimated run time exceeds
           `astropy.utils.data.Conf.remote_timeout`.

    .. note::

        If ``verbose=True``, extra log info will be provided.
        But unlike :func:`conesearch_timer`, timer info is suppressed.

        If ``plot=True``, plot will be displayed.
        Plotting uses `matplotlib <http://matplotlib.sourceforge.net/>`_.

        The predicted results are just *rough* estimates.

        Prediction is done using :func:`conesearch`. Prediction for
        `AsyncConeSearch` is not supported.

    Parameters
    ----------
    url : str
        Cone Search access URL to use.

    args, kwargs : see :func:`conesearch`
        Extra keyword ``plot`` is allowed and only used by this
        function and not :func:`conesearch`.

    Returns
    -------
    t_est : float
        Estimated time in seconds needed for the search.

    n_est : int
        Estimated number of objects the search will yield.

    Raises
    ------
    AssertionError
        If prediction fails.

    ConeSearchError
        If input parameters are invalid.

    VOSError
        If VO service request fails.

    i   u(   conesearch must have exactly 2 argumentsu   ploti    u!   Search radius must be > 0 degreesu
   catalog_dbi
   g©?g      ΰ?g      π?i   u;   Estimated runtime ({0} s) is non-physical with slope of {1}u1   Estimated runtime is longer than timeout of {0} su:   Estimated #objects ({0}) is non-physical with slope of {1}Nu   radius (deg)t
   xlabeltextu   kx-t   labelu   Actualu   b--u   Fitt   markeru   ot   cu   ru	   Predictedu   #objectst   locu   bestt	   numpoints(%   t   lenR   R2   t   FalseR"   R   R   t   npt   aranget	   time_funct   do_fitt   predict_timet   warningst   warnt   formatR   R   R   t   remote_timeoutt   sortedt   resultst   arrayt   sizet   polyfitt   poly1dR$   t   roundt   matplotlib.pyplott   pyplott   appendt   plott   subplotst   scattert
   set_xlabelt
   set_ylabelt   legendt   draw(   R7   R   R   RY   R'   R(   R,   t   cs_predt   num_datapointst   sr_mint   sr_maxt   sr_stept   sr_arrt   t_coeffst   t_estt   keyt   n_arrt   n_coeffst	   n_fitfunct   n_estt   pltR>   t   sr_fitt   n_fitt   figt   ax(    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyt   predict_searchO  sd    A



&(u4   astroquery.vo_conesearch.conesearch.conesearch_timerc          O` s   t  |  |   S(   ue  Time a single Cone Search using `astropy.utils.timer.timefunc`
    with a single try and a verbose timer.

    Parameters
    ----------
    args, kwargs : see :func:`conesearch`

    Returns
    -------
    t : float
        Run time in seconds.

    obj : `astropy.io.votable.tree.Table`
        First table from first successful VO service request.

    (   R   (   R   R   (    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyt   conesearch_timerΦ  s    c         C` s@   y |  |  } Wn% t  k
 r7 } t t |    n X| Sd S(   uF   Try ``func(x)`` and replace `ValueError` with
    ``ConeSearchError``.N(   t
   ValueErrorR   t   str(   t   funct   xt   yt   e(    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyR#   ν  s
    c         C` s   t  |  t  r$ |  j t  j } nV t  |  t  rE |  j t  } n5 t t |  d d t j t	 |  d d t j  } | j
 j | j j f S(   u   Validate coordinates.i    t   uniti   (   t
   isinstanceR   t   transform_toR	   t   frameR
   R   t   ut   degreeR   R*   R+   (   R'   t	   icrscoord(    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyR!   ψ  s    c         C` s8   t  |  t  r$ |  j t j  } n |  t j } | j S(   u   Validate search radius.(   R{   R   t   toR~   R   t   value(   R(   t   sr_angle(    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyR"     s    (.   R   t
   __future__R    R   R   R   RK   t   numpyRF   R    R   t   vo_asyncR   t
   exceptionsR   R   R   R~   t   coordinatesR	   R
   R   R   R   R   t   utils.timerR   R   t   utils.exceptionsR   t   utils.decoratorsR   t   utilsR   t   __all__t   __doctest_skip__R   R   R-   R.   R=   Rr   Rs   R#   R!   R"   (    (    (    s;   lib/python2.7/site-packages/astropy/vo/client/conesearch.pyt   <module>   sJ   "(.p-5%		