U
    d»{jŒ  ã                	   @   sž   d Z ddg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 ee	eeeedœZdd„ Zdd„ Zddd„Zdd„ Zddd„ZdS )z±
Main Lomb-Scargle Implementation

The ``lombscargle`` function here is essentially a sophisticated switch
statement for the various implementations available in this submodule
ÚlombscargleÚavailable_methodsé    Né   )Úlombscargle_chi2)Úlombscargle_cython)Úlombscargle_fast)Úlombscargle_fastchi2)Úlombscargle_scipy)Úlombscargle_slow)ÚslowÚfastÚchi2ÚscipyÚfastchi2Úcythonc                  C   s@   ddddddg} zdd l }W n tk
r0   Y nX |  d¡ | S )	NÚautor   r   r   r   r   r   r   )r   ÚImportErrorÚappend)Úmethodsr   © r   ú/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/timeseries/periodograms/lombscargle/implementations/main.pyr      s    
c                 C   sF   t  | ¡} | jdkrdS t| ƒdkr(dS t  | ¡}t  |d |¡S d S )Nr   FTr   )ÚnpÚasarrayÚndimÚlenÚdiffÚallclose)Ú	frequencyr   r   r   r   Ú_is_regular*   s    


r   Fc                 C   sn   t  | ¡} | jdkrtdƒ‚n2t| ƒdkr<| d | d dfS |sPt| ƒsPtdƒ‚| d | d | d  t| ƒfS )a¯  Utility to get grid parameters from a frequency array

    Parameters
    ----------
    frequency : array-like or `~astropy.units.Quantity` ['frequency']
        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 : scalar
        Parameters such that all(frequency == f0 + df * np.arange(N))
    r   z$frequency grid must be 1 dimensionalr   z frequency must be a regular grid)r   r   r   Ú
ValueErrorr   r   )r   Úassume_regular_frequencyr   r   r   Ú_get_frequency_grid6   s    


r!   c           	      C   s†   t ƒ }t|ƒdko|pt|ƒ}d|ko2|dko2| }| dkrl|dkrT|rNd} qld} n|r^d} n|rhd} nd	} | tkr‚td
| › �ƒ‚| S )z^
    Validate the method argument, and if method='auto'
    choose the appropriate method
    éÈ   r   Nr   r   r   r   r   r   zinvalid method: )r   r   r   ÚMETHODSr   )	ÚmethodÚdyÚfit_meanÚntermsr   r    r   Zprefer_fastZprefer_scipyr   r   r   Úvalidate_methodP   s$    
ÿr(   r   ÚstandardTc                 C   s  |j }| ¡ }| ||f}tf |||||
dœ|	p0i —Ž}t||||
||d�}|dkrœ| d¡rdtdƒ‚|dk	r”t t |¡¡}t |d |¡s”tdƒ‚| |f}| 	d	¡rÌt
| d
¡|ƒ\}}}|j|||d� | d¡sì| d¡dkrìtdƒ‚t| ||Ž}| |¡S )a�
  
    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 : str, 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 : str, optional
        Normalization to use for the periodogram.
        Options are 'standard' or 'psd'.
    fit_mean : bool, optional
        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
        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, optional
        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   Úcenter_datar&   Únormalizationr'   )r%   r&   r'   r   r    r   r&   z+scipy method does not support fit_mean=TrueNr   z3scipy method only supports uniform uncertainties dyr   r   )Úf0ÚdfÚNfr   r'   r   z<nterms != 1 only supported with 'chi2' or 'fastchi2' methods)ÚshapeZravelÚdictr(   Úpopr   r   r   r   Ú
startswithr!   ÚupdateÚendswithr#   Zreshape)ÚtÚyr%   r   r$   r    r+   r&   r*   Zmethod_kwdsr'   Zoutput_shapeÚargsÚkwdsr,   r-   r.   ZPLSr   r   r   r   o   sR    H
ûú	ú


 ÿ

ÿ)F)	NNr   Fr)   TTNr   )Ú__doc__Ú__all__Únumpyr   Z	chi2_implr   Zcython_implr   Z	fast_implr   Zfastchi2_implr   Z
scipy_implr	   Z	slow_implr
   r#   r   r   r!   r(   r   r   r   r   r   Ú<module>   s:   ú

"         õ