
    HR-e                        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	m
Z
mZ ddlmZmZ g dZd 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dS )'    N)models)Fittable1DModelFittable2DModel   )KernelKernel1DKernel2D)has_even_axisraise_even_kernel_exception)Gaussian1DKernelGaussian2DKernelCustomKernelBox1DKernelBox2DKernelTophat2DKernelTrapezoid1DKernelRickerWavelet1DKernelRickerWavelet2DKernelAiryDisk2DKernelMoffat2DKernelModel1DKernelModel2DKernelTrapezoidDisk2DKernelRing2DKernelc                 J    t          j        |           }|dz  dk    r|dz   S |S )N   r   r   )mathceil)valueis     ;lib/python3.11/site-packages/astropy/convolution/kernels.py_round_up_to_odd_integerr"       s,    	%A1uzz1u    c                   *     e Zd ZdZdZdZ fdZ xZS )r   u  
    1D Gaussian filter kernel.

    The Gaussian filter is a filter with great smoothing properties. It is
    isotropic and does not produce artifacts.

    The generated kernel is normalized so that it integrates to 1.

    Parameters
    ----------
    stddev : number
        Standard deviation of the Gaussian kernel.
    x_size : int, optional
        Size of the kernel array. Default = ⌊8*stddev+1⌋.
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by linearly interpolating
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin. Very slow.
    factor : number, optional
        Factor of oversampling. Default factor = 10. If the factor
        is too large, evaluation can be very slow.

    See Also
    --------
    Box1DKernel, Trapezoid1DKernel, RickerWavelet1DKernel

    Examples
    --------
    Kernel response:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import Gaussian1DKernel
        gauss_1D_kernel = Gaussian1DKernel(10)
        plt.plot(gauss_1D_kernel, drawstyle='steps')
        plt.xlabel('x [pixels]')
        plt.ylabel('value')
        plt.show()
    TFc                    t          j        dt          j        dt          j        z            |z  z  d|          | _        t          d|z            | _         t                      j	        di | | 
                                 d S )N      ?r   r       )r   
Gaussian1Dnpsqrtpi_modelr"   _default_sizesuper__init__	normalize)selfstddevkwargs	__class__s      r!   r0   zGaussian1DKernel.__init__`   s{    'rwq25y/A/AF/J(KQPVWW5a&jAA""6"""r#   __name__
__module____qualname____doc__
_separable_is_boolr0   __classcell__r5   s   @r!   r   r   (   sO        2 2h JH        r#   r   c                   ,     e Zd ZdZdZdZd fd	Z xZS )r   uv  
    2D Gaussian filter kernel.

    The Gaussian filter is a filter with great smoothing properties. It is
    isotropic and does not produce artifacts.

    The generated kernel is normalized so that it integrates to 1.

    Parameters
    ----------
    x_stddev : float
        Standard deviation of the Gaussian in x before rotating by theta.
    y_stddev : float
        Standard deviation of the Gaussian in y before rotating by theta.
    theta : float or `~astropy.units.Quantity` ['angle']
        Rotation angle. If passed as a float, it is assumed to be in radians.
        The rotation angle increases counterclockwise.
    x_size : int, optional
        Size in x direction of the kernel array. Default = ⌊8*stddev + 1⌋.
    y_size : int, optional
        Size in y direction of the kernel array. Default = ⌊8*stddev + 1⌋.
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by performing a bilinear interpolation
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    See Also
    --------
    Box2DKernel, Tophat2DKernel, RickerWavelet2DKernel, Ring2DKernel,
    TrapezoidDisk2DKernel, AiryDisk2DKernel, Moffat2DKernel

    Examples
    --------
    Kernel response:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import Gaussian2DKernel
        gaussian_2D_kernel = Gaussian2DKernel(10)
        plt.imshow(gaussian_2D_kernel, interpolation='none', origin='lower')
        plt.xlabel('x [pixels]')
        plt.ylabel('y [pixels]')
        plt.colorbar()
        plt.show()
    TFN        c                 *   ||}t          j        ddt          j        z  |z  |z  z  dd|||          | _        t          dt          j        ||g          z            | _         t                      j	        di | | 
                                 d S )Nr&   r   r   )	amplitudex_meany_meanx_stddevy_stddevthetar'   r(   )r   
Gaussian2Dr*   r,   r-   r"   maxr.   r/   r0   r1   )r2   rE   rF   rG   r4   r5   s        r!   r0   zGaussian2DKernel.__init__   s    H'QY1H<=
 
 
 6a"&(HAU:V:V6VWW""6"""r#   )Nr@   r6   r>   s   @r!   r   r   g   sT        : :x JH         r#   r   c                   *     e Zd ZdZdZdZ fdZ xZS )r   a0  
    1D Box filter kernel.

    The Box filter or running mean is a smoothing filter. It is not isotropic
    and can produce artifacts when applied repeatedly to the same data.

    The generated kernel is normalized so that it integrates to 1.

    By default the Box kernel uses the ``linear_interp`` discretization mode,
    which allows non-shifting, even-sized kernels.  This is achieved by
    weighting the edge pixels with 1/2. E.g a Box kernel with an effective
    smoothing of 4 pixel would have the following array: [0.5, 1, 1, 1, 0.5].

    Parameters
    ----------
    width : number
        Width of the filter kernel.
    mode : {'linear_interp', 'center', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'linear_interp' (default)
                Discretize model by linearly interpolating
                between the values at the corners of the bin.
            * 'center'
                Discretize model by taking the value
                at the center of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    See Also
    --------
    Gaussian1DKernel, Trapezoid1DKernel, RickerWavelet1DKernel

    Examples
    --------
    Kernel response function:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import Box1DKernel
        box_1D_kernel = Box1DKernel(9)
        plt.plot(box_1D_kernel, drawstyle='steps')
        plt.xlim(-1, 9)
        plt.xlabel('x [pixels]')
        plt.ylabel('value')
        plt.show()
    Tc                     t          j        d|z  d|          | _        t          |          | _        d|d<    t                      j        di | |                                  d S )Nr&   r   linear_interpmoder(   )r   Box1Dr-   r"   r.   r/   r0   r1   r2   widthr4   r5   s      r!   r0   zBox1DKernel.__init__   sh    l3;5995e<<(v""6"""r#   r6   r>   s   @r!   r   r      sO        5 5n JH        r#   r   c                   *     e Zd ZdZdZdZ fdZ xZS )r   a}  
    2D Box filter kernel.

    The Box filter or running mean is a smoothing filter. It is not isotropic
    and can produce artifacts when applied repeatedly to the same data.

    The generated kernel is normalized so that it integrates to 1.

    By default the Box kernel uses the ``linear_interp`` discretization mode,
    which allows non-shifting, even-sized kernels.  This is achieved by
    weighting the edge pixels with 1/2.

    Parameters
    ----------
    width : number
        Width of the filter kernel.
    mode : {'linear_interp', 'center', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'linear_interp' (default)
                Discretize model by performing a bilinear interpolation
                between the values at the corners of the bin.
            * 'center'
                Discretize model by taking the value
                at the center of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    See Also
    --------
    Gaussian2DKernel, Tophat2DKernel, RickerWavelet2DKernel, Ring2DKernel,
    TrapezoidDisk2DKernel, AiryDisk2DKernel, Moffat2DKernel

    Examples
    --------
    Kernel response:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import Box2DKernel
        box_2D_kernel = Box2DKernel(9)
        plt.imshow(box_2D_kernel, interpolation='none', origin='lower',
                   vmin=0.0, vmax=0.015)
        plt.xlim(-1, 9)
        plt.ylim(-1, 9)
        plt.xlabel('x [pixels]')
        plt.ylabel('y [pixels]')
        plt.colorbar()
        plt.show()
    Tc                     t          j        d|dz  z  dd||          | _        t          |          | _        d|d<    t                      j        di | |                                  d S )Nr&   r   r   rL   rM   r(   )r   Box2Dr-   r"   r.   r/   r0   r1   rO   s      r!   r0   zBox2DKernel.__init__8  sp    l3>1aFF5e<<(v""6"""r#   r6   r>   s   @r!   r   r      sO        8 8t JH        r#   r   c                   "     e Zd ZdZ fdZ xZS )r   aZ  
    2D Tophat filter kernel.

    The Tophat filter is an isotropic smoothing filter. It can produce
    artifacts when applied repeatedly on the same data.

    The generated kernel is normalized so that it integrates to 1.

    Parameters
    ----------
    radius : int
        Radius of the filter kernel.
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by performing a bilinear interpolation
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    See Also
    --------
    Gaussian2DKernel, Box2DKernel, RickerWavelet2DKernel, Ring2DKernel,
    TrapezoidDisk2DKernel, AiryDisk2DKernel, Moffat2DKernel

    Examples
    --------
    Kernel response:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import Tophat2DKernel
        tophat_2D_kernel = Tophat2DKernel(40)
        plt.imshow(tophat_2D_kernel, interpolation='none', origin='lower')
        plt.xlabel('x [pixels]')
        plt.ylabel('y [pixels]')
        plt.colorbar()
        plt.show()
    c                     t          j        dt          j        |dz  z  z  dd|          | _        t          d|z            | _         t                      j        di | | 	                                 d S Nr&   r   r   r(   )
r   Disk2Dr*   r,   r-   r"   r.   r/   r0   r1   r2   radiusr4   r5   s      r!   r0   zTophat2DKernel.__init__t  sq    mC25619+<$=q!VLL5a&jAA""6"""r#   r7   r8   r9   r:   r0   r=   r>   s   @r!   r   r   @  sC        1 1f        r#   r   c                   "     e Zd ZdZ fdZ xZS )r   a  
    2D Ring filter kernel.

    The Ring filter kernel is the difference between two Tophat kernels of
    different width. This kernel is useful for, e.g., background estimation.

    The generated kernel is normalized so that it integrates to 1.

    Parameters
    ----------
    radius_in : number
        Inner radius of the ring kernel.
    width : number
        Width of the ring kernel.
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by performing a bilinear interpolation
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    See Also
    --------
    Gaussian2DKernel, Box2DKernel, Tophat2DKernel, RickerWavelet2DKernel,
    TrapezoidDisk2DKernel, AiryDisk2DKernel, Moffat2DKernel

    Examples
    --------
    Kernel response:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import Ring2DKernel
        ring_2D_kernel = Ring2DKernel(9, 8)
        plt.imshow(ring_2D_kernel, interpolation='none', origin='lower')
        plt.xlabel('x [pixels]')
        plt.ylabel('y [pixels]')
        plt.colorbar()
        plt.show()
    c                    ||z   }t          j        dt          j        |dz  |dz  z
  z  z  dd||          | _        t          d|z            | _         t                      j        di | | 	                                 d S rV   )
r   Ring2Dr*   r,   r-   r"   r.   r/   r0   r1   )r2   	radius_inrP   r4   
radius_outr5   s        r!   r0   zRing2DKernel.__init__  s    &
m25JMIqL89:Aq)U
 
 6a*nEE""6"""r#   rZ   r>   s   @r!   r   r   {  sC        3 3j        r#   r   c                   (     e Zd ZdZdZd fd	Z xZS )r   a  
    1D trapezoid kernel.

    The generated kernel is normalized so that it integrates to 1.

    Parameters
    ----------
    width : number
        Width of the filter kernel, defined as the width of the constant part,
        before it begins to slope down.
    slope : number
        Slope of the filter kernel's tails
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by linearly interpolating
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    See Also
    --------
    Box1DKernel, Gaussian1DKernel, RickerWavelet1DKernel

    Examples
    --------
    Kernel response:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import Trapezoid1DKernel
        trapezoid_1D_kernel = Trapezoid1DKernel(17, slope=0.2)
        plt.plot(trapezoid_1D_kernel, drawstyle='steps')
        plt.xlabel('x [pixels]')
        plt.ylabel('amplitude')
        plt.xlim(-1, 28)
        plt.show()
    Fr&   c                     t          j        dd||          | _        t          |d|z  z             | _         t                      j        di | |                                  d S )Nr   r          @r(   )r   Trapezoid1Dr-   r"   r.   r/   r0   r1   )r2   rP   sloper4   r5   s       r!   r0   zTrapezoid1DKernel.__init__  sg    (Aue<<5ecEk6IJJ""6"""r#   r&   r7   r8   r9   r:   r<   r0   r=   r>   s   @r!   r   r     sO        0 0d H         r#   r   c                   (     e Zd ZdZdZd fd	Z xZS )r   a  
    2D trapezoid kernel.

    The generated kernel is normalized so that it integrates to 1.

    Parameters
    ----------
    radius : number
        Width of the filter kernel, defined as the width of the constant part,
        before it begins to slope down.
    slope : number
        Slope of the filter kernel's tails
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by performing a bilinear interpolation
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    See Also
    --------
    Gaussian2DKernel, Box2DKernel, Tophat2DKernel, RickerWavelet2DKernel,
    Ring2DKernel, AiryDisk2DKernel, Moffat2DKernel

    Examples
    --------
    Kernel response:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import TrapezoidDisk2DKernel
        trapezoid_2D_kernel = TrapezoidDisk2DKernel(20, slope=0.2)
        plt.imshow(trapezoid_2D_kernel, interpolation='none', origin='lower')
        plt.xlabel('x [pixels]')
        plt.ylabel('y [pixels]')
        plt.colorbar()
        plt.show()
    Fr&   c                     t          j        ddd||          | _        t          d|z  d|z  z             | _         t                      j        di | |                                  d S )Nr   r   r   rb   r(   )r   TrapezoidDisk2Dr-   r"   r.   r/   r0   r1   )r2   rY   rd   r4   r5   s       r!   r0   zTrapezoidDisk2DKernel.__init__-  sm    ,Q1feDD5a&j3;6NOO""6"""r#   re   rf   r>   s   @r!   r   r     sO        1 1f H         r#   r   c                   &     e Zd ZdZdZ fdZ xZS )r   u  
    1D Ricker wavelet filter kernel (sometimes known as a "Mexican Hat"
    kernel).

    The Ricker wavelet, or inverted Gaussian-Laplace filter, is a
    bandpass filter. It smooths the data and removes slowly varying
    or constant structures (e.g. Background). It is useful for peak or
    multi-scale detection.

    This kernel is derived from a normalized Gaussian function, by
    computing the second derivative. This results in an amplitude
    at the kernels center of 1. / (sqrt(2 * pi) * width ** 3). The
    normalization is the same as for `scipy.ndimage.gaussian_laplace`,
    except for a minus sign.

    .. note::

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

    Parameters
    ----------
    width : number
        Width of the filter kernel, defined as the standard deviation
        of the Gaussian function from which it is derived.
    x_size : int, optional
        Size in x direction of the kernel array. Default = ⌊8*width +1⌋.
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by linearly interpolating
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    See Also
    --------
    Box1DKernel, Gaussian1DKernel, Trapezoid1DKernel

    Examples
    --------
    Kernel response:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import RickerWavelet1DKernel
        ricker_1d_kernel = RickerWavelet1DKernel(10)
        plt.plot(ricker_1d_kernel, drawstyle='steps')
        plt.xlabel('x [pixels]')
        plt.ylabel('value')
        plt.show()
    Tc                     dt          j        dt           j        z            |dz  z  z  }t          j        |d|          | _        t          d|z            | _         t                      j	        di | d S )Nr&   r      r   r'   r(   )
r*   r+   r,   r   RickerWavelet1Dr-   r"   r.   r/   r0   r2   rP   r4   rB   r5   s       r!   r0   zRickerWavelet1DKernel.__init__w  ss    271ru9--q89	,Y5AA5a%i@@""6"""""r#   rf   r>   s   @r!   r   r   4  sJ        > >@ H# # # # # # # # #r#   r   c                   &     e Zd ZdZdZ fdZ xZS )r   u	  
    2D Ricker wavelet filter kernel (sometimes known as a "Mexican Hat"
    kernel).

    The Ricker wavelet, or inverted Gaussian-Laplace filter, is a
    bandpass filter. It smooths the data and removes slowly varying
    or constant structures (e.g. Background). It is useful for peak or
    multi-scale detection.

    This kernel is derived from a normalized Gaussian function, by
    computing the second derivative. This results in an amplitude
    at the kernels center of 1. / (pi * width ** 4). The normalization
    is the same as for `scipy.ndimage.gaussian_laplace`, except
    for a minus sign.

    .. note::

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

    Parameters
    ----------
    width : number
        Width of the filter kernel, defined as the standard deviation
        of the Gaussian function from which it is derived.
    x_size : int, optional
        Size in x direction of the kernel array. Default = ⌊8*width +1⌋.
    y_size : int, optional
        Size in y direction of the kernel array. Default = ⌊8*width +1⌋.
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by performing a bilinear interpolation
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    See Also
    --------
    Gaussian2DKernel, Box2DKernel, Tophat2DKernel, Ring2DKernel,
    TrapezoidDisk2DKernel, AiryDisk2DKernel, Moffat2DKernel

    Examples
    --------
    Kernel response:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import RickerWavelet2DKernel
        ricker_2d_kernel = RickerWavelet2DKernel(10)
        plt.imshow(ricker_2d_kernel, interpolation='none', origin='lower')
        plt.xlabel('x [pixels]')
        plt.ylabel('y [pixels]')
        plt.colorbar()
        plt.show()
    Fc                     dt           j        |dz  z  z  }t          j        |dd|          | _        t          d|z            | _         t                      j        di | d S )Nr&      r   r'   r(   )	r*   r,   r   RickerWavelet2Dr-   r"   r.   r/   r0   rn   s       r!   r0   zRickerWavelet2DKernel.__init__  sg    255!8+,	,Y1eDD5a%i@@""6"""""r#   rf   r>   s   @r!   r   r   ~  sL        B BH H# # # # # # # # #r#   r   c                   &     e Zd ZdZdZ fdZ xZS )r   u  
    2D Airy disk kernel.

    This kernel models the diffraction pattern of a circular aperture.

    The generated kernel is normalized so that it integrates to 1.

    Parameters
    ----------
    radius : float
        The radius of the Airy disk kernel (radius of the first zero).
    x_size : int, optional
        Size in x direction of the kernel array. Default = ⌊8*radius + 1⌋.
    y_size : int, optional
        Size in y direction of the kernel array. Default = ⌊8*radius + 1⌋.
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by performing a bilinear interpolation
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    See Also
    --------
    Gaussian2DKernel, Box2DKernel, Tophat2DKernel, RickerWavelet2DKernel,
    Ring2DKernel, TrapezoidDisk2DKernel, Moffat2DKernel

    Examples
    --------
    Kernel response:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import AiryDisk2DKernel
        airydisk_2D_kernel = AiryDisk2DKernel(10)
        plt.imshow(airydisk_2D_kernel, interpolation='none', origin='lower')
        plt.xlabel('x [pixels]')
        plt.ylabel('y [pixels]')
        plt.colorbar()
        plt.show()
    Fc                     t          j        ddd|          | _        t          d|z            | _         t                      j        di | |                                  d S )Nr   r   r'   r(   )r   
AiryDisk2Dr-   r"   r.   r/   r0   r1   rX   s      r!   r0   zAiryDisk2DKernel.__init__  sb    '1a885a&jAA""6"""r#   rf   r>   s   @r!   r   r     sJ        4 4l H        r#   r   c                   &     e Zd ZdZdZ fdZ xZS )r   u&  
    2D Moffat kernel.

    This kernel is a typical model for a seeing limited PSF.

    The generated kernel is normalized so that it integrates to 1.

    Parameters
    ----------
    gamma : float
        Core width of the Moffat model.
    alpha : float
        Power index of the Moffat model.
    x_size : int, optional
        Size in x direction of the kernel array. Default = ⌊8*radius + 1⌋.
    y_size : int, optional
        Size in y direction of the kernel array. Default = ⌊8*radius + 1⌋.
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by performing a bilinear interpolation
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    See Also
    --------
    Gaussian2DKernel, Box2DKernel, Tophat2DKernel, RickerWavelet2DKernel,
    Ring2DKernel, TrapezoidDisk2DKernel, AiryDisk2DKernel

    Examples
    --------
    Kernel response:

     .. plot::
        :include-source:

        import matplotlib.pyplot as plt
        from astropy.convolution import Moffat2DKernel
        moffat_2D_kernel = Moffat2DKernel(3, 2)
        plt.imshow(moffat_2D_kernel, interpolation='none', origin='lower')
        plt.xlabel('x [pixels]')
        plt.ylabel('y [pixels]')
        plt.colorbar()
        plt.show()
    Fc                    |dz
  t           j        |z  |z  z  }t          j        |dd||          | _        t          d| j        j        z            | _         t                      j	        di | | 
                                 d S )Nr&   r   g      @r(   )r*   r,   r   Moffat2Dr-   r"   fwhmr.   r/   r0   r1   )r2   gammaalphar4   rB   r5   s        r!   r0   zMoffat2DKernel.__init__G  s     S[RUU]U%:;	oiAueDD5cDK<L6LMM""6"""r#   rf   r>   s   @r!   r   r     sJ        6 6p H        r#   r   c                   *     e Zd ZdZdZdZ fdZ xZS )r   u  
    Create kernel from 1D model.

    The model has to be centered on x = 0.

    Parameters
    ----------
    model : `~astropy.modeling.Fittable1DModel`
        Kernel response function model
    x_size : int, optional
        Size in x direction of the kernel array. Default = ⌊8*width +1⌋.
        Must be odd.
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by linearly interpolating
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    Raises
    ------
    TypeError
        If model is not an instance of `~astropy.modeling.Fittable1DModel`

    See Also
    --------
    Model2DKernel : Create kernel from `~astropy.modeling.Fittable2DModel`
    CustomKernel : Create kernel from list or array

    Examples
    --------
    Define a Gaussian1D model:

        >>> from astropy.modeling.models import Gaussian1D
        >>> from astropy.convolution.kernels import Model1DKernel
        >>> gauss = Gaussian1D(1, 0, 2)

    And create a custom one dimensional kernel from it:

        >>> gauss_kernel = Model1DKernel(gauss, x_size=9)

    This kernel can now be used like a usual Astropy kernel.
    Fc                     t          |t                    r|| _        nt          d           t	                      j        di | d S )NzMust be Fittable1DModelr(   )
isinstancer   r-   	TypeErrorr/   r0   r2   modelr4   r5   s      r!   r0   zModel1DKernel.__init__  sP    e_-- 	7DKK5666""6"""""r#   r6   r>   s   @r!   r   r   Q  sO        4 4l JH# # # # # # # # #r#   r   c                   *     e Zd ZdZdZdZ fdZ xZS )r   u;  
    Create kernel from 2D model.

    The model has to be centered on x = 0 and y = 0.

    Parameters
    ----------
    model : `~astropy.modeling.Fittable2DModel`
        Kernel response function model
    x_size : int, optional
        Size in x direction of the kernel array. Default = ⌊8*width +1⌋.
        Must be odd.
    y_size : int, optional
        Size in y direction of the kernel array. Default = ⌊8*width +1⌋.
    mode : {'center', 'linear_interp', 'oversample', 'integrate'}, optional
        One of the following discretization modes:
            * 'center' (default)
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp'
                Discretize model by performing a bilinear interpolation
                between the values at the corners of the bin.
            * 'oversample'
                Discretize model by taking the average
                on an oversampled grid.
            * 'integrate'
                Discretize model by integrating the
                model over the bin.
    factor : number, optional
        Factor of oversampling. Default factor = 10.

    Raises
    ------
    TypeError
        If model is not an instance of `~astropy.modeling.Fittable2DModel`

    See Also
    --------
    Model1DKernel : Create kernel from `~astropy.modeling.Fittable1DModel`
    CustomKernel : Create kernel from list or array

    Examples
    --------
    Define a Gaussian2D model:

        >>> from astropy.modeling.models import Gaussian2D
        >>> from astropy.convolution.kernels import Model2DKernel
        >>> gauss = Gaussian2D(1, 0, 0, 2, 2)

    And create a custom two dimensional kernel from it:

        >>> gauss_kernel = Model2DKernel(gauss, x_size=9)

    This kernel can now be used like a usual astropy kernel.
    Fc                     d| _         t          |t                    r|| _        nt	          d           t                      j        di | d S )NFzMust be Fittable2DModelr(   )r;   r~   r   r-   r   r/   r0   r   s      r!   r0   zModel2DKernel.__init__  sW    e_-- 	7DKK5666""6"""""r#   )r7   r8   r9   r:   r<   r;   r0   r=   r>   s   @r!   r   r     sO        6 6p HJ# # # # # # # # #r#   r   c                   X     e Zd ZdZ fdZed             Zej        d             Z xZS )r   a>  
    Create filter kernel from list or array.

    Parameters
    ----------
    array : list or array
        Filter kernel array. Size must be odd.

    Raises
    ------
    TypeError
        If array is not a list or array.
    `~astropy.convolution.KernelSizeError`
        If array size is even.

    See Also
    --------
    Model2DKernel, Model1DKernel

    Examples
    --------
    Define one dimensional array:

        >>> from astropy.convolution.kernels import CustomKernel
        >>> import numpy as np
        >>> array = np.array([1, 2, 3, 2, 1])
        >>> kernel = CustomKernel(array)
        >>> kernel.dimension
        1

    Define two dimensional array:

        >>> array = np.array([[1, 1, 1], [1, 2, 1], [1, 1, 1]])
        >>> kernel = CustomKernel(array)
        >>> kernel.dimension
        2
    c                 b    || _         t                                          | j                   d S )N)arrayr/   r0   _array)r2   r   r5   s     r!   r0   zCustomKernel.__init__  s*    
%%%%%r#   c                     | j         S )z&
        Filter kernel array.
        )r   )r2   s    r!   r   zCustomKernel.array  s    
 {r#   c                    t          |t          j                  r%|                    t          j                  | _        nJt          |t                    r&t          j        |t          j                  | _        nt          d          t          |           rt                       | j        dk    }| j        dk    }t          t          j        t          j        ||                              | _        dS )z-
        Filter kernel array setter.
        )dtypezMust be list or array.r&   r   N)r~   r*   ndarrayastypefloat64r   listr   r   r
   r   boolall
logical_orr<   )r2   r   oneszeross       r!   r   zCustomKernel.array
  s    
 eRZ(( 	6,,rz22DKKt$$ 	6(5
;;;DKK4555  	*'))) {c!q RVBM$$>$>??@@r#   )	r7   r8   r9   r:   r0   propertyr   setterr=   r>   s   @r!   r   r     s        $ $L& & & & &   X \A A \A A A A Ar#   r   ) r   numpyr*   astropy.modelingr   astropy.modeling.corer   r   corer   r   r	   utilsr
   r   __all__r"   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r#   r!   <module>r      sv        # # # # # # B B B B B B B B , , , , , , , , , , = = = = = = = =  &  < < < < <x < < <~M M M M Mx M M M`@ @ @ @ @( @ @ @FC C C C C( C C CL8 8 8 8 8X 8 8 8v= = = = =8 = = =@9 9 9 9 9 9 9 9x: : : : :H : : :zG# G# G# G# G#H G# G# G#TK# K# K# K# K#H K# K# K#\= = = = =x = = =@B B B B BX B B BJ?# ?# ?# ?# ?#H ?# ?# ?#DB# B# B# B# B#H B# B# B#JEA EA EA EA EA6 EA EA EA EA EAr#   