ó
šßÈ[c           @  sN   d  d l  m Z m Z d  d l Z d d l m Z e e d e d d „ Z	 d S(   iÿÿÿÿ(   t   print_functiont   divisionNi   (   t   trig_sumt   standardc      	   C  sˆ  | d k r d } n  t j |  | | ƒ \ }  } } |  j d k rQ t d ƒ ‚ n  | d k  rl t d ƒ ‚ n  | d k r‡ t d ƒ ‚ n  | d k r¢ t d ƒ ‚ n  | d } | | j ƒ  } | sÈ | rá | t j | | ƒ } n  t j |
 pð i  ƒ } | j	 d | d	 | d
 |	 d | ƒ t
 |  | | |  \ } } t
 |  | d d | \ } } | r™t
 |  | |  \ } } | d | | | | | | | } n
 | | } | t j d | | ƒ } d t j d | | ƒ } t j d ƒ t j d | ƒ } t j d ƒ t j | ƒ t j d | ƒ } t j | | d ƒ } | | | | } | | | | } d d | | | | } d d | | | | } | rÑ| | | | | d 8} | | | | | d 8} n  | | | | | | } | d k r| | } n€ | d k r!| | | } nc | d k rHt j d | | ƒ } n< | d k ro| d | d j ƒ  9} n t d j | ƒ ƒ ‚ | S(   sÓ  Fast Lomb-Scargle Periodogram

    This implements the Press & Rybicki method [1]_ for fast O[N log(N)]
    Lomb-Scargle periodograms.

    Parameters
    ----------
    t, y, dy : array_like  (NOT astropy.Quantities)
        times, values, and errors of the data points. These should be
        broadcastable to the same shape.
    f0, df, Nf : (float, float, int)
        parameters describing the frequency grid, f = f0 + df * arange(Nf).
    center_data : bool (default=True)
        Specify whether to subtract the mean of the data before the fit
    fit_mean : bool (default=True)
        If True, then compute the floating-mean periodogram; i.e. let the mean
        vary with the fit.
    normalization : string (optional, default='standard')
        Normalization to use for the periodogram.
        Options are 'standard', 'model', 'log', or 'psd'.
    use_fft : bool (default=True)
        If True, then use the Press & Rybicki O[NlogN] algorithm to compute
        the result. Otherwise, use a slower O[N^2] algorithm
    trig_sum_kwds : dict or None (optional)
        extra keyword arguments to pass to the ``trig_sum`` utility.
        Options are ``oversampling`` and ``Mfft``. See documentation
        of ``trig_sum`` for details.

    Returns
    -------
    power : ndarray
        Lomb-Scargle power associated with each frequency.
        Units of the result depend on the normalization.

    Notes
    -----
    Note that the ``use_fft=True`` algorithm is an approximation to the true
    Lomb-Scargle periodogram, and as the number of points grows this
    approximation improves. On the other hand, for very small datasets
    (<~50 points or so) this approximation may not be useful.

    References
    ----------
    .. [1] Press W.H. and Rybicki, G.B, "Fast algorithm for spectral analysis
        of unevenly sampled data". ApJ 1:338, p277, 1989
    .. [2] M. Zechmeister and M. Kurster, A&A 496, 577-584 (2009)
    .. [3] W. Press et al, Numerical Recipes in C (2002)
    i   s"   t, y, dy should be one dimensionali    s   Frequencies must be positives    Frequency steps must be positives&   Number of frequencies must be positiveg       Àt   f0t   dft   use_fftt   Nt   freq_factori   g      à?R   t   modelt   logt   psds"   normalization='{0}' not recognizedN(   t   Nonet   npt   broadcast_arrayst   ndimt
   ValueErrort   sumt   dott   dictt   copyt   updateR   t   sqrtt   signR
   t   format(   t   tt   yt   dyR   R   t   Nft   center_datat   fit_meant   normalizationR   t   trig_sum_kwdst   wt   kwargst   Sht   Cht   S2t   C2t   St   Ct   tan_2omega_taut   S2wt   C2wt   Cwt   Swt   YYt   YCt   YSt   CCt   SSt   power(    (    sR   lib/python2.7/site-packages/astropy/stats/lombscargle/implementations/fast_impl.pyt   lombscargle_fast   s^    4	
")
	 -	(
   t
   __future__R    R   t   numpyR   t   utilsR   t   TrueR   R4   (    (    (    sR   lib/python2.7/site-packages/astropy/stats/lombscargle/implementations/fast_impl.pyt   <module>   s
   