ó
šßÈ[c        
   @  s+  d  Z  d d l m Z m Z d d g Z d d l Z d d l 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 d d l m Z i e
 d 6e d 6e d 6e d 6e d 6e d 6Z d „  Z d „  Z e d „ Z d „  Z d d d e d e e d d d „	 Z d S(   s±   
Main Lomb-Scargle Implementation

The ``lombscargle`` function here is essentially a sophisticated switch
statement for the various implementations available in this submodule
iÿÿÿÿ(   t   print_functiont   divisiont   lombscarglet   available_methodsNi   (   t   lombscargle_slow(   t   lombscargle_fast(   t   lombscargle_scipy(   t   lombscargle_chi2(   t   lombscargle_fastchi2(   t   lombscargle_cythont   slowt   fastt   chi2t   scipyt   fastchi2t   cythonc          C  sp   d d d d g }  t  t j d ƒ r: |  j d d g ƒ n  y t j d ƒ |  j d ƒ Wn t k
 rk n X|  S(	   Nt   autoR
   R   R   t   atR   R   R   (   t   hasattrt   npt   ufunct   extendt   impt   find_modulet   appendt   ImportError(   t   methods(    (    sM   lib/python2.7/site-packages/astropy/stats/lombscargle/implementations/main.pyR       s    c         C  s_   t  j |  ƒ }  |  j d k r" t St |  ƒ d k r8 t St  j |  ƒ } t  j | d | ƒ Sd  S(   Ni   i    (   R   t   asarrayt   ndimt   Falset   lent   Truet   difft   allclose(   t	   frequencyR    (    (    sM   lib/python2.7/site-packages/astropy/stats/lombscargle/implementations/main.pyt   _is_regular0   s    c         C  s˜   t  j |  ƒ }  |  j d k r- t d ƒ ‚ nH t |  ƒ d k rT |  d |  d d f S| pc t |  ƒ su t d ƒ ‚ n  |  d |  d |  d t |  ƒ f S(   s‘  Utility to get grid parameters from a frequency array

    Parameters
    ----------
    frequency : array_like or Quantity
        input frequency grid
    assume_regular_frequency : bool (default = False)
        if True, then do not check whether frequency is a regular grid

    Returns
    -------
    f0, df, N : scalars
        Parameters such that all(frequency == f0 + df * np.arange(N))
    i   s$   frequency grid must be 1 dimensionali    s    frequency must be a regular grid(   R   R   R   t
   ValueErrorR   R#   (   R"   t   assume_regular_frequency(    (    sM   lib/python2.7/site-packages/astropy/stats/lombscargle/implementations/main.pyt   _get_frequency_grid<   s    c   
      C  só   t  ƒ  } d | k } | o< t | ƒ d k o< | p< t | ƒ } d | k o[ | d k o[ | }	 |  d k rË | s€ t j d ƒ n  | d k r¤ | r› d }  qÈ d }  qË | r³ d }  qË |	 rÂ d }  qË d	 }  n  |  t k rï t d
 j |  ƒ ƒ ‚ n  |  S(   s^   
    Validate the method argument, and if method='auto'
    choose the appropriate method
    R   iÈ   R   R   s[   Fast Lomb-Scargle methods require numpy version 1.8 or newer. Using slower methods instead.i   R   R   R   s   invalid method: {0}N(	   R   R   R#   t   Nonet   warningst   warnt   METHODSR$   t   format(
   t   methodt   dyt   fit_meant   ntermsR"   R%   R   t   fast_method_okt   prefer_fastt   prefer_scipy(    (    sM   lib/python2.7/site-packages/astropy/stats/lombscargle/implementations/main.pyt   validate_methodV   s(    						R   t   standardc         C  s¨  | j  } | j ƒ  } |  | | f } t d | d | d | d | d |
 |	 pN i   } t | d | d | d |
 d | d | ƒ} | d k r| j d ƒ r¨ t d	 ƒ ‚ n  | d k	 rô t j t j | ƒ ƒ } t j	 | d
 | ƒ sô t d ƒ ‚ qô n  |  | f } n  | j
 d ƒ rRt | j d ƒ | ƒ \ } } } | j d | d | d | ƒ n  | j d ƒ sˆ| j d ƒ d k rˆt d ƒ ‚ qˆn  t | | | Ž  } | j | ƒ S(   sÀ
  
    Compute the Lomb-scargle Periodogram with a given method.

    Parameters
    ----------
    t : array_like
        sequence of observation times
    y : array_like
        sequence of observations associated with times t
    dy : float or array_like (optional)
        error or sequence of observational errors associated with times t
    frequency : array_like
        frequencies (not angular frequencies) at which to evaluate the
        periodogram. If not specified, optimal frequencies will be chosen using
        a heuristic which will attempt to provide sufficient frequency range
        and sampling so that peaks will not be missed. Note that in order to
        use method='fast', frequencies must be regularly spaced.
    method : string (optional)
        specify the lomb scargle implementation to use. Options are:

        - 'auto': choose the best method based on the input
        - 'fast': use the O[N log N] fast method. Note that this requires
          evenly-spaced frequencies: by default this will be checked unless
          ``assume_regular_frequency`` is set to True.
        - `slow`: use the O[N^2] pure-python implementation
        - `chi2`: use the O[N^2] chi2/linear-fitting implementation
        - `fastchi2`: use the O[N log N] chi2 implementation. Note that this
          requires evenly-spaced frequencies: by default this will be checked
          unless `assume_regular_frequency` is set to True.
        - `scipy`: use ``scipy.signal.lombscargle``, which is an O[N^2]
          implementation written in C. Note that this does not support
          heteroskedastic errors.

    assume_regular_frequency : bool (optional)
        if True, assume that the input frequency is of the form
        freq = f0 + df * np.arange(N). Only referenced if method is 'auto'
        or 'fast'.
    normalization : string (optional, default='standard')
        Normalization to use for the periodogram.
        Options are 'standard' or 'psd'.
    fit_mean : bool (optional, default=True)
        if True, include a constant offset as part of the model at each
        frequency. This can lead to more accurate results, especially in the
        case of incomplete phase coverage.
    center_data : bool (optional, default=True)
        if True, pre-center the data by subtracting the weighted mean
        of the input data. This is especially important if `fit_mean = False`
    method_kwds : dict (optional)
        additional keywords to pass to the lomb-scargle method
    nterms : int (default=1)
        number of Fourier terms to use in the periodogram.
        Not supported with every method.

    Returns
    -------
    PLS : array_like
        Lomb-Scargle power associated with each frequency omega
    R"   t   center_dataR.   t   normalizationR/   R-   R%   R   s+   scipy method does not support fit_mean=Truei    s3   scipy method only supports uniform uncertainties dyR   t   f0t   dft   NfR   i   s<   nterms != 1 only supported with 'chi2' or 'fastchi2' methodsN(   t   shapet   ravelt   dictR3   t   popR$   R'   R   R   R!   t
   startswithR&   t   updatet   endswithR*   t   reshape(   t   tt   yR-   R"   R,   R%   R6   R.   R5   t   method_kwdsR/   t   output_shapet   argst   kwdsR7   R8   R9   t   PLS(    (    sM   lib/python2.7/site-packages/astropy/stats/lombscargle/implementations/main.pyR   z   s:    B		(   t   __doc__t
   __future__R    R   t   __all__R(   R   t   numpyR   t	   slow_implR   t	   fast_implR   t
   scipy_implR   t	   chi2_implR   t   fastchi2_implR   t   cython_implR	   R*   R   R#   R   R&   R3   R'   R   R   (    (    (    sM   lib/python2.7/site-packages/astropy/stats/lombscargle/implementations/main.pyt   <module>   s8   

			$