a
    ߙfb|                     @   s  d dl Z d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZ d dlmZmZ d dlmZ d dlmZ g dZe	e
egZeeegZejd	ee eed
d Zejdedd Zejd	ee eedd Zejd	ee eedd Z ejdedd Z!ej"ddd Z#ej"ddd Z$ej"ddd Z%dd Z&dd Z'd d! Z(d"d# Z)d$d% Z*d&d' Z+d(d) Z,d*d+ Z-dS ),    N)assert_allclose)discretize_model)
Gaussian1DBox1DRickerWavelet1D
Gaussian2DBox2DRickerWavelet2D)	models_1D	models_2D)create_model)	HAS_SCIPY)centerZlinear_interp
oversample)model_classmodec                 C   s`   | t kr|dkrtd t|  }t| |}t|t|  d |d}t| t|  d dd dS )	K
    Test if the sum of all pixels corresponds nearly to the integral.
    r   )Non integrating mode. Skip integral test.x_limr   integral-C6?ZatolN)r   pytestskipr
   r   r   r   sumr   r   
parametersmodelvalues r    Hlib/python3.9/site-packages/astropy/convolution/tests/test_discretize.pytest_pixel_sum_1D   s    

r"   r   c                 C   s@   t ddd}tdd}||}t|d| d}t||dd	 d
S )zt
    Discretize Gaussian with different modes and check
    if result is at least similar to Gaussian1D.eval().
       r      e   )r%   r&   r   MbP?r   N)r   nparanger   r   )r   r   xr   disc_valuesr    r    r!   test_gaussian_eval_1D$   s
    r,   c                 C   sj   | t kr|dkrtd t|  }t| |}t|t|  d t|  d |d}t| t|  d dd d	S )
r   r   r   r   y_limr   r   r   r   Nr   r   r   r   r   r   r   r   r   r    r    r!   test_pixel_sum_2D1   s    

r/   c                 C   sv   | t kr|dkrtd t|  }t| |}t|| t|  d t|  d |d}dt|  d  }t| |dd	 d
S )z_
    Test if the sum of all pixels of a compound model corresponds nearly to the integral.
    r   r   r   r-   r      r   r   r   Nr.   )r   r   r   r   r   Zmodel_integralr    r    r!   test_pixel_sum_compound_2DA   s    

r1   c                 C   sd   t ddddd}tdd}tdd}t||\}}|||}t|dd| d}t||dd d	S )
zs
    Discretize Gaussian with different modes and check
    if result is at least similar to Gaussian2D.eval()
    {Gz?r   r#      r3   r4   r   r   Nr   r(   r)   Zmeshgridr   r   )r   r   r*   yr   r+   r    r    r!   test_gaussian_eval_2DS   s    
r8   znot HAS_SCIPYc                  C   s   t dddddt dddddt dddddg} tdd}tdd}t||\}}| D ],}|||}t|dddd	}t||dd
 qZdS )z1
    Discretize Gaussian with integrate mode
    r2   r   r0   r#   r3   r4   r5   	integrater   r   Nr6   )Z
model_listr*   r7   r   r   r+   r    r    r!   $test_gaussian_eval_2D_integrate_modee   s    
r:   c                  C   sB   t ddd} t| dddd}t| tdtj d d	d
 dS )zN
    Test subpixel accuracy of the integrate mode with gaussian 1D model.
    r#   r   皙?r0   r9   d   r   factorr0   h㈵>r   N)r   r   r   r   r(   Zsqrtpi)Zgauss_1Dr   r    r    r!   test_subpixel_gauss_1Dy   s    rC   c                  C   sB   t ddddd} t| ddddd}t| dtj d	 d
d dS )zN
    Test subpixel accuracy of the integrate mode with gaussian 2D model.
    r#   r   r;   r<   r9   r>   r?   r0   r2   rA   r   N)r   r   r   r   r(   rB   )gauss_2Dr   r    r    r!   test_subpixel_gauss_2D   s    rE   c                  C   s,   dd } t | d}t|tddd  dS )z7
    Test discretize when a 1d function is passed.
    c                 S   s   | d S Nr0   r    r*   r    r    r!   f   s    z&test_discretize_callable_1d.<locals>.f   rJ   rK   r0   N)r   r   r(   r)   )rH   r7   r    r    r!   test_discretize_callable_1d   s    
rL   c                  C   sD   dd } t | dd}tdd \}}|d |d  }t|| dS )z7
    Test discretize when a 2d function is passed.
    c                 S   s   | d |d  S rF   r    r*   r7   r    r    r!   rH      s    z&test_discretize_callable_2d.<locals>.frI   )   rN      r0   N)r   r(   indicesr   )rH   Zactualr7   r*   Zdesiredr    r    r!   test_discretize_callable_2d   s
    rQ   c                  C   sP   t t} ttdd W d   n1 s.0    Y  | jjd dksLJ dS )z
    Test type exception.
    r   irN   NzModel must be callable.)r   raises	TypeErrorr   floatvalueargs)excr    r    r!   test_type_exception   s    ,rY   c                  C   sV   dd } t t}t| dd W d   n1 s40    Y  |jjd dksRJ dS )z&
    Test dimension exception 1d.
    c                 S   s   | d S rF   r    rG   r    r    r!   rH      s    z test_dim_exception_1d.<locals>.frR   Nr   z)y range specified, but model is only 1-d.r   rS   
ValueErrorr   rV   rW   rH   rX   r    r    r!   test_dim_exception_1d   s    *r]   c                  C   sT   dd } t t}t| d W d   n1 s20    Y  |jjd dksPJ dS )z&
    Test dimension exception 2d.
    c                 S   s   | d |d  S rF   r    rM   r    r    r!   rH      s    z test_dim_exception_2d.<locals>.frR   Nr   z'y range not specified, but model is 2-drZ   r\   r    r    r!   test_dim_exception_2d   s    (r^   c                  C   sT   dd } t t}t| d W d    n1 s20    Y  |jjd dksPJ d S )Nc                 S   s   | d |d  S rF   r    rM   r    r    r!   rH      s    z'test_float_x_range_exception.<locals>.fg/$$g(\u&@r   zUThe difference between the upper and lower limit of 'x_range' must be a whole number.rZ   r\   r    r    r!   test_float_x_range_exception   s    (r`   c                  C   sV   dd } t t}t| dd W d    n1 s40    Y  |jjd dksRJ d S )Nc                 S   s   | d |d  S rF   r    rM   r    r    r!   rH      s    z'test_float_y_range_exception.<locals>.frR   r_   r   zUThe difference between the upper and lower limit of 'y_range' must be a whole number.rZ   r\   r    r    r!   test_float_y_range_exception   s    *ra   c                  C   s   t dddddd} t| ddgd	d
gddd}t|}t| |j}t| ddgd	d
gddd}t| ddgd	d
gdd}|jdksJ t|ddd |dksJ t|| d S )Ng      ?g      @g     @_@g      ?r4   )Z	amplitudeZx_meanZy_meanZx_stddevZy_stddevr   
   r>      r   )x_rangey_ranger   r@   r#   r   )rd   re   r   )#   rb   gDl?r'   r   )   rO   )r   r   r(   maxZunravel_indexZargmaxshaper   )rD   r   ZvmaxZvmax_yxZvalues_osf1Zvalues_centerr    r    r!   test_discretize_oversample   s0    
rj   ).	itertoolsr   Znumpyr(   Znumpy.testingr   Zastropy.convolution.utilsr   Z"astropy.modeling.functional_modelsr   r   r   r   r   r	   Z%astropy.modeling.tests.example_modelsr
   r   Z"astropy.modeling.tests.test_modelsr   Z"astropy.utils.compat.optional_depsr   ZmodesZtest_models_1DZtest_models_2DZmarkZparametrizelistproductr"   r,   r/   r1   r8   Zskipifr:   rC   rE   rL   rQ   rY   r]   r^   r`   ra   rj   r    r    r    r!   <module>   sF    










	

	
			