
    IR-e                         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 Zd ZddZd Z	 	 	 	 	 	 	 	 	 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                  d    g d} 	 dd l }|                     d           n# t          $ r Y nw xY w| S )N)autor   r   r   r   r   r   r   )r   appendImportError)methodsr   s     `lib/python3.11/site-packages/astropy/timeseries/periodograms/lombscargle/implementations/main.pyr   r      s[    DDDG  	w     Ns     
--c                     t          j        |           } | j        dk    rdS t          |           dk    rdS t          j        |           }t          j        |d         |          S )Nr   FTr   )npasarrayndimlendiffallclose)	frequencyr   s     r   _is_regularr    *   s^    
9%%I~u	Y1		twy!!{47D)))    Fc                 4   t          j        |           } | j        dk    rt          d          t	          |           dk    r| d         | d         dfS |st          |           st          d          | d         | d         | d         z
  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_frequencys     r   _get_frequency_gridr%   6   s     
9%%I~?@@@	Y1		|Yq\1,,& =+i*@*@ =;<<<Q<1	!4c)nnDDr!   c                     t                      }t          |          dk    o|pt          |          }d|v o|du o| }| dk    r|dk    r|rd} nd} n|rd} n|rd} nd	} | t          v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   prefer_fastprefer_scipys	            r   validate_methodr/   P   s    
  !!Gi..3&  :K	$:$:  g%E"*EXL Q;;  # 	FF 	FFFW4F44555Mr!   r   standardTc           	         |j         }|                                }| ||f}t          d|||||
d|	pi }t          ||||
||          }|dk    rz|                    d          rt          d          |Pt          j        t          j        |                    }t          j        |d         |          st          d          | |f}|	                    d	          r?t          |                    d
          |          \  }}}|                    |||           |                    d          s(|                    d          dk    rt          d          t          |         |i |}|                    |          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 )shaperaveldictr/   popr#   r   r   r   
startswithr%   updateendswithr(   reshape)tyr*   r   r)   r$   r3   r+   r2   method_kwdsr,   output_shapeargskwdsr4   r5   r6   PLSs                     r   r   r   o   s   P ?L!!I q":D #  " D !9  F 88J 	LJKKK>"*R..))B;r!ub)) X !VWWW1v    )(HH[!!#;
 

B 	rbR((( ??6"" 88H""N   &/4
(4
(
(C;;|$$$r!   )F)	NNr   Fr0   TTNr   )__doc____all__numpyr   	chi2_implr   cython_implr   	fast_implr   fastchi2_implr	   
scipy_implr
   	slow_implr   r(   r   r    r%   r/   r   r7   r!   r   <module>rP      s;    -
.     ' ' ' ' ' ' + + + + + + ' ' ' ' ' ' / / / / / / ) ) ) ) ) ) ' ' ' ' ' ' $  
 
 
	* 	* 	*E E E E4  D "x% x% x% x% x% x%r!   