
    IR-e@                    0   d Z ddlZddl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mZ dd	lmZmZ dd
lmZ g dZdej        z  Z e ej        ej                  j                  Zd ej        d ej        d          z            z  Z  G d de          Z! G d de          Z" G d de          Z# G d de          Z$ G d de          Z% G d de          Z& G d de          Z' G d de          Z( G d de(          Z) G d  d!e(          Z* G d" d#e(          Z+ G d$ d%e(          Z, G d& d'e,          Z- G d( d)e,          Z. G d* d+e,          Z/ G d, d-e          Z0 G d. d/e          Z1 G d0 d1e          Z2 G d2 d3e          Z3 G d4 d5e          Z4 G d6 d7e          Z5 G d8 d9e          Z6 G d: d;e          Z7 G d< d=e          Z8 G d> d?e          Z9 G d@ dAe          Z: G dB dCe          Z; G dD dEe          Z< G dF dGe          Z= G dH dIe          Z> G dJ dKe          Z? G dL dMe          Z@ G dN dOe          ZA G dP dQe          ZB G dR dSe          ZC G dT dUe          ZD G dV dWe          ZEdS )XzMathematical models.    N)units)Quantity
UnitsError)	HAS_SCIPY)AstropyDeprecationWarning   )Fittable1DModelFittable2DModel)InputParameterError	Parameter)ellipse_extent)#
AiryDisk2DMoffat1DMoffat2DBox1DBox2DConst1DConst2D	Ellipse2DDisk2D
Gaussian1D
Gaussian2DLinear1D	Lorentz1DRickerWavelet1DRickerWavelet2DRedshiftScaleFactorMultiplyPlanar2DScaleSersic1DSersic2DShiftSine1DCosine1D	Tangent1D	ArcSine1DArcCosine1DArcTangent1DTrapezoid1DTrapezoidDisk2DRing2DVoigt1DKingProjectedAnalytic1DExponential1DLogarithmic1D          @c                       e Zd ZdZ edd          Z edd          Z ededfd	          ZddZ	e
d             Zed             Zed             Ze
d             Zd ZdS )r   a  
    One dimensional Gaussian model.

    Parameters
    ----------
    amplitude : float or `~astropy.units.Quantity`.
        Amplitude (peak value) of the Gaussian - for a normalized profile
        (integrating to 1), set amplitude = 1 / (stddev * np.sqrt(2 * np.pi))
    mean : float or `~astropy.units.Quantity`.
        Mean of the Gaussian.
    stddev : float or `~astropy.units.Quantity`.
        Standard deviation of the Gaussian with FWHM = 2 * stddev * np.sqrt(2 * np.log(2)).

    Notes
    -----
    Either all or none of input ``x``, ``mean`` and ``stddev`` must be provided
    consistently with compatible units or as unitless numbers.

    Model formula:

        .. math:: f(x) = A e^{- \frac{\left(x - x_{0}\right)^{2}}{2 \sigma^{2}}}

    Examples
    --------
    >>> from astropy.modeling import models
    >>> def tie_center(model):
    ...         mean = 50 * model.stddev
    ...         return mean
    >>> tied_parameters = {'mean': tie_center}

    Specify that 'mean' is a tied parameter in one of two ways:

    >>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3,
    ...                             tied=tied_parameters)

    or

    >>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3)
    >>> g1.mean.tied
    False
    >>> g1.mean.tied = tie_center
    >>> g1.mean.tied
    <function tie_center at 0x...>

    Fixed parameters:

    >>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3,
    ...                        fixed={'stddev': True})
    >>> g1.stddev.fixed
    True

    or

    >>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3)
    >>> g1.stddev.fixed
    False
    >>> g1.stddev.fixed = True
    >>> g1.stddev.fixed
    True

    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import Gaussian1D

        plt.figure()
        s1 = Gaussian1D()
        r = np.arange(-5, 5, .01)

        for factor in range(1, 4):
            s1.amplitude = factor
            plt.plot(r, s1(r), color=str(0.25 * factor), lw=2)

        plt.axis([-5, 5, -1, 4])
        plt.show()

    See Also
    --------
    Gaussian2D, Box1D, Moffat1D, Lorentz1D
    r   z&Amplitude (peak value) of the Gaussiandefaultdescriptionr   zPosition of peak (Gaussian)Nz"Standard deviation of the Gaussianr5   boundsr6         @c                 8    | j         }|| j        z  }||z
  ||z   fS )aV  
        Tuple defining the default ``bounding_box`` limits,
        ``(x_low, x_high)``.

        Parameters
        ----------
        factor : float
            The multiple of `stddev` used to define the limits.
            The default is 5.5, corresponding to a relative error < 1e-7.

        Examples
        --------
        >>> from astropy.modeling.models import Gaussian1D
        >>> model = Gaussian1D(mean=0, stddev=2)
        >>> model.bounding_box
        ModelBoundingBox(
            intervals={
                x: Interval(lower=-11.0, upper=11.0)
            }
            model=Gaussian1D(inputs=('x',))
            order='C'
        )

        This range can be set directly (see: `Model.bounding_box
        <astropy.modeling.Model.bounding_box>`) or by using a different factor,
        like:

        >>> model.bounding_box = model.bounding_box(factor=2)
        >>> model.bounding_box
        ModelBoundingBox(
            intervals={
                x: Interval(lower=-4.0, upper=4.0)
            }
            model=Gaussian1D(inputs=('x',))
            order='C'
        )
        )meanstddevselffactorx0dxs       Blib/python3.11/site-packages/astropy/modeling/functional_models.pybounding_boxzGaussian1D.bounding_box   s+    L Ydk!Rb!!    c                      | j         t          z  S )z$Gaussian full width at half maximum.)r<   GAUSSIAN_SIGMA_TO_FWHMr>   s    rB   fwhmzGaussian1D.fwhm   s     {333rD   c                 N    |t          j        d| |z
  dz  z  |dz  z            z  S )z,
        Gaussian1D model function.
              r1   npexp)x	amplituder;   r<   s       rB   evaluatezGaussian1D.evaluate   s/    
 26$!d(q"8619"DEEEErD   c                     t          j        d|dz  z  | |z
  dz  z            }||z  | |z
  z  |dz  z  }||z  | |z
  dz  z  |dz  z  }|||gS )z8
        Gaussian1D model function derivatives.
        rJ   r1      rK   )rN   rO   r;   r<   d_amplituded_meand_stddevs          rB   	fit_derivzGaussian1D.fit_deriv   sr    
 fTFAI-Ta?@@[(AH5	A{*a$h1_<vqyHVX..rD   c                 P    | j         j        d S | j        d         | j         j        iS Nr   )r;   
input_unitinputsrG   s    rB   input_unitszGaussian1D.input_units   s(    9'4A	 455rD   c                 t    || j         d                  || j         d                  || j        d                  dS )Nr   )r;   r<   rO   rZ   outputsr>   inputs_unitoutputs_units      rB   _parameter_units_for_data_unitsz*Gaussian1D._parameter_units_for_data_units   s;    A/!$+a.1%dl1o6
 
 	
rD   r9   )__name__
__module____qualname____doc__r   rO   r;   FLOAT_EPSILONr<   rC   propertyrH   staticmethodrP   rV   r[   rb    rD   rB   r   r   A   s       R Rh 	G  I 9Q,IJJJD Yt$8  F)" )" )" )"V 4 4 X4 F F \F / / \/ 6 6 X6

 
 
 
 
rD   r   c                   h    e Zd ZdZ edd          Z edd          Z edd          Z edd          Z edd	          Z	 ed
d          Z
ej        ej        ej        ddddf fd	Zed             Zed             ZddZed             Zed             Zed             Zd Z xZS )r   ap  
    Two dimensional Gaussian model.

    Parameters
    ----------
    amplitude : float or `~astropy.units.Quantity`.
        Amplitude (peak value) of the Gaussian.
    x_mean : float or `~astropy.units.Quantity`.
        Mean of the Gaussian in x.
    y_mean : float or `~astropy.units.Quantity`.
        Mean of the Gaussian in y.
    x_stddev : float or `~astropy.units.Quantity` or None.
        Standard deviation of the Gaussian in x before rotating by theta. Must
        be None if a covariance matrix (``cov_matrix``) is provided. If no
        ``cov_matrix`` is given, ``None`` means the default value (1).
    y_stddev : float or `~astropy.units.Quantity` or None.
        Standard deviation of the Gaussian in y before rotating by theta. Must
        be None if a covariance matrix (``cov_matrix``) is provided. If no
        ``cov_matrix`` is given, ``None`` means the default value (1).
    theta : float or `~astropy.units.Quantity`, optional.
        The rotation angle as an angular quantity
        (`~astropy.units.Quantity` or `~astropy.coordinates.Angle`)
        or a value in radians (as a float). The rotation angle
        increases counterclockwise. Must be `None` if a covariance matrix
        (``cov_matrix``) is provided. If no ``cov_matrix`` is given,
        `None` means the default value (0).
    cov_matrix : ndarray, optional
        A 2x2 covariance matrix. If specified, overrides the ``x_stddev``,
        ``y_stddev``, and ``theta`` defaults.

    Notes
    -----
    Either all or none of input ``x, y``, ``[x,y]_mean`` and ``[x,y]_stddev``
    must be provided consistently with compatible units or as unitless numbers.

    Model formula:

        .. math::

            f(x, y) = A e^{-a\left(x - x_{0}\right)^{2}  -b\left(x - x_{0}\right)
            \left(y - y_{0}\right)  -c\left(y - y_{0}\right)^{2}}

    Using the following definitions:

        .. math::
            a = \left(\frac{\cos^{2}{\left (\theta \right )}}{2 \sigma_{x}^{2}} +
            \frac{\sin^{2}{\left (\theta \right )}}{2 \sigma_{y}^{2}}\right)

            b = \left(\frac{\sin{\left (2 \theta \right )}}{2 \sigma_{x}^{2}} -
            \frac{\sin{\left (2 \theta \right )}}{2 \sigma_{y}^{2}}\right)

            c = \left(\frac{\sin^{2}{\left (\theta \right )}}{2 \sigma_{x}^{2}} +
            \frac{\cos^{2}{\left (\theta \right )}}{2 \sigma_{y}^{2}}\right)

    If using a ``cov_matrix``, the model is of the form:
        .. math::
            f(x, y) = A e^{-0.5 \left(
                    \vec{x} - \vec{x}_{0}\right)^{T} \Sigma^{-1} \left(\vec{x} - \vec{x}_{0}
                \right)}

    where :math:`\vec{x} = [x, y]`, :math:`\vec{x}_{0} = [x_{0}, y_{0}]`,
    and :math:`\Sigma` is the covariance matrix:

        .. math::
            \Sigma = \left(\begin{array}{ccc}
            \sigma_x^2               & \rho \sigma_x \sigma_y \\
            \rho \sigma_x \sigma_y   & \sigma_y^2
            \end{array}\right)

    :math:`\rho` is the correlation between ``x`` and ``y``, which should
    be between -1 and +1.  Positive correlation corresponds to a
    ``theta`` in the range 0 to 90 degrees.  Negative correlation
    corresponds to a ``theta`` in the range of 0 to -90 degrees.

    See [1]_ for more details about the 2D Gaussian function.

    See Also
    --------
    Gaussian1D, Box2D, Moffat2D

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Gaussian_function
    r   zAmplitude of the Gaussianr4   r   z(Peak position (along x axis) of Gaussianz(Peak position (along y axis) of Gaussianz1Standard deviation of the Gaussian (along x axis)z1Standard deviation of the Gaussian (along y axis)        zNRotation angle either as a float (in radians) or a |Quantity| angle (optional)Nc           
         |:|| j         j        j        }|| j         j        j        }|| j         j        j        }n|||t          d          t          j        |          }|j        dk    rt          d          t          j
                            |          \  }	}
t          j        |	          \  }}|
d d df         }t          j        |d         |d                   }|                    di            |d                             dt          d f           |d                             dt          d f            t!                      j        d
||||||d	| d S )Nz3Cannot specify both cov_matrix and x/y_stddev/theta)r1   r1   zCovariance matrix must be 2x2r   r   r8   x_stddevy_stddev)rO   x_meany_meanro   rp   thetark   )	__class__ro   r5   rp   rs   r   rL   arrayshape
ValueErrorlinalgeigsqrtarctan2
setdefaultrh   super__init__)r>   rO   rq   rr   ro   rp   rs   
cov_matrixkwargseig_valseig_vecsy_vecrt   s               rB   r~   zGaussian2D.__init__^  s    >2:>2:},4#x';u?P)I   *--J6)) !@AAA!#z!:!:Hh!#!2!2HhQQQTNEJuQxq22E 	(B'''x##J0EFFFx##J0EFFF 	
	
 	
 	
 	
 	
 	
 	
rD   c                      | j         t          z  S )z)Gaussian full width at half maximum in X.)ro   rF   rG   s    rB   x_fwhmzGaussian2D.x_fwhm       }555rD   c                      | j         t          z  S )z)Gaussian full width at half maximum in Y.)rp   rF   rG   s    rB   y_fwhmzGaussian2D.y_fwhm  r   rD   r9   c                     || j         z  }|| j        z  }t          ||| j                  \  }}| j        |z
  | j        |z   f| j        |z
  | j        |z   ffS )a  
        Tuple defining the default ``bounding_box`` limits in each dimension,
        ``((y_low, y_high), (x_low, x_high))``.

        The default offset from the mean is 5.5-sigma, corresponding
        to a relative error < 1e-7. The limits are adjusted for rotation.

        Parameters
        ----------
        factor : float, optional
            The multiple of `x_stddev` and `y_stddev` used to define the limits.
            The default is 5.5.

        Examples
        --------
        >>> from astropy.modeling.models import Gaussian2D
        >>> model = Gaussian2D(x_mean=0, y_mean=0, x_stddev=1, y_stddev=2)
        >>> model.bounding_box
        ModelBoundingBox(
            intervals={
                x: Interval(lower=-5.5, upper=5.5)
                y: Interval(lower=-11.0, upper=11.0)
            }
            model=Gaussian2D(inputs=('x', 'y'))
            order='C'
        )

        This range can be set directly (see: `Model.bounding_box
        <astropy.modeling.Model.bounding_box>`) or by using a different factor
        like:

        >>> model.bounding_box = model.bounding_box(factor=2)
        >>> model.bounding_box
        ModelBoundingBox(
            intervals={
                x: Interval(lower=-2.0, upper=2.0)
                y: Interval(lower=-4.0, upper=4.0)
            }
            model=Gaussian2D(inputs=('x', 'y'))
            order='C'
        )
        )ro   rp   r   rs   rr   rq   )r>   r?   abrA   dys         rB   rC   zGaussian2D.bounding_box  sl    V T]"T]"1dj11B [2t{R/0[2t{R/0
 	
rD   c                 h   t          j        |          dz  }t          j        |          dz  }	t          j        d|z            }
|dz  }|dz  }| |z
  }||z
  }d||z  |	|z  z   z  }d|
|z  |
|z  z
  z  }d|	|z  ||z  z   z  }|t          j        ||dz  z  ||z  |z  z   ||dz  z  z              z  S )z"Two dimensional Gaussian function.r1   r2         ?rL   cossinrM   )rN   yrO   rq   rr   ro   rp   rs   cost2sint2sin2txstd2ystd2xdiffydiffr   r   cs                     rB   rP   zGaussian2D.evaluate  s     u"u"sU{##!!F
F
EEMeem45EEMeem45EEMeem45265!8|E	E 12a%(lCD
 
 
 	
rD   c                 t   t          j        |          }t          j        |          }	t          j        |          dz  }
t          j        |          dz  }t          j        d|z            }t          j        d|z            }|dz  }|dz  }|dz  }|dz  }| |z
  }||z
  }|dz  }|dz  }d|
|z  ||z  z   z  }d||z  ||z  z
  z  }d||z  |
|z  z   z  }|t          j        ||z  ||z  |z  z   ||z  z              z  }|	|z  d|z  d|z  z
  z  }|
 |z  }| |z  }||z  ||z  z
  }| |z  }||z  }| } | |z  }!|
 |z  }"||z  }#|d|z  |z  ||z  z   z  }$|||z  d|z  |z  z   z  }%|||z  ||z  |z  z   |!|z  z    z  }&|||z  ||z  |z  z   |"|z  z    z  }'|||z  ||z  |z  z   | |z  z    z  }(|#|$|%|&|'|(gS )zHTwo dimensional Gaussian function derivative with respect to parameters.r1   r2   rR   r         ?r   ))rN   r   rO   rq   rr   ro   rp   rs   costsintr   r   cos2tr   r   r   xstd3ystd3r   r   xdiff2ydiff2r   r   r   g	da_dthetada_dx_stddevda_dy_stddev	db_dthetadb_dx_stddevdb_dy_stddev	dc_dthetadc_dx_stddevdc_dy_stddevdg_dA
dg_dx_mean
dg_dy_meandg_dx_stddevdg_dy_stddev	dg_dthetas)                                            rB   rV   zGaussian2D.fit_deriv  s    ve}}ve}}u"u"sU{##sU{##!!!!F
F
EEMeem45EEMeem45EEMeem45!f*UU1B!Cq6z!RSTTT4KC%KC%K#@A	v~v~U]uu}5	v~u}J	v~v~I37U?q5y9:
1u9q59:
v%&./'(
 v%&./'(
 & 9u#4u#<<y6?QQR
	 z:|\9UUrD   c                 v    | j         j        }| j        j        }||d S | j        d         || j        d         |iS Nr   r   )rq   rY   rr   rZ   r>   x_unity_units      rB   r[   zGaussian2D.input_units  s?    ''>fn4AA??rD   c                 @   || j         d                  || j         d                  k    rt          d          || j         d                  || j         d                  || j         d                  || j         d                  t          j        || j        d                  dS )Nr   r   (Units of 'x' and 'y' inputs should match)rq   rr   ro   rp   rs   rO   rZ   r   uradr^   r_   s      rB   rb   z*Gaussian2D._parameter_units_for_data_units  s     t{1~&+dk!n*EEEGHHH!$+a.1!$+a.1#DKN3#DKN3U%dl1o6
 
 	
rD   rc   )rd   re   rf   rg   r   rO   rq   rr   ro   rp   rs   r5   r~   ri   r   r   rC   rj   rP   rV   r[   rb   __classcell__rt   s   @rB   r   r      s       S Sj 	!1LMMMIYI  F YI  F yR  H yR  H I*  E #~~2
 2
 2
 2
 2
 2
h 6 6 X6 6 6 X62
 2
 2
 2
h 
 
 \
  1V 1V \1Vf @ @ X@
 
 
 
 
 
 
rD   r   c                       e Zd ZdZ edd          ZdZdZed             Z	ed             Z
ed             Zed	             Zed
             Zd ZdS )r#   zv
    Shift a coordinate.

    Parameters
    ----------
    offset : float
        Offset to add to a coordinate.
    r   zOffset to add to a modelr4   Tc                 P    | j         j        d S | j        d         | j         j        iS rX   )offsetrY   rZ   rG   s    rB   r[   zShift.input_units>  (    ;!)4A 677rD   c                                                        }|xj        dz  c_        	  j         t           fd j        D                       |_        n# t          $ r Y nw xY w|S )z-One dimensional inverse Shift model function.c              3   N   K   | ]}                     |j                  V   d S N)rP   r   .0rN   r>   s     rB   	<genexpr>z Shift.inverse.<locals>.<genexpr>O  D       % %23a--% % % % % %rD   )copyr   rC   tupleNotImplementedErrorr>   invs   ` rB   inversezShift.inverseD  s     iikk

b

	  % % % % %7;7H% % %    C # 	 	 	D	 
s   A 
A! A!c                     | |z   S )z%One dimensional Shift model function.rk   )rN   r   s     rB   rP   zShift.evaluateU  s     6zrD   c                     | S )z>Evaluate the implicit term (x) of one dimensional Shift model.rk   )rN   s    rB   sum_of_implicit_termszShift.sum_of_implicit_termsZ  s	     rD   c                 0    t          j        |           }|gS )zAOne dimensional Shift model derivative with respect to parameter.rL   	ones_like)rN   paramsd_offsets      rB   rV   zShift.fit_deriv_  s     <??zrD   c                 ,    d|| j         d                  iS )Nr   r   r^   r_   s      rB   rb   z%Shift._parameter_units_for_data_unitse      ,t|A788rD   N)rd   re   rf   rg   r   r   linear_has_inverse_bounding_boxri   r[   r   rj   rP   r   rV   rb   rk   rD   rB   r#   r#   /  s          Yq.HIIIFF $8 8 X8
   X    \   \   \
9 9 9 9 9rD   r#   c                       e Zd ZdZ edd          ZdZdZdZdZ	dZ
ed             Zed             Zed             Zed	             Zd
 ZdS )r    a  
    Multiply a model by a dimensionless factor.

    Parameters
    ----------
    factor : float
        Factor by which to scale a coordinate.

    Notes
    -----
    If ``factor`` is a `~astropy.units.Quantity` then the units will be
    stripped before the scaling operation.

    r   z Factor by which to scale a modelr4   Tc                 P    | j         j        d S | j        d         | j         j        iS rX   )r?   rY   rZ   rG   s    rB   r[   zScale.input_units  r   rD   c                                                        }d j        z  |_        	  j         t           fd j                                        D                       |_        n# t          $ r Y nw xY w|S )z-One dimensional inverse Scale model function.r   c              3   N   K   | ]}                     |j                  V   d S r   rP   r?   r   s     rB   r   z Scale.inverse.<locals>.<genexpr>  r   rD   r   r?   rC   r   r   r   s   ` rB   r   zScale.inverse       iikk_
	  % % % % %7;7H7U7U7W7W% % %    C # 	 	 	D	 
   A% %
A21A2c                 N    t          |t          j                  r|j        }|| z  S )z%One dimensional Scale model function.)
isinstancer   r   valuerN   r?   s     rB   rP   zScale.evaluate  s)     faj)) 	"\FzrD   c                     | }|gS )zAOne dimensional Scale model derivative with respect to parameter.rk   rN   r   d_factors      rB   rV   zScale.fit_deriv       zrD   c                 ,    d|| j         d                  iS Nr?   r   r   r_   s      rB   rb   z%Scale._parameter_units_for_data_units  r   rD   N)rd   re   rf   rg   r   r?   r   fittable_input_units_strict _input_units_allow_dimensionlessr   ri   r[   r   rj   rP   rV   rb   rk   rD   rB   r    r    i  s          Yq.PQQQFFH'+$ $8 8 X8
   X    \   \
9 9 9 9 9rD   r    c                       e Zd ZdZ edd          ZdZdZdZe	d             Z
ed             Zed             Zd	 Zd
S )r   z
    Multiply a model by a quantity or number.

    Parameters
    ----------
    factor : float
        Factor by which to multiply a coordinate.
    r   z#Factor by which to multiply a modelr4   Tc                                                        }d j        z  |_        	  j         t           fd j                                        D                       |_        n# t          $ r Y nw xY w|S )z0One dimensional inverse multiply model function.r   c              3   N   K   | ]}                     |j                  V   d S r   r   r   s     rB   r   z#Multiply.inverse.<locals>.<genexpr>  r   rD   r   r   s   ` rB   r   zMultiply.inverse  r   r   c                     || z  S )z(One dimensional multiply model function.rk   r   s     rB   rP   zMultiply.evaluate  s     zrD   c                     | }|gS )zDOne dimensional multiply model derivative with respect to parameter.rk   r   s      rB   rV   zMultiply.fit_deriv  r   rD   c                 ,    d|| j         d                  iS r   r   r_   s      rB   rb   z(Multiply._parameter_units_for_data_units  r   rD   N)rd   re   rf   rg   r   r?   r   r   r   ri   r   rj   rP   rV   rb   rk   rD   rB   r   r     s          Yq.STTTFFH $  X    \   \
9 9 9 9 9rD   r   c                   r    e Zd ZdZ edd          ZdZed             Zed             Z	e
d             Zd	S )
r   z
    One dimensional redshift scale factor model.

    Parameters
    ----------
    z : float
        Redshift value.

    Notes
    -----
    Model formula:

        .. math:: f(x) = x (1 + z)
    Redshiftr   )r6   r5   Tc                     d|z   | z  S )z3One dimensional RedshiftScaleFactor model function.r   rk   )rN   zs     rB   rP   zRedshiftScaleFactor.evaluate  s     A{rD   c                     | }|gS )z5One dimensional RedshiftScaleFactor model derivative.rk   )rN   r   d_zs      rB   rV   zRedshiftScaleFactor.fit_deriv  s     urD   c                                                        }dd j        z   z  dz
  |_        	  j         t           fd j                                        D                       |_        n# t          $ r Y nw xY w|S )z"Inverse RedshiftScaleFactor model.r   c              3   N   K   | ]}                     |j                  V   d S r   )rP   r   r   s     rB   r   z.RedshiftScaleFactor.inverse.<locals>.<genexpr>  sD       % %-.a((% % % % % %rD   )r   r   rC   r   r   r   s   ` rB   r   zRedshiftScaleFactor.inverse  s     iikksTV|$s*	  % % % % %262C2P2P2R2R% % %    C # 	 	 	D	 
s   A+ +
A87A8N)rd   re   rf   rg   r   r   r   rj   rP   rV   ri   r   rk   rD   rB   r   r     s          		j!444A $  \   \
   X  rD   r   c                       e Zd ZdZ edd          Z edd          Z edd          ZdZe	d	             Z
ed
             Zd ZdS )r!   a  
    One dimensional Sersic surface brightness profile.

    Parameters
    ----------
    amplitude : float
        Surface brightness at r_eff.
    r_eff : float
        Effective (half-light) radius
    n : float
        Sersic Index.

    See Also
    --------
    Gaussian1D, Moffat1D, Lorentz1D

    Notes
    -----
    Model formula:

    .. math::

        I(r)=I_e\exp\left\{-b_n\left[\left(\frac{r}{r_{e}}\right)^{(1/n)}-1\right]\right\}

    The constant :math:`b_n` is defined such that :math:`r_e` contains half the total
    luminosity, and can be solved for numerically.

    .. math::

        \Gamma(2n) = 2\gamma (b_n,2n)

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        from astropy.modeling.models import Sersic1D
        import matplotlib.pyplot as plt

        plt.figure()
        plt.subplot(111, xscale='log', yscale='log')
        s1 = Sersic1D(amplitude=1, r_eff=5)
        r=np.arange(0, 100, .01)

        for n in range(1, 10):
             s1.n = n
             plt.plot(r, s1(r), color=str(float(n) / 15))

        plt.axis([1e-1, 30, 1e-2, 1e3])
        plt.xlabel('log Radius')
        plt.ylabel('log Surface Brightness')
        plt.text(.25, 1.5, 'n=1')
        plt.text(.25, 300, 'n=10')
        plt.xticks([])
        plt.yticks([])
        plt.show()

    References
    ----------
    .. [1] http://ned.ipac.caltech.edu/level5/March05/Graham/Graham2.html
    r   Surface brightness at r_effr4   Effective (half-light) radius   Sersic IndexNc                     | j         ddlm} || _         |t          j        |                      d|z  d           ||z  d|z  z  dz
  z            z  S )z(One dimensional Sersic profile function.Nr   gammaincinvr1   r   r   )_gammaincinvscipy.specialr	  rL   rM   )clsrrO   r_effnr	  s         rB   rP   zSersic1D.evaluateQ  ss     #111111*C26a!eS)))a%iQU-Ca-GH
 
 
 	
rD   c                 P    | j         j        d S | j        d         | j         j        iS rX   )r  rY   rZ   rG   s    rB   r[   zSersic1D.input_units]  s(    : (4A
 566rD   c                 P    || j         d                  || j        d                  dS )Nr   )r  rO   r]   r_   s      rB   rb   z(Sersic1D._parameter_units_for_data_unitsc  s-     Q0%dl1o6
 
 	
rD   )rd   re   rf   rg   r   rO   r  r  r
  classmethodrP   ri   r[   rb   rk   rD   rB   r!   r!     s        = =~ 	!1NOOOIIa-LMMME	!888AL	
 	
 [	
 7 7 X7

 
 
 
 
rD   r!   c                   |    e Zd ZdZ edd          Z edd          Z edd          Zed             Z	d	 Z
d
S )_Trigonometric1Da  
    Base class for one dimensional trigonometric and inverse trigonometric models.

    Parameters
    ----------
    amplitude : float
        Oscillation amplitude
    frequency : float
        Oscillation frequency
    phase : float
        Oscillation phase
    r   zOscillation amplituder4   zOscillation frequencyr   zOscillation phasec                 V    | j         j        d S | j        d         d| j         j        z  iS )Nr   r   )	frequencyrY   rZ   rG   s    rB   r[   z_Trigonometric1D.input_units|  s-    >$,4Adn&? ?@@rD   c                 V    || j         d                  dz  || j        d                  dS Nr   r   )r  rO   r]   r_   s      rB   rb   z0_Trigonometric1D._parameter_units_for_data_units  s2    $T[^4:%dl1o6
 
 	
rD   N)rd   re   rf   rg   r   rO   r  phaseri   r[   rb   rk   rD   rB   r  r  j  s          	!1HIIII	!1HIIIIIa-@AAAEA A XA

 
 
 
 
rD   r  c                   T    e Zd ZdZed             Zed             Zed             ZdS )r$   al  
    One dimensional Sine model.

    Parameters
    ----------
    amplitude : float
        Oscillation amplitude
    frequency : float
        Oscillation frequency
    phase : float
        Oscillation phase

    See Also
    --------
    ArcSine1D, Cosine1D, Tangent1D, Const1D, Linear1D


    Notes
    -----
    Model formula:

        .. math:: f(x) = A \sin(2 \pi f x + 2 \pi p)

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import Sine1D

        plt.figure()
        s1 = Sine1D(amplitude=1, frequency=.25)
        r=np.arange(0, 10, .01)

        for amplitude in range(1,4):
             s1.amplitude = amplitude
             plt.plot(r, s1(r), color=str(0.25 * amplitude), lw=2)

        plt.axis([0, 10, -5, 5])
        plt.show()
    c                     t           || z  |z   z  }t          |t                    r|j        }|t	          j        |          z  S )z$One dimensional Sine model function.)TWOPIr   r   r   rL   r   rN   rO   r  r  arguments        rB   rP   zSine1D.evaluate  E     IME12h)) 	&~H26(++++rD   c                 :   t          j        t          |z  | z  t          |z  z             }t          | z  |z  t          j        t          |z  | z  t          |z  z             z  }t          |z  t          j        t          |z  | z  t          |z  z             z  }|||gS )z&One dimensional Sine model derivative.)rL   r   r  r   rN   rO   r  r  rS   d_frequencyd_phases          rB   rV   zSine1D.fit_deriv  s     fUY.2UU]BCCAI	!BF59+<q+@55=+P$Q$QQ 	 )#bfUY->-BUU]-R&S&SS['22rD   c                 D    t          | j        | j        | j                  S )z One dimensional inverse of Sine.rO   r  r  )r'   rO   r  r  rG   s    rB   r   zSine1D.inverse  (     ndj
 
 
 	
rD   N	rd   re   rf   rg   rj   rP   rV   ri   r   rk   rD   rB   r$   r$     p        + +Z 
, 
, \
, 3 3 \3 
 
 X
 
 
rD   r$   c                   T    e Zd ZdZed             Zed             Zed             ZdS )r%   ar  
    One dimensional Cosine model.

    Parameters
    ----------
    amplitude : float
        Oscillation amplitude
    frequency : float
        Oscillation frequency
    phase : float
        Oscillation phase

    See Also
    --------
    ArcCosine1D, Sine1D, Tangent1D, Const1D, Linear1D


    Notes
    -----
    Model formula:

        .. math:: f(x) = A \cos(2 \pi f x + 2 \pi p)

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import Cosine1D

        plt.figure()
        s1 = Cosine1D(amplitude=1, frequency=.25)
        r=np.arange(0, 10, .01)

        for amplitude in range(1,4):
             s1.amplitude = amplitude
             plt.plot(r, s1(r), color=str(0.25 * amplitude), lw=2)

        plt.axis([0, 10, -5, 5])
        plt.show()
    c                     t           || z  |z   z  }t          |t                    r|j        }|t	          j        |          z  S )z&One dimensional Cosine model function.)r  r   r   r   rL   r   r  s        rB   rP   zCosine1D.evaluate  r  rD   c                 >   t          j        t          |z  | z  t          |z  z             }t          | z  |z  t          j        t          |z  | z  t          |z  z             z   }t          |z  t          j        t          |z  | z  t          |z  z             z   }|||gS )z(One dimensional Cosine model derivative.)rL   r   r  r   r!  s          rB   rV   zCosine1D.fit_deriv  s     fUY.2UU]BCCAI	!BF59+<q+@55=+P$Q$QQ
 I%uy/@1/Duu}/T(U(UUV['22rD   c                 D    t          | j        | j        | j                  S )z"One dimensional inverse of Cosine.r%  )r(   rO   r  r  rG   s    rB   r   zCosine1D.inverse  s(     ndj
 
 
 	
rD   Nr'  rk   rD   rB   r%   r%     r(  rD   r%   c                   Z    e Zd ZdZed             Zed             Zed             Zd Z	dS )r&   a  
    One dimensional Tangent model.

    Parameters
    ----------
    amplitude : float
        Oscillation amplitude
    frequency : float
        Oscillation frequency
    phase : float
        Oscillation phase

    See Also
    --------
    Sine1D, Cosine1D, Const1D, Linear1D


    Notes
    -----
    Model formula:

        .. math:: f(x) = A \tan(2 \pi f x + 2 \pi p)

    Note that the tangent function is undefined for inputs of the form
    pi/2 + n*pi for all integers n. Thus thus the default bounding box
    has been restricted to:

        .. math:: [(-1/4 - p)/f, (1/4 - p)/f]

    which is the smallest interval for the tangent function to be continuous
    on.

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import Tangent1D

        plt.figure()
        s1 = Tangent1D(amplitude=1, frequency=.25)
        r=np.arange(0, 10, .01)

        for amplitude in range(1,4):
             s1.amplitude = amplitude
             plt.plot(r, s1(r), color=str(0.25 * amplitude), lw=2)

        plt.axis([0, 10, -5, 5])
        plt.show()
    c                     t           || z  |z   z  }t          |t                    r|j        }|t	          j        |          z  S )z'One dimensional Tangent model function.)r  r   r   r   rL   tanr  s        rB   rP   zTangent1D.evaluateZ  r  rD   c                     dt          j        t          |z  | z  t          |z  z             dz  z  }t          j        t          |z  | z  t          |z  z             }t          | z  |z  |z  }t          |z  |z  }|||gS )z)One dimensional Tangent model derivative.r   r1   )rL   r   r  r/  )rN   rO   r  r  secrS   r"  r#  s           rB   rV   zTangent1D.fit_derivg  s     26%)+a/%%-?@@QFFfUY.2UU]BCCai)+c1)#c)['22rD   c                 D    t          | j        | j        | j                  S )z#One dimensional inverse of Tangent.r%  )r)   rO   r  r  rG   s    rB   r   zTangent1D.inverseq  s(     ndj
 
 
 	
rD   c                     d| j         z
  | j        z  d| j         z
  | j        z  g}| j        j        || j        j        z  }|S )b
        Tuple defining the default ``bounding_box`` limits,
        ``(x_low, x_high)``.
        g      пg      ?)r  r  unit)r>   bboxs     rB   rC   zTangent1D.bounding_boxx  sN     dj DN2TZ4>1

 >*$.--DrD   N)
rd   re   rf   rg   rj   rP   rV   ri   r   rC   rk   rD   rB   r&   r&   #  s        4 4l 
, 
, \
, 3 3 \3 
 
 X
    rD   r&   c                   .    e Zd ZdZed             Zd ZdS )_InverseTrigonometric1DzF
    Base class for one dimensional inverse trigonometric models.
    c                 P    | j         j        d S | j        d         | j         j        iS rX   )rO   rY   rZ   rG   s    rB   r[   z#_InverseTrigonometric1D.input_units  s(    >$,4A 9::rD   c                 V    || j         d                  dz  || j        d                  dS r  r^   rZ   r_   s      rB   rb   z7_InverseTrigonometric1D._parameter_units_for_data_units  s2    %dl1o6"<$T[^4
 
 	
rD   N)rd   re   rf   rg   ri   r[   rb   rk   rD   rB   r8  r8    sH          ; ; X;

 
 
 
 
rD   r8  c                   Z    e Zd ZdZed             Zed             Zd Zed             Z	dS )r'   aR  
    One dimensional ArcSine model returning values between -pi/2 and pi/2
    only.

    Parameters
    ----------
    amplitude : float
        Oscillation amplitude for corresponding Sine
    frequency : float
        Oscillation frequency for corresponding Sine
    phase : float
        Oscillation phase for corresponding Sine

    See Also
    --------
    Sine1D, ArcCosine1D, ArcTangent1D


    Notes
    -----
    Model formula:

        .. math:: f(x) = ((arcsin(x / A) / 2pi) - p) / f

    The arcsin function being used for this model will only accept inputs
    in [-A, A]; otherwise, a runtime warning will be thrown and the result
    will be NaN. To avoid this, the bounding_box has been properly set to
    accommodate this; therefore, it is recommended that this model always
    be evaluated with the ``with_bounding_box=True`` option.

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import ArcSine1D

        plt.figure()
        s1 = ArcSine1D(amplitude=1, frequency=.25)
        r=np.arange(-1, 1, .01)

        for amplitude in range(1,4):
             s1.amplitude = amplitude
             plt.plot(r, s1(r), color=str(0.25 * amplitude), lw=2)

        plt.axis([-1, 1, -np.pi/2, np.pi/2])
        plt.show()
    c                     | |z  }t          |t                    r|j        }t          j        |          t
          z  }||z
  |z  S )z'One dimensional ArcSine model function.)r   r   r   rL   arcsinr  )rN   rO   r  r  r  arc_sines         rB   rP   zArcSine1D.evaluate  sJ     y=h)) 	&~H9X&&.5 I--rD   c                     |  t           |z  |dz  z  t          j        d| |z  dz  z
            z  z  }|t          j        | |z            t           z  z
  |dz  z  }d|z  t          j        | j                  z  }|||gS )z)One dimensional ArcSine model derivative.r1   r   r   )r  rL   rz   r>  onesrv   r!  s          rB   rV   zArcSine1D.fit_deriv  s     bI	1,rwqA	Ma;O7O/P/PP
 	!i- 8 85 @AYPQ\Qy.2717#3#33['22rD   c                 *    d| j         z  d| j         z  fS r4  r   r   rO   rG   s    rB   rC   zArcSine1D.bounding_box      
 DN"A$666rD   c                 D    t          | j        | j        | j                  S )z#One dimensional inverse of ArcSine.r%  )r$   rO   r  r  rG   s    rB   r   zArcSine1D.inverse  s(     ndj
 
 
 	
rD   N
rd   re   rf   rg   rj   rP   rV   rC   ri   r   rk   rD   rB   r'   r'     s        2 2h . . \. 3 3 \37 7 7 
 
 X
 
 
rD   r'   c                   Z    e Zd ZdZed             Zed             Zd Zed             Z	dS )r(   aF  
    One dimensional ArcCosine returning values between 0 and pi only.


    Parameters
    ----------
    amplitude : float
        Oscillation amplitude for corresponding Cosine
    frequency : float
        Oscillation frequency for corresponding Cosine
    phase : float
        Oscillation phase for corresponding Cosine

    See Also
    --------
    Cosine1D, ArcSine1D, ArcTangent1D


    Notes
    -----
    Model formula:

        .. math:: f(x) = ((arccos(x / A) / 2pi) - p) / f

    The arccos function being used for this model will only accept inputs
    in [-A, A]; otherwise, a runtime warning will be thrown and the result
    will be NaN. To avoid this, the bounding_box has been properly set to
    accommodate this; therefore, it is recommended that this model always
    be evaluated with the ``with_bounding_box=True`` option.

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import ArcCosine1D

        plt.figure()
        s1 = ArcCosine1D(amplitude=1, frequency=.25)
        r=np.arange(-1, 1, .01)

        for amplitude in range(1,4):
             s1.amplitude = amplitude
             plt.plot(r, s1(r), color=str(0.25 * amplitude), lw=2)

        plt.axis([-1, 1, 0, np.pi])
        plt.show()
    c                     | |z  }t          |t                    r|j        }t          j        |          t
          z  }||z
  |z  S )z)One dimensional ArcCosine model function.)r   r   r   rL   arccosr  rN   rO   r  r  r  arc_coss         rB   rP   zArcCosine1D.evaluate-  I     y=h)) 	&~H)H%%-%9,,rD   c                     | t           |z  |dz  z  t          j        d| |z  dz  z
            z  z  }|t          j        | |z            t           z  z
  |dz  z  }d|z  t          j        | j                  z  }|||gS )z+One dimensional ArcCosine model derivative.r1   r   r   )r  rL   rz   rJ  rA  rv   r!  s          rB   rV   zArcCosine1D.fit_deriv=  s     I	1,rwqA	Ma;O7O/P/PP
 	!i- 8 85 @AYPQ\Qy.2717#3#33['22rD   c                 *    d| j         z  d| j         z  fS rC  rD  rG   s    rB   rC   zArcCosine1D.bounding_boxG  rE  rD   c                 D    t          | j        | j        | j                  S )z%One dimensional inverse of ArcCosine.r%  )r%   rO   r  r  rG   s    rB   r   zArcCosine1D.inverseN  s(     ndj
 
 
 	
rD   NrG  rk   rD   rB   r(   r(     s        2 2h - - \- 3 3 \37 7 7 
 
 X
 
 
rD   r(   c                   T    e Zd ZdZed             Zed             Zed             ZdS )r)   a  
    One dimensional ArcTangent model returning values between -pi/2 and
    pi/2 only.

    Parameters
    ----------
    amplitude : float
        Oscillation amplitude for corresponding Tangent
    frequency : float
        Oscillation frequency for corresponding Tangent
    phase : float
        Oscillation phase for corresponding Tangent

    See Also
    --------
    Tangent1D, ArcSine1D, ArcCosine1D


    Notes
    -----
    Model formula:

        .. math:: f(x) = ((arctan(x / A) / 2pi) - p) / f

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import ArcTangent1D

        plt.figure()
        s1 = ArcTangent1D(amplitude=1, frequency=.25)
        r=np.arange(-10, 10, .01)

        for amplitude in range(1,4):
             s1.amplitude = amplitude
             plt.plot(r, s1(r), color=str(0.25 * amplitude), lw=2)

        plt.axis([-10, 10, -np.pi/2, np.pi/2])
        plt.show()
    c                     | |z  }t          |t                    r|j        }t          j        |          t
          z  }||z
  |z  S )z*One dimensional ArcTangent model function.)r   r   r   rL   arctanr  rK  s         rB   rP   zArcTangent1D.evaluate  rM  rD   c                     |  t           |z  |dz  z  d| |z  dz  z   z  z  }|t          j        | |z            t           z  z
  |dz  z  }d|z  t          j        | j                  z  }|||gS )z,One dimensional ArcTangent model derivative.r1   r   r   )r  rL   rS  rA  rv   r!  s          rB   rV   zArcTangent1D.fit_deriv  s     bI	1,Q]q4H0HI
 	!i- 8 85 @AYPQ\Qy.2717#3#33['22rD   c                 D    t          | j        | j        | j                  S )z&One dimensional inverse of ArcTangent.r%  )r&   rO   r  r  rG   s    rB   r   zArcTangent1D.inverse  r&  rD   Nr'  rk   rD   rB   r)   r)   V  sp        , ,\ - - \- 3 3 \3 
 
 X
 
 
rD   r)   c                       e Zd ZdZ edd          Z edd          ZdZed             Z	ed	             Z
ed
             Zed             Zd ZdS )r   a(  
    One dimensional Line model.

    Parameters
    ----------
    slope : float
        Slope of the straight line

    intercept : float
        Intercept of the straight line

    See Also
    --------
    Const1D

    Notes
    -----
    Model formula:

        .. math:: f(x) = a x + b
    r   zSlope of the straight liner4   r   zIntercept of the straight lineTc                     || z  |z   S )z$One dimensional Line model function.rk   )rN   slope	intercepts      rB   rP   zLinear1D.evaluate  s     qy9$$rD   c                 6    | }t          j        |           }||gS )zAOne dimensional Line model derivative with respect to parameters.r   )rN   r   d_sloped_intercepts       rB   rV   zLinear1D.fit_deriv  s!     l1oo%%rD   c                 d    | j         dz  }| j         | j         z  }|                     ||          S )Nr   )rX  rY  )rX  rY  rt   )r>   	new_slopenew_intercepts      rB   r   zLinear1D.inverse  s3    JN	$*4~~I~GGGrD   c                     | j         j        | j        j        d S | j        d         | j         j        | j        j        z  iS rX   )rY  rY   rX  rZ   rG   s    rB   r[   zLinear1D.input_units  s<    >$,1F1N4A 9DJ<Q QRRrD   c                 x    || j         d                  || j         d                  || j        d                  z  dS )Nr   )rY  rX  r;  r_   s      rB   rb   z(Linear1D._parameter_units_for_data_units  s=    %dl1o6!$,q/2[Q5PP
 
 	
rD   N)rd   re   rf   rg   r   rX  rY  r   rj   rP   rV   ri   r   r[   rb   rk   rD   rB   r   r     s         , Ia-IJJJE	!1QRRRIF% % \% & & \& H H XH
 S S XS

 
 
 
 
rD   r   c                       e Zd ZdZ edd          Z edd          Z edd          ZdZe	d	             Z
e	d
             Zd ZdS )r   a9  
    Two dimensional Plane model.

    Parameters
    ----------
    slope_x : float
        Slope of the plane in X

    slope_y : float
        Slope of the plane in Y

    intercept : float
        Z-intercept of the plane

    Notes
    -----
    Model formula:

        .. math:: f(x, y) = a x + b y + c
    r   zSlope of the plane in Xr4   zSlope of the plane in Yr   zZ-intercept of the planeTc                     || z  ||z  z   |z   S )z%Two dimensional Plane model function.rk   )rN   r   slope_xslope_yrY  s        rB   rP   zPlanar2D.evaluate  s     {Wq[(944rD   c                 <    | }|}t          j        |           }|||gS )zBTwo dimensional Plane model derivative with respect to parameters.r   )rN   r   r   	d_slope_x	d_slope_yr\  s         rB   rV   zPlanar2D.fit_deriv  s(     		l1oo9k22rD   c                 V    |d         |d         |d         z  |d         |d         z  dS )Nr   rN   r   )rY  rd  re  rk   r_   s      rB   rb   z(Planar2D._parameter_units_for_data_units	  s=    %c*#C(;s+;;#C(;s+;;
 
 	
rD   N)rd   re   rf   rg   r   rd  re  rY  r   rj   rP   rV   rb   rk   rD   rB   r   r     s         * i/HIIIGi/HIIIG	!1KLLLIF5 5 \5 3 3 \3
 
 
 
 
rD   r   c                       e Zd ZdZ edd          Z edd          Z edd          Zed             Z	ed	             Z
ddZed             Zd ZdS )r   a  
    One dimensional Lorentzian model.

    Parameters
    ----------
    amplitude : float or `~astropy.units.Quantity`.
        Peak value - for a normalized profile (integrating to 1),
        set amplitude = 2 / (np.pi * fwhm)
    x_0 : float or `~astropy.units.Quantity`.
        Position of the peak
    fwhm : float or `~astropy.units.Quantity`.
        Full width at half maximum (FWHM)

    See Also
    --------
    Gaussian1D, Box1D, RickerWavelet1D

    Notes
    -----
    Either all or none of input ``x``, position ``x_0`` and ``fwhm`` must be provided
    consistently with compatible units or as unitless numbers.

    Model formula:

    .. math::

        f(x) = \frac{A \gamma^{2}}{\gamma^{2} + \left(x - x_{0}\right)^{2}}

    where :math:`\gamma` is half of given FWHM.

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import Lorentz1D

        plt.figure()
        s1 = Lorentz1D()
        r = np.arange(-5, 5, .01)

        for factor in range(1, 4):
            s1.amplitude = factor
            plt.plot(r, s1(r), color=str(0.25 * factor), lw=2)

        plt.axis([-5, 5, -1, 4])
        plt.show()
    r   z
Peak valuer4   r   Position of the peakzFull width at half maximumc                 <    ||dz  dz  z  | |z
  dz  |dz  dz  z   z  S )z*One dimensional Lorentzian model function.r2   r1   rk   )rN   rO   x_0rH   s       rB   rP   zLorentz1D.evaluateJ  s4     TCZA-.1s7q.D3JSTCT2TUUrD   c                     |dz  |dz  | |z
  dz  z   z  }||z  d| z  d|z  z
  z  |dz  | |z
  dz  z   z  }d|z  |z  |z  d|z
  z  }|||gS )zGOne dimensional Lorentzian model derivative with respect to parameters.r1   r   rk   )rN   rO   rm  rH   rS   d_x_0d_fwhms          rB   rV   zLorentz1D.fit_derivO  s     AgqAG>!9:#q1uq3w747a#gRS^;ST 	 Y,t3q;GUF++rD      c                 8    | j         }|| j        z  }||z
  ||z   fS )ar  Tuple defining the default ``bounding_box`` limits,
        ``(x_low, x_high)``.

        Parameters
        ----------
        factor : float
            The multiple of FWHM used to define the limits.
            Default is chosen to include most (99%) of the
            area under the curve, while still showing the
            central feature of interest.

        )rm  rH   r=   s       rB   rC   zLorentz1D.bounding_boxY  s*     XdiRb!!rD   c                 P    | j         j        d S | j        d         | j         j        iS rX   rm  rY   rZ   rG   s    rB   r[   zLorentz1D.input_unitsk  (    8&4A 344rD   c                 t    || j         d                  || j         d                  || j        d                  dS )Nr   )rm  rH   rO   r]   r_   s      rB   rb   z)Lorentz1D._parameter_units_for_data_unitsq  s;    t{1~.A/%dl1o6
 
 	
rD   N)rq  )rd   re   rf   rg   r   rO   rm  rH   rj   rP   rV   rC   ri   r[   rb   rk   rD   rB   r   r     s        2 2h 	!>>>I
)A+A
B
B
BC9Q,HIIIDV V \V , , \," " " "$ 5 5 X5

 
 
 
 
rD   r   c                   .    e Zd ZdZ edd          Z edd          Z edej        z  d          Z	 e ej
        d          d	          Z ej        ej                  Z ej         ej
        d                    Z ej         ej
        d          ej        z            Z ej        de
          Z ej        de
          ZdZej        ej        e	j        ej        df fd	Zd Zd Zd Zed             Zd Zedd            Z xZ S )r-   a  
    One dimensional model for the Voigt profile.

    Parameters
    ----------
    x_0 : float or `~astropy.units.Quantity`
        Position of the peak
    amplitude_L : float or `~astropy.units.Quantity`.
        The Lorentzian amplitude (peak of the associated Lorentz function)
        - for a normalized profile (integrating to 1), set
        amplitude_L = 2 / (np.pi * fwhm_L)
    fwhm_L : float or `~astropy.units.Quantity`
        The Lorentzian full width at half maximum
    fwhm_G : float or `~astropy.units.Quantity`.
        The Gaussian full width at half maximum
    method : str, optional
        Algorithm for computing the complex error function; one of
        'Humlicek2' (default, fast and generally more accurate than ``rtol=3.e-5``) or
        'Scipy', alternatively 'wofz' (requires ``scipy``, almost as fast and
        reference in accuracy).

    See Also
    --------
    Gaussian1D, Lorentz1D

    Notes
    -----
    Either all or none of input ``x``, position ``x_0`` and the ``fwhm_*`` must be provided
    consistently with compatible units or as unitless numbers.
    Voigt function is calculated as real part of the complex error function computed from either
    Humlicek's rational approximations (JQSRT 21:309, 1979; 27:437, 1982) following
    Schreier 2018 (MNRAS 479, 3068; and ``hum2zpf16m`` from his cpfX.py module); or
    `~scipy.special.wofz` (implementing 'Faddeeva.cc').

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        from astropy.modeling.models import Voigt1D
        import matplotlib.pyplot as plt

        plt.figure()
        x = np.arange(0, 10, 0.01)
        v1 = Voigt1D(x_0=5, amplitude_L=10, fwhm_L=0.5, fwhm_G=0.9)
        plt.plot(x, v1(x))
        plt.show()
    r   rk  r4   r   zThe Lorentzian amplituder1   z)The Lorentzian full width at half maximumz'The Gaussian full width at half maximum)dtypeNc                     t          |                                          dk    r$t          rt          j        | dt
                     |t          rd}nd}t          |                                          dv rddlm} || _        nEt          |                                          dk    r| j	        | _        nt          d| d          | j        j        | _         t                      j        d
||||d	| d S )N	humlicek2z has been deprecated since Astropy 5.3 and will be removed in a future version.
It is recommended to always use the `~scipy.special.wofz` implementation when `scipy` is installed.wofz)r{  scipyr   )r{  z2Not a valid method for Voigt1D Faddeeva function: .)rm  amplitude_Lfwhm_Lfwhm_Grk   )strlowerr   warningswarnr   r  r{  	_faddeeva_hum2zpf16crw   rd   methodr}   r~   )	r>   rm  r~  r  r  r  r   r{  rt   s	           rB   r~   zVoigt1D.__init__  s=    v;;+--)-M - - - *	   > %$v;;"333******!DNN[[  K//!-DNNNVNNN   n- 	
VF	
 	
NT	
 	
 	
 	
 	
rD   c                 @   |j         | j        j         k    r$t          j        || j        dd          r| j        S t          |t          j                  r|                    t          j	                  n|| _        | 
                    | j                  | _        | j        S )zCall complex error (Faddeeva) function w(z) implemented by algorithm `method`;
        cache results for consecutive calls from `evaluate`, `fit_deriv`.
        g+=gV瞯<)rtolatol)rv   _last_zrL   allclose_last_wr   r   r   to_valuedimensionless_unscaledr  )r>   r   s     rB   
_wrap_wofzzVoigt1D._wrap_wofz  s     7dl(((R[t|'.
 .
 .
( < 5?q!*4M4MTAJJq/000ST 	 ~~dl33|rD   c                     t          j        d||z
  z  d|z  z             | j        z  |z  }|                     |          j        | j        z  |z  |z  |z  S )z@One dimensional Voigt function scaled to Lorentz peak amplitude.r1                 ?)rL   
atleast_1dsqrt_ln2r  real
sqrt_ln2pi)r>   rN   rm  r~  r  r  r   s          rB   rP   zVoigt1D.evaluate  s[    M!q3w-"v+566FO q!!&86AFJ[XXrD   c                 z   | j         |z  }t          j        d||z
  z  d|z  z             |z  }|                     |          |z  |z  |z  | j        z  }d|z  |z  d|z  |z  |z  z   }	|	j         dz  |z  |j        |z  |j        |z  |	j        |z  z
  |j         |d||z
  z  |	j        z  ||	j        z  z
  z  z
  |z  gS )z^
        Derivative of the one dimensional Voigt function with respect to parameters.
        r1   r  y               @)r  rL   r  r  sqrt_pir  imag)
r>   rN   rm  r~  r  r  sr   wdwdzs
             rB   rV   zVoigt1D.fit_deriv  s     MF"M!q3w-"v+566:OOA"V+k9DLH AvzBFVOk99 YJNQF[ FVOdi!m+fWqASMDI58JJKKvU	
 	
rD   c                 P    | j         j        d S | j        d         | j         j        iS rX   rt  rG   s    rB   r[   zVoigt1D.input_units  ru  rD   c                     || j         d                  || j         d                  || j         d                  || j        d                  dS )Nr   )rm  r  r  r~  r]   r_   s      rB   rb   z'Voigt1D._parameter_units_for_data_units  sI    t{1~.!$+a.1!$+a.1'Q8	
 
 	
rD         $@c                    t          j        g d          }t          j        g d          }dt          j        t           j                  z  }| | z  }d| ||z  dz
  z  z  d||dz
  z  z   z  }t          j        | j        |k               rvt          | j                  | j        z   |k     }| t          j        |                   dz   }||z  }	|d	         |z  |d
         z   |z  |d         z   |z  |d         z   |z  |d         z   |z  |d         z   |z  |d         z   |z  |d         z   |z  |d         z   |z  |d         z   |z  |d         z   |z  |d         z   |z  |d         z   |z  |d         z   |z  |d         z   |z  |d         z   }
|	|d         z   |	z  |d         z   |	z  |d         z   |	z  |d         z   |	z  |d         z   |	z  |d         z   |	z  |d         z   |	z  |d         z   }t          j	        |||
|z             |S )a  Complex error function w(z = x + iy) combining Humlicek's rational approximations.

        |x| + y > 10:  Humlicek (JQSRT, 1982) rational approximation for region II;
        else:          Humlicek (JQSRT, 1979) rational approximation with n=16 and delta=y0=1.35

        Version using a mask and np.place;
        single complex argument version of Franz Schreier's cpfX.hum2zpf16m.
        Originally licensed under a 3-clause BSD style license - see
        https://atmos.eoc.dlr.de/tools/lbl4IR/cpfX.py
        )gO@y       tgˤo7	y        pd,Ag"YYAy       gi"U&y        mA6@gGb@y       {3qglL}`sy        p@g:@qF@y       JJe{LAgE|_y        BP?)	g@g    g   @
Ag    2g    @g    Sg     T@g      Nr   r   r  g]/M?g      ?g      @y        ?               
   	               r  rR   r1   r   r   )
rL   ru   rz   pianyr  absr  whereplace)r   r  AAbb
sqrt_piinvzzr  maskZZZnumerdenoms               rB   r  zVoigt1D._hum2zpf16c  s    X	 	 	
 
 X
 
 

 
 2725>>)
U!rJ123tbBHo7MN6!&1* 	-qv;;'!+D "(4..!E)AQB $&b6!8bf#4a"7"R&"@!!Cbf!La ORTUWRX XZ[[!"v &'()+-a5123468e<=>?ACAGHIJLNqERSTUQ% !"#%'U+,-..0e45679;A?@ABDFqEJKLMOQRSuUE 1:r/BqE1251=rA"Q%GKbQReSUWWe "$Q%()+,.0e4E HQeem,,,rD   r  )!rd   re   rf   rg   r   rm  r~  rL   r  r  logr  rz   r  r  r  zeroscomplexr  floatr  r  r5   r~   r  rP   rV   ri   r[   rb   rj   r  r   r   s   @rB   r-   r-   y  s       0 0d )A+A
B
B
BC)A3MNNNKYBE	'R  F Yq		'P  F bgbennGrwvrvayy!!HRU*++Jbhq(((Gbhq&&&GI K'~~%
 %
 %
 %
 %
 %
N   Y Y Y
 
 
& 5 5 X5

 
 
 J J J \J J J J JrD   r-   c                   z    e Zd ZdZ eddd          ZdZed             Zed             Z	e
d             Zd	 Zd
S )r   a  
    One dimensional Constant model.

    Parameters
    ----------
    amplitude : float
        Value of the constant function

    See Also
    --------
    Const2D

    Notes
    -----
    Model formula:

        .. math:: f(x) = A

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import Const1D

        plt.figure()
        s1 = Const1D()
        r = np.arange(-5, 5, .01)

        for factor in range(1, 4):
            s1.amplitude = factor
            plt.plot(r, s1(r), color=str(0.25 * factor), lw=2)

        plt.axis([-5, 5, -1, 4])
        plt.show()
    r   Value of the constant functionTr5   r6   magc                 :   |j         dk    rIt          j        || j        | j                  } |                     |                                           n|t          j        | d          z  } t          |t                    rt          | |j
        dd          S | S )z(One dimensional Constant model function.r   rv   rx  FsubokTr5  r   r  sizerL   
empty_likerv   rx  fillitemr   r   r   r5  )rN   rO   s     rB   rP   zConst1D.evaluate       >QiqwagFFFAFF9>>##$$$$ BL%8888Ai** 	LAINdKKKKrD   c                 0    t          j        |           }|gS )zEOne dimensional Constant model derivative with respect to parameters.r   )rN   rO   rS   s      rB   rV   zConst1D.fit_deriv  s     l1oo}rD   c                     d S r   rk   rG   s    rB   r[   zConst1D.input_units      trD   c                 ,    d|| j         d                  iS NrO   r   r   r_   s      rB   rb   z'Const1D._parameter_units_for_data_units      \$,q/:;;rD   N)rd   re   rf   rg   r   rO   r   rj   rP   rV   ri   r[   rb   rk   rD   rB   r   r   i  s        & &P 	?T  I F  \   \
   X< < < < <rD   r   c                   d    e Zd ZdZ eddd          ZdZed             Ze	d             Z
d Zd	S )
r   z
    Two dimensional Constant model.

    Parameters
    ----------
    amplitude : float
        Value of the constant function

    See Also
    --------
    Const1D

    Notes
    -----
    Model formula:

        .. math:: f(x, y) = A
    r   r  Tr  c                 :   |j         dk    rIt          j        || j        | j                  } |                     |                                           n|t          j        | d          z  } t          |t                    rt          | |j
        dd          S | S )z(Two dimensional Constant model function.r   r  Fr  Tr  r  )rN   r   rO   s      rB   rP   zConst2D.evaluate  r  rD   c                     d S r   rk   rG   s    rB   r[   zConst2D.input_units  r  rD   c                 ,    d|| j         d                  iS r  r   r_   s      rB   rb   z'Const2D._parameter_units_for_data_units  r  rD   N)rd   re   rf   rg   r   rO   r   rj   rP   ri   r[   rb   rk   rD   rB   r   r     s         & 	?T  I F  \   X< < < < <rD   r   c                       e Zd ZdZ eddd          Z edd          Z edd	          Z edd
          Z edd          Z	 edd          Z
ed             Zed             Zed             Zd ZdS )r   a  
    A 2D Ellipse model.

    Parameters
    ----------
    amplitude : float
        Value of the ellipse.

    x_0 : float
        x position of the center of the disk.

    y_0 : float
        y position of the center of the disk.

    a : float
        The length of the semimajor axis.

    b : float
        The length of the semiminor axis.

    theta : float or `~astropy.units.Quantity`, optional
        The rotation angle as an angular quantity
        (`~astropy.units.Quantity` or `~astropy.coordinates.Angle`)
        or a value in radians (as a float). The rotation angle
        increases counterclockwise from the positive x axis.

    See Also
    --------
    Disk2D, Box2D

    Notes
    -----
    Model formula:

    .. math::

        f(x, y) = \left \{
                    \begin{array}{ll}
                      \mathrm{amplitude} & : \left[\frac{(x - x_0) \cos
                        \theta + (y - y_0) \sin \theta}{a}\right]^2 +
                        \left[\frac{-(x - x_0) \sin \theta + (y - y_0)
                        \cos \theta}{b}\right]^2  \leq 1 \\
                      0 & : \mathrm{otherwise}
                    \end{array}
                  \right.

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        from astropy.modeling.models import Ellipse2D
        from astropy.coordinates import Angle
        import matplotlib.pyplot as plt
        import matplotlib.patches as mpatches
        x0, y0 = 25, 25
        a, b = 20, 10
        theta = Angle(30, 'deg')
        e = Ellipse2D(amplitude=100., x_0=x0, y_0=y0, a=a, b=b,
                      theta=theta.radian)
        y, x = np.mgrid[0:50, 0:50]
        fig, ax = plt.subplots(1, 1)
        ax.imshow(e(x, y), origin='lower', interpolation='none', cmap='Greys_r')
        e2 = mpatches.Ellipse((x0, y0), 2*a, 2*b, angle=theta.degree, edgecolor='red',
                              facecolor='none')
        ax.add_patch(e2)
        plt.show()
    r   zValue of the ellipseTr  r   z%X position of the center of the disk.r4   z%Y position of the center of the disk.z The length of the semimajor axisz The length of the semiminor axisrm   CRotation angle either as a float (in radians) or a |Quantity| anglec                 J   | |z
  }||z
  }	t          j        |          }
t          j        |          }||
z  |	|z  z   }||z   |	|
z  z   }||z  dz  ||z  dz  z   dk    }t          j        |g|g          }t	          |t
                    rt          ||j        dd          S |S )z'Two dimensional Ellipse model function.r1   r   FTr  )rL   r   r   selectr   r   r5  )rN   r   rO   rm  y_0r   r   rs   xxyyr   r   
numerator1
numerator2
in_ellipseresults                   rB   rP   zEllipse2D.evaluate9  s     WWve}}ve}}4iBI.
Dy\R$Y/
!A~!+zA~!.CCK
J<)55i** 	QFe4PPPPrD   c                     | j         }| j        }| j        }t          |||          \  }}| j        |z
  | j        |z   f| j        |z
  | j        |z   ffS zu
        Tuple defining the default ``bounding_box`` limits.

        ``((y_low, y_high), (x_low, x_high))``
        )r   r   rs   r   r  rm  )r>   r   r   rs   rA   r   s         rB   rC   zEllipse2D.bounding_boxI  s[     FF
1e,,BB2.B20NOOrD   c                 ~    | j         j        d S | j        d         | j         j        | j        d         | j        j        iS r   rm  rY   rZ   r  rG   s    rB   r[   zEllipse2D.input_unitsW  <    8&4KNDH/KNDH/
 	
rD   c                 @   || j         d                  || j         d                  k    rt          d          || j         d                  || j         d                  || j         d                  || j         d                  t          j        || j        d                  dS )Nr   r   r   )rm  r  r   r   rs   rO   r   r_   s      rB   rb   z)Ellipse2D._parameter_units_for_data_units`  s     t{1~&+dk!n*EEEGHHHt{1~.t{1~.T[^,T[^,U%dl1o6
 
 	
rD   N)rd   re   rf   rg   r   rO   rm  r  r   r   rs   rj   rP   ri   rC   r[   rb   rk   rD   rB   r   r     s       D DL 	!1GTRRRI
)A+R
S
S
SC
)A+R
S
S
SC	!)KLLLA	!)KLLLAIQ  E   \ P P XP 
 
 X

 
 
 
 
rD   r   c                       e Zd ZdZ eddd          Z edd          Z edd	          Z edd
          Ze	d             Z
ed             Zed             Zd ZdS )r   af  
    Two dimensional radial symmetric Disk model.

    Parameters
    ----------
    amplitude : float
        Value of the disk function
    x_0 : float
        x position center of the disk
    y_0 : float
        y position center of the disk
    R_0 : float
        Radius of the disk

    See Also
    --------
    Box2D, TrapezoidDisk2D

    Notes
    -----
    Model formula:

        .. math::

            f(r) = \left \{
                     \begin{array}{ll}
                       A & : r \leq R_0 \\
                       0 & : r > R_0
                     \end{array}
                   \right.
    r   zValue of disk functionTr  r   z X position of center of the diskr4   z Y position of center of the diskzRadius of the diskc                     | |z
  dz  ||z
  dz  z   }t          j        ||dz  k    g|g          }t          |t                    rt          ||j        dd          S |S )z$Two dimensional Disk model function.r1   FTr  )rL   r  r   r   r5  )rN   r   rO   rm  r  R_0rrr  s           rB   rP   zDisk2D.evaluate  sl     #g!^q3w1n,B#q&L>I;77i** 	QFe4PPPPrD   c                 z    | j         | j        z
  | j         | j        z   f| j        | j        z
  | j        | j        z   ffS r  )r  r  rm  rG   s    rB   rC   zDisk2D.bounding_box  sB     X $(TX"56X $(TX"56
 	
rD   c                 v    | j         j        }| j        j        }||d S | j        d         || j        d         |iS r   rm  rY   r  rZ   r   s      rB   r[   zDisk2D.input_units  s?    $$>fn4AA??rD   c                    || j         d                  || j         d                  k    rt          d          || j         d                  || j         d                  || j         d                  || j        d                  dS )Nr   r   r   )rm  r  r  rO   rZ   r   r^   r_   s      rB   rb   z&Disk2D._parameter_units_for_data_units  s{     t{1~&+dk!n*EEEGHHHt{1~.t{1~.t{1~.%dl1o6	
 
 	
rD   N)rd   re   rf   rg   r   rO   rm  r  r  rj   rP   ri   rC   r[   rb   rk   rD   rB   r   r   p  s         @ 	!1ItTTTI
)A+M
N
N
NC
)A+M
N
N
NC
)A+?
@
@
@C  \ 	
 	
 X	
 @ @ X@
 
 
 
 
rD   r   c                       e Zd ZdZ eddd          Z edd          Z edd	          Z edd
          Z edd          Z	ej
        ej
        ej
        dddf fd	Zed             Zed             Zed             Zd Z xZS )r,   a7  
    Two dimensional radial symmetric Ring model.

    Parameters
    ----------
    amplitude : float
        Value of the disk function
    x_0 : float
        x position center of the disk
    y_0 : float
        y position center of the disk
    r_in : float
        Inner radius of the ring
    width : float
        Width of the ring.
    r_out : float
        Outer Radius of the ring. Can be specified instead of width.

    See Also
    --------
    Disk2D, TrapezoidDisk2D

    Notes
    -----
    Model formula:

        .. math::

            f(r) = \left \{
                     \begin{array}{ll}
                       A & : r_{in} \leq r \leq r_{out} \\
                       0 & : \text{else}
                     \end{array}
                   \right.

    Where :math:`r_{out} = r_{in} + r_{width}`.
    r   zValue of the disk functionTr  r   zX position of center of discr4   zY position of center of disczInner radius of the ringzWidth of the ringNc           	         |||| j         j        }| j        j        }n|||| j        j        }ns|||| j         j        }||z
  }n[|||| j         j        }nH|
||||z
  }n<|
||||z
  }n0|.|,|*t          j        |||z
  k              rt          d          t          j        |dk               st          j        |dk               rt          d|d|d           t                      j        d|||||d| d S )NzWidth must be r_out - r_inr   zr_in=z and width=z must both be >=0)rO   rm  r  r_inwidthrk   )r  r5   r  rL   r  r   r}   r~   )	r>   rO   rm  r  r  r  r_outr   rt   s	           rB   r~   zRing2D.__init__  s    Lu}5=9$DJ&EEU]J&EEl!29$DDLEElU5F9$DDU%6U]DLEEl!29J5=DDU%6U=Nve-.. H)*FGGG6$( 	Prveai00 	P%&N&N&NU&N&N&NOOO 	
ScE	
 	
MS	
 	
 	
 	
 	
rD   c                     | |z
  dz  ||z
  dz  z   }t          j        ||dz  k    |||z   dz  k              }t          j        |g|g          }	t          |t                    rt	          |	|j        dd          S |	S )z$Two dimensional Ring model function.r1   FTr  rL   logical_andr  r   r   r5  )
rN   r   rO   rm  r  r  r  r  r_ranger  s
             rB   rP   zRing2D.evaluate	  s     #g!^q3w1n,.tQwte|6I0IJJG9yk22i** 	QFe4PPPPrD   c                 p    | j         | j        z   }| j        |z
  | j        |z   f| j        |z
  | j        |z   ffS n
        Tuple defining the default ``bounding_box``.

        ``((y_low, y_high), (x_low, x_high))``
        )r  r  r  rm  r>   drs     rB   rC   zRing2D.bounding_box	  s?     Y#B2.B20NOOrD   c                 ~    | j         j        d S | j        d         | j         j        | j        d         | j        j        iS r   r  rG   s    rB   r[   zRing2D.input_units)	  r  rD   c                 *   || j         d                  || j         d                  k    rt          d          || j         d                  || j         d                  || j         d                  || j         d                  || j        d                  dS )Nr   r   r   )rm  r  r  r  rO   r  r_   s      rB   rb   z&Ring2D._parameter_units_for_data_units2	  s     t{1~&+dk!n*EEEGHHHt{1~.t{1~.A/ Q0%dl1o6
 
 	
rD   )rd   re   rf   rg   r   rO   rm  r  r  r  r5   r~   rj   rP   ri   rC   r[   rb   r   r   s   @rB   r,   r,     s5       $ $L 	!1MSWXXXI
)A+I
J
J
JC
)A+I
J
J
JC9Q,FGGGDIa-@AAAE #KK!
 !
 !
 !
 !
 !
F   \ P P XP 
 
 X

 
 
 
 
 
 
rD   r,   c                       e Zd ZdZ eddd          Z edd          Z edd	          Zed
             Z	e
d             Ze
d             Ze
d             Zd ZdS )r   a  
    One dimensional Box model.

    Parameters
    ----------
    amplitude : float
        Amplitude A
    x_0 : float
        Position of the center of the box function
    width : float
        Width of the box

    See Also
    --------
    Box2D, TrapezoidDisk2D

    Notes
    -----
    Model formula:

      .. math::

            f(x) = \left \{
                     \begin{array}{ll}
                       A & : x_0 - w/2 \leq x \leq x_0 + w/2 \\
                       0 & : \text{else}
                     \end{array}
                   \right.

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import Box1D

        plt.figure()
        s1 = Box1D()
        r = np.arange(-5, 5, .01)

        for factor in range(1, 4):
            s1.amplitude = factor
            s1.width = factor
            plt.plot(r, s1(r), color=str(0.25 * factor), lw=2)

        plt.axis([-5, 5, -1, 4])
        plt.show()
    r   zAmplitude ATr  r   z"Position of center of box functionr4   zWidth of the boxc                     t          j        | ||dz  z
  k    | ||dz  z   k              }t          j        |g|gd          S )z#One dimensional Box model function.r2   r   )rL   r  r  )rN   rO   rm  r  insides        rB   rP   zBox1D.evaluatez	  sI     S53;%6 6S53;=N8NOOy&I;222rD   c                 >    | j         dz  }| j        |z
  | j        |z   fS zc
        Tuple defining the default ``bounding_box`` limits.

        ``(x_low, x_high))``
        r1   )r  rm  r>   rA   s     rB   rC   zBox1D.bounding_box	  s&     Z!^2tx"}--rD   c                 P    | j         j        d S | j        d         | j         j        iS rX   rt  rG   s    rB   r[   zBox1D.input_units	  ru  rD   c                 P    | j         j        d S | j        d         | j         j        iS rX   )rO   r5  r^   rG   s    rB   return_unitszBox1D.return_units	  s(    >&4Q!455rD   c                 t    || j         d                  || j         d                  || j        d                  dS )Nr   )rm  r  rO   r]   r_   s      rB   rb   z%Box1D._parameter_units_for_data_units	  ;    t{1~. Q0%dl1o6
 
 	
rD   N)rd   re   rf   rg   r   rO   rm  r  rj   rP   ri   rC   r[   r  rb   rk   rD   rB   r   r   A	  s        2 2h 	!DIIII
)A+O
P
P
PCIa-?@@@E3 3 \3
 . . X. 5 5 X5
 6 6 X6

 
 
 
 
rD   r   c                       e Zd ZdZ eddd          Z edd          Z edd	          Z edd
          Z edd          Z	e
d             Zed             Zed             Zd ZdS )r   a  
    Two dimensional Box model.

    Parameters
    ----------
    amplitude : float
        Amplitude
    x_0 : float
        x position of the center of the box function
    x_width : float
        Width in x direction of the box
    y_0 : float
        y position of the center of the box function
    y_width : float
        Width in y direction of the box

    See Also
    --------
    Box1D, Gaussian2D, Moffat2D

    Notes
    -----
    Model formula:

      .. math::

            f(x, y) = \left \{
                     \begin{array}{ll}
            A : & x_0 - w_x/2 \leq x \leq x_0 + w_x/2 \text{ and} \\
                & y_0 - w_y/2 \leq y \leq y_0 + w_y/2 \\
            0 : & \text{else}
                     \end{array}
                   \right.

    r   	AmplitudeTr  r   z,X position of the center of the box functionr4   z,Y position of the center of the box functionzWidth in x direction of the boxzWidth in y direction of the boxc                 Z   t          j        | ||dz  z
  k    | ||dz  z   k              }t          j        |||dz  z
  k    |||dz  z   k              }t          j        t          j        ||          g|gd          }	t          |t                    rt	          |	|j        dd          S |	S )z#Two dimensional Box model function.r2   r   FTr  r  )
rN   r   rO   rm  r  x_widthy_widthx_rangey_ranger  s
             rB   rP   zBox2D.evaluate	  s     .cGcM&9!91gPSm@S;STT.cGcM&9!91gPSm@S;STTBN7G<<=	{ANNi** 	QFe4PPPPrD   c                 z    | j         dz  }| j        dz  }| j        |z
  | j        |z   f| j        |z
  | j        |z   ffS )r  r1   )r  r  r  rm  )r>   rA   r   s      rB   rC   zBox2D.bounding_box	  sI     \A\AB2.B20NOOrD   c                 ~    | j         j        d S | j        d         | j         j        | j        d         | j        j        iS r   r  rG   s    rB   r[   zBox2D.input_units	  r  rD   c                     || j         d                  || j         d                  || j         d                  || j         d                  || j        d                  dS )Nr   r   )rm  r  r  r  rO   r]   r_   s      rB   rb   z%Box2D._parameter_units_for_data_units	  sW    t{1~.t{1~."4;q>2"4;q>2%dl1o6
 
 	
rD   N)rd   re   rf   rg   r   rO   rm  r  r  r  rj   rP   ri   rC   r[   rb   rk   rD   rB   r   r   	  s        " "H 	!$GGGI
)M  C )M  C i/PQQQGi/PQQQG	 	 \	 	P 	P X	P 
 
 X

 
 
 
 
rD   r   c                       e Zd ZdZ edd          Z edd          Z edd          Z edd          Ze	d	             Z
ed
             Zed             Zd ZdS )r*   ae  
    One dimensional Trapezoid model.

    Parameters
    ----------
    amplitude : float
        Amplitude of the trapezoid
    x_0 : float
        Center position of the trapezoid
    width : float
        Width of the constant part of the trapezoid.
    slope : float
        Slope of the tails of the trapezoid

    See Also
    --------
    Box1D, Gaussian1D, Moffat1D

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import Trapezoid1D

        plt.figure()
        s1 = Trapezoid1D()
        r = np.arange(-5, 5, .01)

        for factor in range(1, 4):
            s1.amplitude = factor
            s1.width = factor
            plt.plot(r, s1(r), color=str(0.25 * factor), lw=2)

        plt.axis([-5, 5, -1, 4])
        plt.show()
    r   Amplitude of the trapezoidr4   r   z Center position of the trapezoidz'Width of constant part of the trapezoidzSlope of the tails of trapezoidc                    ||dz  z
  }||dz  z   }|||z  z
  }|||z  z   }t          j        | |k    | |k               }	t          j        | |k    | |k               }
t          j        | |k    | |k               }|| |z
  z  }|}||| z
  z  }t          j        |	|
|g|||g          }t          |t                    rt	          ||j        dd          S |S )z)One dimensional Trapezoid model function.r2   FTr  r  )rN   rO   rm  r  rX  x2x3x1x4range_arange_brange_cval_aval_bval_cr  s                   rB   rP   zTrapezoid1D.evaluate(
  s    
 53;53;)e##)e## .b!b&11.b!b&11.b!b&11R a GWg6u8MNNi** 	QFe4PPPPrD   c                 ^    | j         dz  | j        | j        z  z   }| j        |z
  | j        |z   fS r  )r  rO   rX  rm  r  s     rB   rC   zTrapezoid1D.bounding_box?
  s4     Z!^dntz992tx"}--rD   c                 P    | j         j        d S | j        d         | j         j        iS rX   rt  rG   s    rB   r[   zTrapezoid1D.input_unitsJ
  ru  rD   c                     || j         d                  || j         d                  || j        d                  || j         d                  z  || j        d                  dS )Nr   )rm  r  rX  rO   r]   r_   s      rB   rb   z+Trapezoid1D._parameter_units_for_data_unitsP
  sY    t{1~. Q0!$,q/2[Q5PP%dl1o6	
 
 	
rD   N)rd   re   rf   rg   r   rO   rm  r  rX  rj   rP   ri   rC   r[   rb   rk   rD   rB   r*   r*   	  s        ' 'R 	!1MNNNI
)A+M
N
N
NCIa-VWWWEIa-NOOOE  \, . . X. 5 5 X5

 
 
 
 
rD   r*   c                       e Zd ZdZ edd          Z edd          Z edd          Z edd          Z edd	          Z	e
d
             Zed             Zed             Zd ZdS )r+   a  
    Two dimensional circular Trapezoid model.

    Parameters
    ----------
    amplitude : float
        Amplitude of the trapezoid
    x_0 : float
        x position of the center of the trapezoid
    y_0 : float
        y position of the center of the trapezoid
    R_0 : float
        Radius of the constant part of the trapezoid.
    slope : float
        Slope of the tails of the trapezoid in x direction.

    See Also
    --------
    Disk2D, Box2D
    r   r  r4   r   z)X position of the center of the trapezoidz)Y position of the center of the trapezoidz$Radius of constant part of trapezoidz*Slope of tails of trapezoid in x directionc                 D   t          j        | |z
  dz  ||z
  dz  z             }||k    }t          j        ||k    ||||z  z   k              }	|}
||||z
  z  z   }t          j        ||	g|
|g          }t	          |t
                    rt          ||j        dd          S |S )z.Two dimensional Trapezoid Disk model function.r1   FTr  )rL   rz   r  r  r   r   r5  )rN   r   rO   rm  r  r  rX  r  range_1range_2val_1val_2r  s                rB   rP   zTrapezoidDisk2D.evaluatew
  s     GQWNa#g!^344s(.S!sY5F/F*FGGES1W--GW-u~>>i** 	QFe4PPPPrD   c                     | j         | j        | j        z  z   }| j        |z
  | j        |z   f| j        |z
  | j        |z   ffS r  )r  rO   rX  r  rm  r  s     rB   rC   zTrapezoidDisk2D.bounding_box
  sF     X33B2.B20NOOrD   c                 v    | j         j        }| j        j        }||d S | j        d         || j        d         |iS r   r  r   s      rB   r[   zTrapezoidDisk2D.input_units
  s?    $$>fn4AA??rD   c                 &   |d         |d         k    rt          d          || j        d                  || j        d                  || j        d                  || j        d                  || j        d                  z  || j        d                  dS )NrN   r   r   r   )rm  r  r  rX  rO   )r   rZ   r^   r_   s      rB   rb   z/TrapezoidDisk2D._parameter_units_for_data_units
  s     s{3///GHHHt{1~.t{1~.t{1~.!$,q/2[Q5PP%dl1o6
 
 	
rD   N)rd   re   rf   rg   r   rO   rm  r  r  rX  rj   rP   ri   rC   r[   rb   rk   rD   rB   r+   r+   Y
  s         * 	!1MNNNI
)A+V
W
W
WC
)A+V
W
W
WC
)A+Q
R
R
RCIK  E   \ P P XP @ @ X@
 
 
 
 
rD   r+   c                       e Zd ZdZ edd          Z edd          Z edd          Zed             Z	dd
Z
ed             Zd ZdS )r   a  
    One dimensional Ricker Wavelet model (sometimes known as a "Mexican Hat"
    model).

    .. note::

        See https://github.com/astropy/astropy/pull/9445 for discussions
        related to renaming of this model.

    Parameters
    ----------
    amplitude : float
        Amplitude
    x_0 : float
        Position of the peak
    sigma : float
        Width of the Ricker wavelet

    See Also
    --------
    RickerWavelet2D, Box1D, Gaussian1D, Trapezoid1D

    Notes
    -----
    Model formula:

    .. math::

        f(x) = {A \left(1 - \frac{\left(x - x_{0}\right)^{2}}{\sigma^{2}}\right)
        e^{- \frac{\left(x - x_{0}\right)^{2}}{2 \sigma^{2}}}}

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import RickerWavelet1D

        plt.figure()
        s1 = RickerWavelet1D()
        r = np.arange(-5, 5, .01)

        for factor in range(1, 4):
            s1.amplitude = factor
            s1.width = factor
            plt.plot(r, s1(r), color=str(0.25 * factor), lw=2)

        plt.axis([-5, 5, -2, 4])
        plt.show()
    r   Amplitude (peak) valuer4   r   rk  Width of the Ricker waveletc                 f    | |z
  dz  d|dz  z  z  }|dd|z  z
  z  t          j        |           z  S )z.One dimensional Ricker Wavelet model function.r1   r   rK   )rN   rO   rm  sigmaxx_wws        rB   rP   zRickerWavelet1D.evaluate
  s@     SQ!eQh,/AE	M*RVUF^^;;rD   r  c                 8    | j         }|| j        z  }||z
  ||z   fS )zTuple defining the default ``bounding_box`` limits,
        ``(x_low, x_high)``.

        Parameters
        ----------
        factor : float
            The multiple of sigma used to define the limits.

        )rm  r5  r=   s       rB   rC   zRickerWavelet1D.bounding_box
  s*     Xdj Rb!!rD   c                 P    | j         j        d S | j        d         | j         j        iS rX   rt  rG   s    rB   r[   zRickerWavelet1D.input_units
  ru  rD   c                 t    || j         d                  || j         d                  || j        d                  dS )Nr   )rm  r5  rO   r]   r_   s      rB   rb   z/RickerWavelet1D._parameter_units_for_data_units
  r  rD   Nr  )rd   re   rf   rg   r   rO   rm  r5  rj   rP   rC   ri   r[   rb   rk   rD   rB   r   r   
  s        4 4l 	!1IJJJI
)A+A
B
B
BCIa-JKKKE< < \<
" " " " 5 5 X5

 
 
 
 
rD   r   c                       e Zd ZdZ edd          Z edd          Z edd          Z edd          Ze	d	             Z
ed
             Zd ZdS )r   a  
    Two dimensional Ricker Wavelet model (sometimes known as a "Mexican Hat"
    model).

    .. note::

        See https://github.com/astropy/astropy/pull/9445 for discussions
        related to renaming of this model.

    Parameters
    ----------
    amplitude : float
        Amplitude
    x_0 : float
        x position of the peak
    y_0 : float
        y position of the peak
    sigma : float
        Width of the Ricker wavelet

    See Also
    --------
    RickerWavelet1D, Gaussian2D

    Notes
    -----
    Model formula:

    .. math::

        f(x, y) = A \left(1 - \frac{\left(x - x_{0}\right)^{2}
        + \left(y - y_{0}\right)^{2}}{\sigma^{2}}\right)
        e^{\frac{- \left(x - x_{0}\right)^{2}
        - \left(y - y_{0}\right)^{2}}{2 \sigma^{2}}}
    r   r2  r4   r   X position of the peakY position of the peakr3  c                 r    | |z
  dz  ||z
  dz  z   d|dz  z  z  }|d|z
  z  t          j        |           z  S )z.Two dimensional Ricker Wavelet model function.r1   r   rK   )rN   r   rO   rm  r  r5  rr_wws          rB   rP   zRickerWavelet2D.evaluate1  sI     c'a1s7q.0Q\BAI&77rD   c                 ~    | j         j        d S | j        d         | j         j        | j        d         | j        j        iS r   r  rG   s    rB   r[   zRickerWavelet2D.input_units7  r  rD   c                    || j         d                  || j         d                  k    rt          d          || j         d                  || j         d                  || j         d                  || j        d                  dS )Nr   r   r   )rm  r  r5  rO   r  r_   s      rB   rb   z/RickerWavelet2D._parameter_units_for_data_units@  {     t{1~&+dk!n*EEEGHHHt{1~.t{1~. Q0%dl1o6	
 
 	
rD   N)rd   re   rf   rg   r   rO   rm  r  r5  rj   rP   ri   r[   rb   rk   rD   rB   r   r     s        " "H 	!1IJJJI
)A+C
D
D
DC
)A+C
D
D
DCIa-JKKKE8 8 \8
 
 
 X

 
 
 
 
rD   r   c                       e Zd ZdZ edd          Z edd          Z edd          Z edd          Zd	Z	d	Z
ed
             Zed             Zd Zd	S )r   a  
    Two dimensional Airy disk model.

    Parameters
    ----------
    amplitude : float
        Amplitude of the Airy function.
    x_0 : float
        x position of the maximum of the Airy function.
    y_0 : float
        y position of the maximum of the Airy function.
    radius : float
        The radius of the Airy disk (radius of the first zero).

    See Also
    --------
    Box2D, TrapezoidDisk2D, Gaussian2D

    Notes
    -----
    Model formula:

        .. math:: f(r) = A \left[
                \frac{2 J_1(\frac{\pi r}{R/R_z})}{\frac{\pi r}{R/R_z}}
            \right]^2

    Where :math:`J_1` is the first order Bessel function of the first
    kind, :math:`r` is radial distance from the maximum of the Airy
    function (:math:`r = \sqrt{(x - x_0)^2 + (y - y_0)^2}`), :math:`R`
    is the input ``radius`` parameter, and :math:`R_z =
    1.2196698912665045`).

    For an optical system, the radius of the first zero represents the
    limiting angular resolution and is approximately 1.22 * lambda / D,
    where lambda is the wavelength of the light and D is the diameter of
    the aperture.

    See [1]_ for more details about the Airy disk.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Airy_disk
    r   z+Amplitude (peak value) of the Airy functionr4   r   r;  r<  z;The radius of the Airy disk (radius of first zero crossing)Nc                 Z   | j         3ddlm}m}  |dd          d         t          j        z  | _         || _        t	          j        ||z
  dz  ||z
  dz  z             || j         z  z  }	t          |	t                    r|	
                    t          j                  }	t	          j        |	j                  }
t          j        |	|	dk             z  }d|                     |          z  |z  dz  |
|	dk    <   t          |t                    rt          |
t          j        dd	          }
|
|z  }
|
S )
z$Two dimensional Airy model function.Nr   )j1jn_zerosr   r1   r2   FT)r   r  )_rzr  rD  rE  rL   r  _j1rz   r   r   r  r   r  rA  rv   )r  rN   r   rO   rm  r  radiusrD  rE  r  r   rts               rB   rP   zAiryDisk2D.evaluate  s$    7?22222222hq!nnQ'"%/CGCGGQWNa#g!^3448HIa"" 	5

1344A GAGUQq1uX#''"++%*q0!a%i** 	NA45MMMA	YrD   c                 ~    | j         j        d S | j        d         | j         j        | j        d         | j        j        iS r   r  rG   s    rB   r[   zAiryDisk2D.input_units  r  rD   c                    || j         d                  || j         d                  k    rt          d          || j         d                  || j         d                  || j         d                  || j        d                  dS )Nr   r   r   )rm  r  rH  rO   r  r_   s      rB   rb   z*AiryDisk2D._parameter_units_for_data_units  s{     t{1~&+dk!n*EEEGHHHt{1~.t{1~.!$+a.1%dl1o6	
 
 	
rD   )rd   re   rf   rg   r   rO   rm  r  rH  rF  rG  r  rP   ri   r[   rb   rk   rD   rB   r   r   N  s        * *X 	L  I )A+C
D
D
DC
)A+C
D
D
DCYQ  F C
C  [6 
 
 X

 
 
 
 
rD   r   c                       e Zd ZdZ edd          Z edd          Z edd          Z edd          Ze	d	             Z
ed
             Zed             Ze	d             Zd ZdS )r   a  
    One dimensional Moffat model.

    Parameters
    ----------
    amplitude : float
        Amplitude of the model.
    x_0 : float
        x position of the maximum of the Moffat model.
    gamma : float
        Core width of the Moffat model.
    alpha : float
        Power index of the Moffat model.

    See Also
    --------
    Gaussian1D, Box1D

    Notes
    -----
    Model formula:

    .. math::

        f(x) = A \left(1 + \frac{\left(x - x_{0}\right)^{2}}{\gamma^{2}}\right)^{- \alpha}

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt

        from astropy.modeling.models import Moffat1D

        plt.figure()
        s1 = Moffat1D()
        r = np.arange(-5, 5, .01)

        for factor in range(1, 4):
            s1.amplitude = factor
            s1.width = factor
            plt.plot(r, s1(r), color=str(0.25 * factor), lw=2)

        plt.axis([-5, 5, -1, 4])
        plt.show()
    r   zAmplitude of the modelr4   r   z%X position of maximum of Moffat modelzCore width of Moffat modelPower index of the Moffat modelc                     dt          j        | j                  z  t          j        dd| j        z  z  dz
            z  S a  
        Moffat full width at half maximum.
        Derivation of the formula is available in
        `this notebook by Yoonsoo Bach
        <https://nbviewer.jupyter.org/github/ysbach/AO_2017/blob/master/04_Ground_Based_Concept.ipynb#1.2.-Moffat>`_.
        r2   r   rL   r  gammarz   alpharG   s    rB   rH   zMoffat1D.fwhm  ;     RVDJ'''"'##
:J2Kc2Q*R*RRRrD   c                 ,    |d| |z
  |z  dz  z   | z  z  S )z&One dimensional Moffat model function.r   r1   rk   )rN   rO   rm  rQ  rR  s        rB   rP   zMoffat1D.evaluate  s)     A!c'U!2q 88ufEEErD   c                     d| |z
  dz  |dz  z  z   }|| z  }d|z  |z  | |z
  z  |z  ||dz  z  z  }d|z  |z  | |z
  dz  z  |z  ||dz  z  z  }| |z  t          j        |          z  }	||||	gS )zCOne dimensional Moffat model derivative with respect to parameters.r   r1   rR   rL   r  )
rN   rO   rm  rQ  rR  facd_Aro  d_gammad_alphas
             rB   rV   zMoffat1D.fit_deriv   s     1s7q.5!8++ufoI%S1C73>Ji-%'1s7q.83>#q.Q*s"RVC[[0UGW--rD   c                 P    | j         j        d S | j        d         | j         j        iS rX   rt  rG   s    rB   r[   zMoffat1D.input_units
  ru  rD   c                 t    || j         d                  || j         d                  || j        d                  dS )Nr   )rm  rQ  rO   r]   r_   s      rB   rb   z(Moffat1D._parameter_units_for_data_units  r  rD   N)rd   re   rf   rg   r   rO   rm  rQ  rR  ri   rH   rj   rP   rV   r[   rb   rk   rD   rB   r   r     s        / /b 	!1IJJJI
)A+R
S
S
SCIa-IJJJEIa-NOOOES S XS F F \F . . \. 5 5 X5

 
 
 
 
rD   r   c                       e Zd ZdZ edd          Z edd          Z edd          Z edd          Z edd	          Z	e
d
             Zed             Zed             Ze
d             Zd ZdS )r   ak  
    Two dimensional Moffat model.

    Parameters
    ----------
    amplitude : float
        Amplitude of the model.
    x_0 : float
        x position of the maximum of the Moffat model.
    y_0 : float
        y position of the maximum of the Moffat model.
    gamma : float
        Core width of the Moffat model.
    alpha : float
        Power index of the Moffat model.

    See Also
    --------
    Gaussian2D, Box2D

    Notes
    -----
    Model formula:

    .. math::

        f(x, y) = A \left(1 + \frac{\left(x - x_{0}\right)^{2} +
        \left(y - y_{0}\right)^{2}}{\gamma^{2}}\right)^{- \alpha}
    r   z#Amplitude (peak value) of the modelr4   r   z-X position of the maximum of the Moffat modelz-Y position of the maximum of the Moffat modelzCore width of the Moffat modelrM  c                     dt          j        | j                  z  t          j        dd| j        z  z  dz
            z  S rO  rP  rG   s    rB   rH   zMoffat2D.fwhmA  rS  rD   c                 H    | |z
  dz  ||z
  dz  z   |dz  z  }|d|z   | z  z  S )z&Two dimensional Moffat model function.r1   r   rk   )rN   r   rO   rm  r  rQ  rR  rr_ggs           rB   rP   zMoffat2D.evaluateK  s=     c'a1s7q.0E1H<AIE6222rD   c                 .   | |z
  dz  ||z
  dz  z   |dz  z  }d|z   | z  }d|z  |z  |z  | |z
  z  |dz  d|z   z  z  }	d|z  |z  |z  ||z
  z  |dz  d|z   z  z  }
| |z  t          j        d|z             z  }d|z  |z  |z  |z  |d|z   z  z  }||	|
||gS )zCTwo dimensional Moffat model derivative with respect to parameters.r1   r   rV  )rN   r   rO   rm  r  rQ  rR  r`  rX  ro  d_y_0rZ  rY  s                rB   rV   zMoffat2D.fit_derivQ  s     c'a1s7q.0E1H<5yuf%I%+q3w75!8q5y;QRI%+q3w75!8q5y;QR*s"RVAI%6%66i-%'#-5!e)9LMUE7G44rD   c                 ~    | j         j        d S | j        d         | j         j        | j        d         | j        j        iS r   r  rG   s    rB   r[   zMoffat2D.input_units\  s>    8&4 A 3A 3 rD   c                    || j         d                  || j         d                  k    rt          d          || j         d                  || j         d                  || j         d                  || j        d                  dS )Nr   r   r   )rm  r  rQ  rO   r  r_   s      rB   rb   z(Moffat2D._parameter_units_for_data_unitsf  rA  rD   N)rd   re   rf   rg   r   rO   rm  r  rQ  rR  ri   rH   rj   rP   rV   r[   rb   rk   rD   rB   r   r     s        < 	!1VWWWI
)N  C )N  C Ia-MNNNEIa-NOOOES S XS 3 3 \3
 5 5 \5   X
 
 
 
 
rD   r   c                       e Zd ZdZ edd          Z edd          Z edd          Z edd	          Z edd
          Z	 edd          Z
 edd          ZdZed             Zed             Zd ZdS )r"   a  
    Two dimensional Sersic surface brightness profile.

    Parameters
    ----------
    amplitude : float
        Surface brightness at r_eff.
    r_eff : float
        Effective (half-light) radius
    n : float
        Sersic Index.
    x_0 : float, optional
        x position of the center.
    y_0 : float, optional
        y position of the center.
    ellip : float, optional
        Ellipticity.
    theta : float or `~astropy.units.Quantity`, optional
        The rotation angle as an angular quantity
        (`~astropy.units.Quantity` or `~astropy.coordinates.Angle`)
        or a value in radians (as a float). The rotation angle
        increases counterclockwise from the positive x axis.

    See Also
    --------
    Gaussian2D, Moffat2D

    Notes
    -----
    Model formula:

    .. math::

        I(x,y) = I(r) = I_e\exp\left\{
                -b_n\left[\left(\frac{r}{r_{e}}\right)^{(1/n)}-1\right]
            \right\}

    The constant :math:`b_n` is defined such that :math:`r_e` contains half the total
    luminosity, and can be solved for numerically.

    .. math::

        \Gamma(2n) = 2\gamma (2n,b_n)

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        from astropy.modeling.models import Sersic2D
        import matplotlib.pyplot as plt

        x,y = np.meshgrid(np.arange(100), np.arange(100))

        mod = Sersic2D(amplitude = 1, r_eff = 25, n=4, x_0=50, y_0=50,
                       ellip=.5, theta=-1)
        img = mod(x, y)
        log_img = np.log10(img)


        plt.figure()
        plt.imshow(log_img, origin='lower', interpolation='nearest',
                   vmin=-1, vmax=2)
        plt.xlabel('x')
        plt.ylabel('y')
        cbar = plt.colorbar()
        cbar.set_label('Log Brightness', rotation=270, labelpad=25)
        cbar.set_ticks([-1, 0, 1, 2])
        plt.show()

    References
    ----------
    .. [1] http://ned.ipac.caltech.edu/level5/March05/Graham/Graham2.html
    r   r  r4   r  r  r  r   zX position of the centerzY position of the centerEllipticityrm   r  Nc
                    | j         ddlm}
 |
| _         |                      d|z  d          }|d|z
  |z  }}t          j        |	          t          j        |	          }}||z
  |z  ||z
  |z  z   }||z
   |z  ||z
  |z  z   }t          j        ||z  dz  ||z  dz  z             }|t          j        | |d|z  z  dz
  z            z  S )z(Two dimensional Sersic profile function.Nr   r  r2   r   r   r1   )r
  r  r	  rL   r   r   rz   rM   )r  rN   r   rO   r  r  rm  r  elliprs   r	  bnr   r   	cos_theta	sin_thetax_majx_minr   s                      rB   rP   zSersic2D.evaluate  s     #111111*CcAgs++q5yE)1!ve}}bfUmm9	SI%SI(==c'
Y&!c'Y)>>GUQY1$	a'7788262#q1u)9":;;;;rD   c                 ~    | j         j        d S | j        d         | j         j        | j        d         | j        j        iS r   r  rG   s    rB   r[   zSersic2D.input_units  r  rD   c                    || j         d                  || j         d                  k    rt          d          || j         d                  || j         d                  || j         d                  t          j        || j        d                  dS )Nr   r   r   )rm  r  r  rs   rO   r   r_   s      rB   rb   z(Sersic2D._parameter_units_for_data_units  s     t{1~&+dk!n*EEEGHHHt{1~.t{1~. Q0U%dl1o6
 
 	
rD   )rd   re   rf   rg   r   rO   r  r  rm  r  rh  rs   r
  r  rP   ri   r[   rb   rk   rD   rB   r"   r"   t  s       J JX 	!1NOOOIIa-LMMME	!888A
)A+E
F
F
FC
)A+E
F
F
FCIa];;;EIQ  E L< < [<  
 
 X

 
 
 
 
rD   r"   c                       e Zd ZdZ ededfd          Z ededfd          Z ededfd          Ze	d	             Z
edd
            Zed             Zd Zd Ze	d             Ze	d             Zd ZdS )r.   a  
    Projected (surface density) analytic King Model.


    Parameters
    ----------
    amplitude : float
        Amplitude or scaling factor.
    r_core : float
        Core radius (f(r_c) ~ 0.5 f_0)
    r_tide : float
        Tidal radius.


    Notes
    -----
    This model approximates a King model with an analytic function. The derivation of this
    equation can be found in King '62 (equation 14). This is just an approximation of the
    full model and the parameters derived from this model should be taken with caution.
    It usually works for models with a concentration (c = log10(r_t/r_c) parameter < 2.

    Model formula:

    .. math::

        f(x) = A r_c^2  \left(\frac{1}{\sqrt{(x^2 + r_c^2)}} -
        \frac{1}{\sqrt{(r_t^2 + r_c^2)}}\right)^2

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        from astropy.modeling.models import KingProjectedAnalytic1D
        import matplotlib.pyplot as plt

        plt.figure()
        rt_list = [1, 2, 5, 10, 20]
        for rt in rt_list:
            r = np.linspace(0.1, rt, 100)

            mod = KingProjectedAnalytic1D(amplitude = 1, r_core = 1., r_tide = rt)
            sig = mod(r)


            plt.loglog(r, sig/sig[0], label=f"c ~ {mod.concentration:0.2f}")

        plt.xlabel("r")
        plt.ylabel(r"$\sigma/\sigma_0$")
        plt.legend()
        plt.show()

    References
    ----------
    .. [1] https://ui.adsabs.harvard.edu/abs/1962AJ.....67..471K
    r   NzAmplitude or scaling factorr7   zCore Radiusr1   zTidal Radiusc                 h    t          j        t          j        | j        | j        z                      S )z*Concentration parameter of the king model.)rL   log10r  r_tider_corerG   s    rB   concentrationz%KingProjectedAnalytic1D.concentration?  s'     xt{T[899:::rD   c                     dt          j        | dz  |dz  z             |z  z  dt          j        |dz  |dz  z             |z  z  z
  S )Nr   r1   )rL   rz   )rN   rt  rs  powers       rB   
_core_funcz"KingProjectedAnalytic1D._core_funcD  sV     "'!Q$*++u44BGFAI	122e;;<	
rD   c                 <    | |k    | dk     z  }||         dz  ||<   dS )zSet invalid r values to 0r   rm   Nrk   )rN   rs  r  r8   s       rB   _filterzKingProjectedAnalytic1D._filterK  s,     v+!a%(#-vrD   c                 z    ||dz  z  |                      |||          dz  z  }|                     |||           |S )z/
        Analytic King model function.
        r1   rx  rz  )r>   rN   rO   rt  rs  r  s         rB   rP   z KingProjectedAnalytic1D.evaluateQ  sG     VQY&FF)K)Kq)PPQ'''rD   c                    |dz  |                      |||          dz  z  }|                     |||           d|z  |dz  z  |                      |||d          z  |                      |||          z  d|z  |z  |                      |||          dz  z  z   }|                     |||           d|z  |dz  z  |z  |                      |||          z  |dz  |dz  z   dz  z  }|                     |||           |||gS )z;
        Analytic King model function derivatives.
        r1   g       rR   )rw  g      ?r|  )r>   rN   rO   rt  rs  rS   d_r_cored_r_tides           rB   rV   z!KingProjectedAnalytic1D.fit_derivZ  sF    ai$//!VV"D"D"IIQ,,, ai ooaqo99: ooa00	1
 )mf$tq&&'I'IQ'NNO 	 	Q))) 	MFAI%.FF1S1SSQY"./ 	Q)))Xx00rD   c                 *    d| j         z  d| j         z  fS )z
        Tuple defining the default ``bounding_box`` limits.

        The model is not defined for r > r_tide.

        ``(r_low, r_high)``
        r   r   )rs  rG   s    rB   rC   z$KingProjectedAnalytic1D.bounding_boxr  s     DKT[11rD   c                 P    | j         j        d S | j        d         | j         j        iS rX   )rt  rY   rZ   rG   s    rB   r[   z#KingProjectedAnalytic1D.input_units}  r   rD   c                 t    || j         d                  || j         d                  || j        d                  dS )Nr   )rt  rs  rO   r]   r_   s      rB   rb   z7KingProjectedAnalytic1D._parameter_units_for_data_units  s;    !$+a.1!$+a.1%dl1o6
 
 	
rD   )r   )rd   re   rf   rg   r   rh   rO   rt  rs  ri   ru  rj   rx  rz  rP   rV   rC   r[   rb   rk   rD   rB   r.   r.     sF       8 8t 	t$1  I
 Y=$/]  F Y=$/^  F ; ; X; 
 
 
 \
 . . \.
  1 1 10 2 2 X2 8 8 X8

 
 
 
 
rD   r.   c                       e Zd ZdZ ed          Z ed          Zed             Zed             Z	e
d             Zd Zee_        e
d             Zd	 Zd
S )r0   z
    One dimensional logarithmic model.

    Parameters
    ----------
    amplitude : float, optional
    tau : float, optional

    See Also
    --------
    Exponential1D, Gaussian1D
    r   r5   c                 6    |t          j        | |z            z  S r   rV  rN   rO   taus      rB   rP   zLogarithmic1D.evaluate      26!c'??**rD   c                 v    t          j        | |z            }t          j        | j                  ||z  z
  }||gS r   )rL   r  r  rv   rN   rO   r  rS   d_taus        rB   rV   zLogarithmic1D.fit_deriv  s8    fQWoo!!Y_5U##rD   c                 @    | j         }| j        }t          ||          S N)rO   r  )r  rO   r/   r>   new_amplitudenew_taus      rB   r   zLogarithmic1D.inverse  #    .}'BBBBrD   c                 T    t          j        |dk              rt          d          d S )Nr   !0 is not an allowed value for taurL   allrw   r>   vals     rB   _tau_validatorzLogarithmic1D._tau_validator  s4    6#( 	B@AAA	B 	BrD   c                 P    | j         j        d S | j        d         | j         j        iS rX   r  rY   rZ   rG   s    rB   r[   zLogarithmic1D.input_units  ru  rD   c                 P    || j         d                  || j        d                  dS Nr   )r  rO   r]   r_   s      rB   rb   z-Logarithmic1D._parameter_units_for_data_units  -    t{1~.%dl1o6
 
 	
rD   Nrd   re   rf   rg   r   rO   r  rj   rP   rV   ri   r   r  
_validatorr[   rb   rk   rD   rB   r0   r0     s          	!$$$I
)A


C+ + \+ $ $ \$
 C C XC
B B B $CN5 5 X5

 
 
 
 
rD   r0   c                       e Zd ZdZ ed          Z ed          Zed             Zed             Z	e
d             Zd Zee_        e
d             Zd	 Zd
S )r/   z
    One dimensional exponential model.

    Parameters
    ----------
    amplitude : float, optional
    tau : float, optional

    See Also
    --------
    Logarithmic1D, Gaussian1D
    r   r  c                 6    |t          j        | |z            z  S r   rK   r  s      rB   rP   zExponential1D.evaluate  r  rD   c                     t          j        | |z            }| | |dz  z  z  t          j        | |z            z  }||gS )z&Derivative with respect to parameters.r1   rK   r  s        rB   rV   zExponential1D.fit_deriv  sE     fQWoo
a#q&j)BF1s7OO;U##rD   c                 @    | j         }| j        }t          ||          S r  )r  rO   r0   r  s      rB   r   zExponential1D.inverse  r  rD   c                 T    t          j        |dk              rt          d          dS )ztau cannot be 0.r   r  Nr  r  s     rB   r  zExponential1D._tau_validator  s4    6#( 	B@AAA	B 	BrD   c                 P    | j         j        d S | j        d         | j         j        iS rX   r  rG   s    rB   r[   zExponential1D.input_units  ru  rD   c                 P    || j         d                  || j        d                  dS r  r]   r_   s      rB   rb   z-Exponential1D._parameter_units_for_data_units  r  rD   Nr  rk   rD   rB   r/   r/     s          	!$$$I
)A


C+ + \+ $ $ \$ C C XC
B B B
 $CN5 5 X5

 
 
 
 
rD   r/   )Frg   r  numpyrL   astropyr   r   astropy.unitsr   r   "astropy.utils.compat.optional_depsr   astropy.utils.exceptionsr   corer	   r
   
parametersr   r   utilsr   __all__r  r  r  finfofloat32tinyrh   rz   r  rF   r   r   r#   r    r   r   r!   r  r$   r%   r&   r8  r'   r(   r)   r   r   r   r-   r   r   r   r   r,   r   r   r*   r+   r   r   r   r   r   r"   r.   r0   r/   rk   rD   rB   <module>r     s.                . . . . . . . . 8 8 8 8 8 8 > > > > > > 2 2 2 2 2 2 2 2 6 6 6 6 6 6 6 6 ! ! ! ! ! !$ $ $L 	
BE	hbhrz**/00
 wrwsVRVC[['8999 n
 n
 n
 n
 n
 n
 n
 n
bz
 z
 z
 z
 z
 z
 z
 z
z	79 79 79 79 79O 79 79 79t?9 ?9 ?9 ?9 ?9O ?9 ?9 ?9D-9 -9 -9 -9 -9 -9 -9 -9`. . . . ./ . . .b[
 [
 [
 [
 [
 [
 [
 [
|
 
 
 
 
 
 
 
>J
 J
 J
 J
 J
 J
 J
 J
ZJ
 J
 J
 J
 J
 J
 J
 J
Zb b b b b  b b bJ
 
 
 
 
. 
 
 
$[
 [
 [
 [
 [
' [
 [
 [
|[
 [
 [
 [
 [
) [
 [
 [
|N
 N
 N
 N
 N
* N
 N
 N
b7
 7
 7
 7
 7
 7
 7
 7
t-
 -
 -
 -
 -
 -
 -
 -
`e
 e
 e
 e
 e
 e
 e
 e
Pm m m m mo m m m`I< I< I< I< I<o I< I< I<X.< .< .< .< .<o .< .< .<bG
 G
 G
 G
 G
 G
 G
 G
TP
 P
 P
 P
 P
_ P
 P
 P
f{
 {
 {
 {
 {
_ {
 {
 {
|[
 [
 [
 [
 [
O [
 [
 [
|W
 W
 W
 W
 W
O W
 W
 W
t]
 ]
 ]
 ]
 ]
/ ]
 ]
 ]
@M
 M
 M
 M
 M
o M
 M
 M
`[
 [
 [
 [
 [
o [
 [
 [
|D
 D
 D
 D
 D
o D
 D
 D
Ni
 i
 i
 i
 i
 i
 i
 i
X[
 [
 [
 [
 [
 [
 [
 [
|Y
 Y
 Y
 Y
 Y
 Y
 Y
 Y
xA
 A
 A
 A
 A
 A
 A
 A
HP
 P
 P
 P
 P
o P
 P
 P
f1
 1
 1
 1
 1
O 1
 1
 1
h3
 3
 3
 3
 3
O 3
 3
 3
 3
 3
rD   