
    HR-e              	          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 j        ee                              d
             Zej                            de          d             Zej                            d	 e e j        ee                              d             Zej                            d	 e e j        ee                              d             Z ej                            de          d             Z!ej        "                    e d          ej        j#        d                         Z$ej        "                    e d          d             Z%ej        "                    e d          d             Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d Z.dS )    N)assert_allclose)discretize_model)Box1DBox2D
Gaussian1D
Gaussian2DRickerWavelet1DRickerWavelet2D)	models_1D	models_2D)create_model)	HAS_SCIPY)centerlinear_interp
oversample)model_classmodec                 :   | t           k    r|dk    rt          j        d           t          |          }t	          | |          }t          |t          |          d         |          }t          |                                t          |          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?atolN)r   pytestskipr   r   r   r   sumr   r   
parametersmodelvaluess        Ilib/python3.11/site-packages/astropy/convolution/tests/test_discretize.pytest_pixel_sum_1Dr%      s     e 0 0?@@@;'Jj11EeY{%;G%D4PPPFFJJLL)K"8"D6RRRRRR    r   c                     t          ddd          }t          j        dd          } ||          }t          |d|           }t	          ||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_valuess        r$   test_gaussian_eval_1Dr1   +   sb     q!R  E
	$AU1XXF"5+DAAAKFKe444444r&   c                 ^   | t           k    r|dk    rt          j        d           t          |          }t	          | |          }t          |t          |          d         t          |          d         |          }t          |                                t          |          d         d           d	S )
r   r   r   r   y_limr   r   r   r   Nr   r   r   r   r   r   r   r   r    s        r$   test_pixel_sum_2Dr5   8   s     e 0 0?@@@;'Jj11E+w'+w'	  F FJJLL)K"8"D6RRRRRRr&   c                 n   | t           k    r|dk    rt          j        d           t          |          }t	          | |          }t          ||z   t          |          d         t          |          d         |          }dt          |          d         z  }t          |                                |d	           d
S )z_
    Test if the sum of all pixels of a compound model corresponds nearly to the integral.
    r   r   r   r3   r      r   r   r   Nr4   )r   r   r!   r"   r#   model_integrals         r$   test_pixel_sum_compound_2Dr9   N   s     e 0 0?@@@;'Jj11E+w'+w'	  F ;/
;;NFJJLL.v>>>>>>r&   c                    t          ddddd          }t          j        dd          }t          j        dd          }t          j        ||          \  }} |||          }t	          |dd|           }t          ||d           d	S )
zs
    Discretize Gaussian with different modes and check
    if result is at least similar to Gaussian2D.eval()
    {Gz?r   r(      r<   r=   r   r   Nr   r-   r.   meshgridr   r   )r   r"   r/   yr#   r0   s         r$   test_gaussian_eval_2DrB   f   s     tQ1a((E
	"aA
	"aA;q!DAqU1a[[F"5'7FFFKFKd333333r&   zRequires scipy)reasonc            	      f   t          ddddd          t          ddddd          t          ddddd          g} t          j        dd          }t          j        dd          }t          j        ||          \  }}| D ]3} |||          }t	          |ddd	          }t          ||d
           4dS )z1
    Discretize Gaussian with integrate mode
    r;   r   r7   r(   r<   r=   r>   	integrater   r   Nr?   )
model_listr/   rA   r"   r#   r0   s         r$   $test_gaussian_eval_2D_integrate_moderG   x   s     	4Aq!$$4Aq!$$4Aq!$$J 		"aA
	"aA;q!DAq 8 8q!&ugw[QQQ$777778 8r&   c                      t          ddd          } t          | ddd          }t          |                                t	          j        dt          j        z            dz  d	
           dS )zN
    Test subpixel accuracy of the integrate mode with gaussian 1D model.
    r(   r   皙?r7   rE   d   r   factorr7   h㈵>r   N)r   r   r   r   r-   sqrtpi)gauss_1Dr#   s     r$   test_subpixel_gauss_1DrS      sc    
 !Q$$Hhk#NNNFFJJLL"'!be)"4"4s":IIIIIIr&   c                      t          ddddd          } t          | dddd          }t          |                                dt          j        z  d	z  d
           dS )zN
    Test subpixel accuracy of the integrate mode with gaussian 2D model.
    r(   r   rI   rJ   rE   rL   rM   r7   r;   rO   r   N)r   r   r   r   r-   rQ   )gauss_2Dr#   s     r$   test_subpixel_gauss_2DrV      s`    
 !Q3,,Hh{SVWWWFFJJLL!be)d"2AAAAAAr&   c                  x    d } t          | d          }t          |t          j        dd          dz             dS )z7
    Test discretize when a 1d function is passed.
    c                     | dz  S Nr7    r/   s    r$   fz&test_discretize_callable_1d.<locals>.f       !tr&      r_   r`   r7   N)r   r   r-   r.   )r\   rA   s     r$   test_discretize_callable_1dra      sI    
   	G$$AAryQ''1,-----r&   c                      d } t          | dd          }t          j        d          dz
  \  }}|dz  |dz  z   }t          ||           dS )z7
    Test discretize when a 2d function is passed.
    c                     | dz  |dz  z   S rY   rZ   r/   rA   s     r$   r\   z&test_discretize_callable_2d.<locals>.f       !tad{r&   r^   )   rf      r7   N)r   r-   indicesr   )r\   actualrA   r/   desireds        r$   test_discretize_callable_2drk      sc    
   a'22F:h!#DAqdQTkGFG$$$$$r&   c                      t          j        t          d          5  t          t	          d          d           ddd           dS # 1 swxY w Y   dS )z
    Test type exception.
    zModel must be callable\.matchr   irf   N)r   raises	TypeErrorr   floatrZ   r&   r$   test_type_exceptionrs      s     
y(C	D	D	D . .q9---. . . . . . . . . . . . . . . . . .s   AAAc                      d } t          j        t          d          5  t          | dd           ddd           dS # 1 swxY w Y   dS )z&
    Test dimension exception 1d.
    c                     | dz  S rY   rZ   r[   s    r$   r\   z test_dim_exception_1d.<locals>.f   r]   r&   z*y_range should not be input for a 1D modelrm   ro   Nr   rp   
ValueErrorr   r\   s    r$   test_dim_exception_1dry      s    
   
z)V	W	W	W 2 2Iy1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2   >AAc                      d } t          j        t          d          5  t          | d           ddd           dS # 1 swxY w Y   dS )z&
    Test dimension exception 2d.
    c                     | dz  |dz  z   S rY   rZ   rd   s     r$   r\   z test_dim_exception_2d.<locals>.f   re   r&   z(y_range must be specified for a 2D modelrm   ro   Nrv   rx   s    r$   test_dim_exception_2dr}      s    
   
z)T	U	U	U ' 'I&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '   =AAc                      d } t          j        t          d          5  t          | d           d d d            d S # 1 swxY w Y   d S )Nc                     | dz  |dz  z   S rY   rZ   rd   s     r$   r\   z'test_float_x_range_exception.<locals>.f   re   r&   zVThe difference between the upper and lower limit of 'x_range' must be a whole number\.rm   g/$$g(\u&@rv   rx   s    r$   test_float_x_range_exceptionr      s       

 
 
 . . 	,---. . . . . . . . . . . . . . . . . .r~   c                      d } t          j        t          d          5  t          | dd           d d d            d S # 1 swxY w Y   d S )Nc                     | dz  |dz  z   S rY   rZ   rd   s     r$   r\   z'test_float_y_range_exception.<locals>.f   re   r&   zVThe difference between the upper and lower limit of 'y_range' must be a whole number\.rm   ro   r   rv   rx   s    r$   test_float_y_range_exceptionr      s       

 
 
 9 9 	I'78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9rz   c                     t          ddddd          } t          | ddgd	d
gdd          }t          j        |          }t          j        |                                |j                  }t          | ddgd	d
gdd          }t          | ddgd	d
gd          }|j        dk    sJ t          |dd           |dk    sJ t          ||           d S )Ng      ?g      @g     @_@g      ?r=   )	amplitudex_meany_meanx_stddevy_stddevr   
   rL      r   )x_rangey_ranger   rN   r(   r   )r   r   r   )#   r   gDl?r,   r   )   rg   )r   r   r-   maxunravel_indexargmaxshaper   )rU   r#   vmaxvmax_yxvalues_osf1values_centers         r$   test_discretize_oversampler      s   c%$  H 1b'C:LQS  F 6&>>Dv}}==G"1b'C:LQR  K %1b'C:H  M <8####D%d++++gM;/////r&   )/	itertoolsnumpyr-   r   numpy.testingr   astropy.convolution.utilsr   "astropy.modeling.functional_modelsr   r   r   r   r	   r
   %astropy.modeling.tests.example_modelsr   r   "astropy.modeling.tests.test_modelsr   "astropy.utils.compat.optional_depsr   modestest_models_1Dtest_models_2Dmarkparametrizelistproductr%   r1   r5   r9   rB   skipifslowrG   rS   rV   ra   rk   rs   ry   r}   r   r   r   rZ   r&   r$   <module>r      s            ) ) ) ) ) ) 6 6 6 6 6 6                G F F F F F F F ; ; ; ; ; ; 8 8 8 8 8 8111e_5e_5 TT"3)"3NE"J"JKK 
S 
S 
S ''	5 	5 ('	5 TT"3)"3NE"J"JKK S S S& TT"3)"3NE"J"JKK ? ? ?* ''4 4 ('4" 	M*:;;8 8  <;8* 	M*:;;J J <;J 	M*:;;B B <;B	. 	. 	.% % %. . .	2 	2 	2	' 	' 	'. . .9 9 90 0 0 0 0r&   