B
    d$                 @   s  d dl Z d dlZddlmZmZmZ ddlmZm	Z	m
Z
 d dlmZ d dlmZmZ d dlmZ dd	d
ddddddddddddgZdd ZG dd deZG dd	 d	eZG dd deZG dd deZG dd deZG dd deZG dd deZG d d deZG d!d deZG d"d deZG d#d deZG d$d deZG d%d deZ G d&d deZ!G d'd( d(eZ"G d)d
 d
eZ#ed*dd+G d,d- d-eZ$ed*dd+G d.d/ d/eZ%dS )0    N   )Kernel1DKernel2DKernel)has_even_axisraise_even_kernel_exceptionKernelSizeError)models)Fittable1DModelFittable2DModel)
deprecatedGaussian1DKernelGaussian2DKernelCustomKernelBox1DKernelBox2DKernelTophat2DKernelTrapezoid1DKernelRickerWavelet1DKernelRickerWavelet2DKernelAiryDisk2DKernelMoffat2DKernelModel1DKernelModel2DKernelTrapezoidDisk2DKernelRing2DKernelc             C   s&   t | }|d dkr|d S |S d S )N   r   r   )mathceil)valuei r!   h/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/astropy/convolution/kernels.py_round_up_to_odd_integer   s    
r#   c                   s(   e Zd ZdZdZdZ fddZ  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.

    Parameters
    ----------
    stddev : number
        Standard deviation of the Gaussian kernel.
    x_size : int, optional
        Size of the kernel array. Default = ⌊8*stddev+1⌋.
    mode : str, 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                sZ   t dtdtj |  d|| _td| | _t j	f | t
d| j  | _d S )Ng      ?r   r      )r	   Z
Gaussian1Dnpsqrtpi_modelr#   _default_sizesuper__init__abs_arraysum_truncation)selfstddevkwargs)	__class__r!   r"   r+   S   s
    
zGaussian1DKernel.__init__)__name__
__module____qualname____doc__
_separable_is_boolr+   __classcell__r!   r!   )r3   r"   r      s   3c                   s*   e Zd ZdZdZdZd fdd	Z  ZS )	r   u  
    2D Gaussian filter kernel.

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

    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 : str, 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                sv   |d kr|}t jddtj | |  dd|||d| _tdt||g | _t j	f | t
d| j  | _d S )Ng      ?r   r   )x_stddevy_stddevthetar$   )r	   Z
Gaussian2Dr%   r'   r(   r#   maxr)   r*   r+   r,   r-   r.   r/   )r0   r<   r=   r>   r2   )r3   r!   r"   r+      s    zGaussian2DKernel.__init__)Nr;   )r4   r5   r6   r7   r8   r9   r+   r:   r!   r!   )r3   r"   r   [   s   ;c                   s(   e Zd ZdZdZdZ fddZ  ZS )r   a  
    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.

    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 : str, optional
        One of the following discretization modes:
            * 'center'
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp' (default)
                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
    --------
    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                sF   t d| d|| _t|| _d|d< t jf | d| _|   d S )Ng      ?r   linear_interpmode)	r	   ZBox1Dr(   r#   r)   r*   r+   r/   	normalize)r0   widthr2   )r3   r!   r"   r+      s    
zBox1DKernel.__init__)r4   r5   r6   r7   r8   r9   r+   r:   r!   r!   )r3   r"   r      s   7c                   s(   e Zd ZdZdZdZ fddZ  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 artifact, when applied repeatedly to the same data.

    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 : str, optional
        One of the following discretization modes:
            * 'center'
                Discretize model by taking the value
                at the center of the bin.
            * 'linear_interp' (default)
                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, 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                sN   t d|d  dd||| _t|| _d|d< t jf | d| _|   d S )Ng      ?r   r   r@   rA   )	r	   ZBox2Dr(   r#   r)   r*   r+   r/   rB   )r0   rC   r2   )r3   r!   r"   r+   '  s    
zBox2DKernel.__init__)r4   r5   r6   r7   r8   r9   r+   r:   r!   r!   )r3   r"   r      s   9c                   s    e Zd ZdZ fddZ  ZS )r   a  
    2D Tophat filter kernel.

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

    Parameters
    ----------
    radius : int
        Radius of the filter kernel.
    mode : str, 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                sF   t dtj|d   dd|| _td| | _t jf | d| _	d S )Ng      ?r   r   )
r	   ZDisk2Dr%   r'   r(   r#   r)   r*   r+   r/   )r0   radiusr2   )r3   r!   r"   r+   c  s     zTophat2DKernel.__init__)r4   r5   r6   r7   r+   r:   r!   r!   )r3   r"   r   0  s   2c                   s    e Zd ZdZ fddZ  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.

    Parameters
    ----------
    radius_in : number
        Inner radius of the ring kernel.
    width : number
        Width of the ring kernel.
    mode : str, 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 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                sX   || }t dtj|d |d    dd||| _td| | _t jf | d| _	d S )Ng      ?r   r   )
r	   ZRing2Dr%   r'   r(   r#   r)   r*   r+   r/   )r0   Z	radius_inrC   r2   Z
radius_out)r3   r!   r"   r+     s    zRing2DKernel.__init__)r4   r5   r6   r7   r+   r:   r!   r!   )r3   r"   r   j  s   2c                   s&   e Zd ZdZdZd fdd	Z  ZS )r   a  
    1D trapezoid kernel.

    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 : str, 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()
    F      ?c                sD   t dd||| _t|d|  | _t jf | d| _|   d S )Nr   r   g       @)	r	   ZTrapezoid1Dr(   r#   r)   r*   r+   r/   rB   )r0   rC   sloper2   )r3   r!   r"   r+     s
    zTrapezoid1DKernel.__init__)rE   )r4   r5   r6   r7   r9   r+   r:   r!   r!   )r3   r"   r     s   /c                   s&   e Zd ZdZdZd fdd	Z  ZS )r   a  
    2D trapezoid kernel.

    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 : str, 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()

    F      ?c                sJ   t ddd||| _td| d|  | _t jf | d| _|   d S )Nr   r   r   g       @)	r	   ZTrapezoidDisk2Dr(   r#   r)   r*   r+   r/   rB   )r0   rD   rF   r2   )r3   r!   r"   r+     s
    zTrapezoidDisk2DKernel.__init__)rG   )r4   r5   r6   r7   r9   r+   r:   r!   r!   )r3   r"   r     s   1c                   s$   e Zd ZdZdZ fddZ  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 : str, 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                sf   dt dt j |d   }t|d|| _td| | _t j	f | t 
| j | jj | _d S )Ng      ?r      r   r$   )r%   r&   r'   r	   ZRickerWavelet1Dr(   r#   r)   r*   r+   r,   r-   r.   sizer/   )r0   rC   r2   	amplitude)r3   r!   r"   r+   `  s
    zRickerWavelet1DKernel.__init__)r4   r5   r6   r7   r9   r+   r:   r!   r!   )r3   r"   r     s   Ac                   s$   e Zd ZdZdZ fddZ  ZS )r   ub	  
    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 : str, 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                s^   dt j|d   }t|dd|| _td| | _t jf | t 	| j
 | j
j | _d S )Ng      ?   r   r$   )r%   r'   r	   ZRickerWavelet2Dr(   r#   r)   r*   r+   r,   r-   r.   rI   r/   )r0   rC   r2   rJ   )r3   r!   r"   r+     s
    zRickerWavelet2DKernel.__init__)r4   r5   r6   r7   r9   r+   r:   r!   r!   )r3   r"   r   h  s   Dc                   s$   e Zd ZdZdZ fddZ  ZS )r   u  
    2D Airy disk kernel.

    This kernel models the diffraction pattern of a circular aperture. This
    kernel is normalized to a peak value of 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 : str, 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, 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                s@   t ddd|| _td| | _t jf | |   d | _d S )Nr   r   r$   )	r	   Z
AiryDisk2Dr(   r#   r)   r*   r+   rB   r/   )r0   rD   r2   )r3   r!   r"   r+     s
    zAiryDisk2DKernel.__init__)r4   r5   r6   r7   r9   r+   r:   r!   r!   )r3   r"   r     s   4c                   s$   e Zd ZdZdZ fddZ  ZS )r   u  
    2D Moffat kernel.

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

    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 : str, 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                s\   |d t j| |  }t|dd||| _td| jj | _t j	f | | 
  d | _d S )Ng      ?r   g      @)r%   r'   r	   ZMoffat2Dr(   r#   Zfwhmr)   r*   r+   rB   r/   )r0   gammaalphar2   rJ   )r3   r!   r"   r+   .  s    zMoffat2DKernel.__init__)r4   r5   r6   r7   r9   r+   r:   r!   r!   )r3   r"   r     s   5c                   s(   e Zd ZdZdZdZ fddZ  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 : str, 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                s,   t |tr|| _ntdt jf | d S )NzMust be Fittable1DModel)
isinstancer
   r(   	TypeErrorr*   r+   )r0   modelr2   )r3   r!   r"   r+   r  s    
zModel1DKernel.__init__)r4   r5   r6   r7   r8   r9   r+   r:   r!   r!   )r3   r"   r   9  s   5c                   s(   e Zd ZdZdZdZ fddZ  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 : str, 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                s2   d| _ t|tr|| _ntdt jf | d S )NFzMust be Fittable2DModel)r8   rN   r   r(   rO   r*   r+   )r0   rP   r2   )r3   r!   r"   r+     s
    
zModel2DKernel.__init__)r4   r5   r6   r7   r9   r8   r+   r:   r!   r!   )r3   r"   r   z  s   8c               @   s   e Zd ZdZdZdd ZdS )	PSFKernelz=
    Initialize filter kernel from astropy PSF instance.
    Fc             C   s   t dd S )NzNot yet implemented)NotImplementedError)r0   r!   r!   r"   r+     s    zPSFKernel.__init__N)r4   r5   r6   r7   r8   r+   r!   r!   r!   r"   rQ     s   rQ   c                   s:   e Zd ZdZ fddZedd Zejdd Z  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                s   || _ t | j d S )N)arrayr*   r+   r-   )r0   rS   )r3   r!   r"   r+     s    zCustomKernel.__init__c             C   s   | j S )z&
        Filter kernel array.
        )r-   )r0   r!   r!   r"   rS     s    zCustomKernel.arrayc             C   s   t |tjr|tj| _n&t |tr:tj|tjd| _ntdt	| rPt
  | jdk}| jdk}ttt||| _d| _dS )z,
        Filter kernel array setter
        )ZdtypezMust be list or array.g      ?r   g        N)rN   r%   ZndarrayZastypeZfloat64r-   listrS   rO   r   r   boolall
logical_orr9   r/   )r0   rS   ZonesZzerosr!   r!   r"   rS     s    


)	r4   r5   r6   r7   r+   propertyrS   setterr:   r!   r!   )r3   r"   r     s   %z4.0)alternativec               @   s   e Zd ZdS )MexicanHat1DKernelN)r4   r5   r6   r!   r!   r!   r"   r[     s   r[   c               @   s   e Zd ZdS )MexicanHat2DKernelN)r4   r5   r6   r!   r!   r!   r"   r\     s   r\   )&r   numpyr%   corer   r   r   utilsr   r   r   Zastropy.modelingr	   Zastropy.modeling.corer
   r   Zastropy.utils.decoratorsr   __all__r#   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rQ   r   r[   r\   r!   r!   r!   r"   <module>   s@   
?KDF:<:<LO?CAE
I