
    IR-e"/                     h   d 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 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
 de
          Zd Zd Zd Zd Zd Zd Z d Z!d Z"ej#        $                    dej%        dfddej%        z  ff          d             Z&d Z'd Z(d Z)d Z*d Z+d Z,dS )zF
Tests that relate to using quantities/units on parameters of models.
    N)coordinates)units)Fittable1DModelInputParameterError)Const1D
Gaussian1DPix2Sky_TANRotateNative2Celestial
Rotation2D	BlackBody)	ParameterParameterDefinitionError)assert_quantity_allclose)
UnitsErrorc                   $    e Zd Zed             ZdS )BaseTestModelc                     | S )N )xas     Qlib/python3.11/site-packages/astropy/modeling/tests/test_quantities_parameters.pyevaluatezBaseTestModel.evaluate   s        N)__name__
__module____qualname__staticmethodr   r   r   r   r   r      s-          \  r   r   c                  ~   t          dt          j        z  dt          j        z  dt          j        z            } | j        j        dk    sJ | j        j        t          j        u sJ | j        j        dk    sJ | j        j        t          j        u sJ | j        j        dk    sJ | j        j        t          j        u sJ dS )z
    Basic tests for initializing general models (that do not require units)
    with parameters that have units attached.
       皙?      ?N)	r   uJm	amplitudevalueunitmeanstddevgs    r   test_parameter_quantityr,      s    
 	1qs7AGS13Y//A;####;qs""""6<36;!#8>S    8=ACr   c                     t          dt          j        z  dt          j        z  dt          j        z            } dt          j        z  | _        t          | j        dt          j        z             dt          j        z  | _        t          | j        dt          j        z             dt          j	        z  | _
        t          | j
        dt          j	        z             dt          j        z  | _        t          | j        dt          j        z             dt          j        z  | _        t          | j        dt          j        z             dS )az  
    Make sure that parameters that start off as quantities can be set to any
    other quantity, regardless of whether the units of the new quantity are
    compatible with the original ones.

    We basically leave it up to the evaluate method to raise errors if there
    are issues with incompatible units, and we don't check for consistency
    at the parameter level.
    r   r             N)r   r"   r#   r$   kJr%   r   kmr(   mmr)   sJyr*   s    r   test_parameter_set_quantityr6   -   s     	1qs7AGS13Y//A ad(AKQ[!ad(333XAFQVQX...14xAHQXq14x000 ac'AKQ[!ac'222XAFQVQX.....r   c                      t          dt          j        z  dd          } d}t          j        t
          |          5  d| _        ddd           dS # 1 swxY w Y   dS )ab  
    Check that parameters that have been set to a quantity that are then set to
    a value with no units raise an exception. We do this because setting a
    parameter to a value with no units is ambiguous if units were set before:
    if a parameter is 1 * u.Jy and the parameter is then set to 4, does this mean
    2 without units, or 2 * u.Jy?
    r   r/   r    zVThe .* parameter should be given as a .* because it was originally initialized as a .*matchr0   N)r   r"   r5   pytestraisesr   r%   r+   MESSAGEs     r   test_parameter_lose_unitsr>   N   s     	1qt8Q$$A	   
z	1	1	1                   s   AAAc                      t          ddd          } dt          j        z  | _        t	          | j        dt          j        z             dS )z
    On the other hand, if starting from a parameter with no units, we should be
    able to add units since this is unambiguous.
    r   r/   r    r0   N)r   r"   r5   r%   r   r*   s    r   test_parameter_add_unitsr@   a   s@     	1aAad(AKQ[!ad(33333r   c                     t          ddt          j        z  dt          j        z            } d}t          j        t
          |          5  t          j        | j        _        ddd           n# 1 swxY w Y   d}t          j        t
          |          5  t          j	        | j
        _        ddd           dS # 1 swxY w Y   dS )z
    Test that changing the unit on a parameter does not work. This is an
    ambiguous operation because it's not clear if it means that the value should
    be converted or if the unit should be changed without conversion.
    r   r    zNCannot attach units to parameters that were not initially specified with unitsr8   NzYCannot change the unit attribute directly, instead change the parameter to a new quantity)r   r"   r$   r:   r;   
ValueErrorr5   r%   r'   cmr(   r<   s     r   test_parameter_change_unitrD   m   s3    	1a!#gsQSy))A	  
z	1	1	1    4                             
	  
z	1	1	1  d                 s$   	A,,A03A0B88B<?B<c                     t          dt          j        z  dt          j        z  dt          j        z            } dt          j        z  | _        d| j        _        t          | j        dt          j        z             | j        j        dk    sJ | j        j        t          j        u sJ d}t          j	        t          |          5  dt          j        z  | j        _        ddd           dS # 1 swxY w Y   dS )	zH
    Test that changing the value on a parameter works as expected.
    r   r    r0   r.   zZThe .value property on parameters should be set to unitless values, not Quantity objects.*r8   r/   N)r   r"   r5   r$   r%   r&   r   r'   r:   r;   	TypeErrorr<   s     r   test_parameter_set_valuerG      s   
 	1qt8QWcACi00A ad(AK AKQ[!ad(333;!!!!;qt####	  
y	0	0	0 % %H% % % % % % % % % % % % % % % % % %s   C++C/2C/c                  \   t          dt          j        z  dt          j        z  dt          j        z            } t	          | j        j        dt          j        z             dt          j        z  | j        _        | j        j        dk    sJ | j        j	        t          j        u sJ dt          j
        z  | j        _        | j        j        dk    sJ | j        j	        t          j
        u sJ d}t          j        t          |          5  d| j        _        ddd           dS # 1 swxY w Y   dS )	zK
    Test that the quantity property of Parameters behaves as expected
    r   r       r.   z:The .quantity attribute should be set to a Quantity objectr8   r/   N)r   r"   r5   r$   r   r%   quantitymJyr&   r'   r4   r:   r;   rF   r<   s     r    test_parameter_quantity_propertyrL      sM    	1qt8QWcACi00AQ[11qt8<<< qu9AK;!!!!;qu$$$$ qs7AK;!!!!;qs"""" LG	y	0	0	0 ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !s   D!!D%(D%c                      d} t          j        t          |           5   G d dt                    }d d d            d S # 1 swxY w Y   d S )NzNparameter default 1.0 m does not have units equivalent to the required unit Jyr8   c                   B    e Zd Z edej        z  ej                  ZdS )1test_parameter_default_units_match.<locals>.TestCr!   defaultr'   N)r   r   r   r   r"   r$   r5   r   r   r   r   TestCrO      s*        	#)!$777AAAr   rR   )r:   r;   r   r   )r=   rR   s     r   "test_parameter_default_units_matchrS      s    	  
/w	?	?	? 8 8	8 	8 	8 	8 	8O 	8 	8 	88 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s   ?AA)r'   rQ   r!   r   c                      G  fddt                     }|j        j        t          j        k    sJ |j        j        dk    sJ  |            }|j        j        t          j        k    sJ |j        j        |j        j        cxk    rdk    sn J  |dt          j        z            }|j        j        t          j        k    sJ |j        j        dk    sJ |j        j        dk    sJ  |dt          j        z            }|j        j        t          j        k    sJ |j        j        dk    sJ |j        j        dk    sJ  |dt          j        z            }|j        j        t          j        k    sJ |j        j        dk    sJ |j        j        dk    sJ d}t          j
        t          |          5   |d           ddd           dS # 1 swxY w Y   dS )zG
    Test that default quantities are correctly taken into account
    c                   *    e Zd Z e           ZdS )*test_parameter_defaults.<locals>.TestModelrP   N)r   r   r   r   r   rP   s   r   	TestModelrV      s#        IgD111r   rW   r!   g       @z'.* requires a Quantity for parameter .*r8   N)r   r   r'   r"   r$   rQ   r&   pcr5   r:   r;   r   )r'   rQ   rW   r$   r=   s   ``   r   test_parameter_defaultsrY      sN   2 2 2 2 2 2 2 2M 2 2 2 ;qs"""";#%%%% 		A38qs????3;!#)****s****** 		#)A38qs????393;# 		#*A38qt39 3;# 		#*A38qt393;# 9G	*'	:	:	:  	#                 s   7GGGc                     t          dt          j        z  dt          j        z  dt          j        z            } | j        dt          j        z  z   dt          j        z  k    sJ dt          j        z  | j        z   dt          j        z  k    sJ | j        dz  dt          j        z  k    sJ d| j        z  dt          j        z  k    sJ | j        dt          j        z  z  dt          j        dz  z  k    sJ dt          j        z  | j        z  dt          j        dz  z  k    sJ | j         dt          j        z  k    sJ t          | j                   | j        k    sJ d}t          j        t          |          5  | j        dz    ddd           n# 1 swxY w Y   t          j        t          |          5  d| j        z    ddd           dS # 1 swxY w Y   dS )zp
    Test that arithmetic operations with properties that have units return the
    appropriate Quantities.
    r   r    r0   zPCan only apply 'add' function to dimensionless quantities when other argument .*r8   N)	r   r"   r#   r$   r(   absr:   r;   r   r<   s     r   "test_parameter_quantity_arithmeticr]      s>    	1qs7AGS13Y//A 6QWQS((((GqvQS(((( 6A:!ac'""""qv:!ac'"""" 6QW!qsAv,////Gqv!qsAv,//// F7rACx    w<<16!!!!	  
z	1	1	1  	

              	z	1	1	1  	AF

                 s$   9FFF6GGGc                  0   t          dt          j        z  dt          j        z  dt          j        z            } | j        dt          j        z  k    sJ dt          j        z  | j        k    sJ | j        dk    sJ d| j        k    sJ | j        dt          j        z  k     sJ dt          j        z  | j        k    sJ d}t          j        t          |          5  | j        dk      ddd           n# 1 swxY w Y   t          j        t          |          5  d| j        k     ddd           n# 1 swxY w Y   t          ddgt          j        z  ddgt          j        z  ddgt          j        z            } t          j	        | j        ddgt          j        z  k              sJ t          j	        ddgt          j        z  | j        k              sJ t          j	        | j        ddgk              sJ t          j	        ddg| j        k              sJ t          j        t          |          5  | j        dd	gk      ddd           n# 1 swxY w Y   t          j        t          |          5  dd	g| j        k     ddd           dS # 1 swxY w Y   dS )
zG
    Basic test of comparison operations on properties with units.
    r   r    r0   zQCan only apply 'less' function to dimensionless quantities when other argument .*r8   Ng?r/   r.   )
r   r"   r#   r$   r(   r:   r;   r   npallr<   s     r   "test_parameter_quantity_comparisonra     sh   
 	1qs7AGS13Y//A 6QWqs7af6Q;;;;;;;;6AGqs7QV	  
z	1	1	1  	

               
z	1	1	1  	AF

               	Aq6AC<!Q!#SzAC/?@@A6!&QFQSL()))))61a&13,!&()))))6!&QF"#####61a&AF"#####	z	1	1	1  	!Q               
z	1	1	1  	
A                 sH   C00C47C4D..D25D20I

II0JJJc                      t                       t          j        ddt          j                  } dt          j        z  }t          | j        | j        |          }t          d          }||z   d S )Ngffffff@i)radecr'         )	r	   coordSkyCoordr"   degr
   rc   rd   r   )
sky_coordslon_polen2crots       r   test_parameters_compound_modelsrn   H  s[    MMM3Cae<<<JQU{H
 

I
IC
R..C#IIIIr   c                  n    t           j        } d| z  }t          |          } |d| z            |k    sJ dS )z2Regression test for bug reproducer in issue #13133g      4g      7N)r"   ABmagr   )r'   cmodels      r   test_magunit_parameterrs   Q  sD     7DAAJJE5!######r   c                     dt           j        z  } t          dt           j        z  t          j        d                    } G d dt                    } |dt           j        z  t          j        t          j        d                              }|j        t          j        d          k    sJ t           ||            ||                      dS ) Regression test for issue #14511ip  i  r   )temperaturescalec                   N    e Zd Z edddej        ej        ej                  Z	dS )(test_log_getter.<locals>.CustomBlackBodyrw   r   r   NrQ   boundsgettersetterr'   N)
r   r   r   r   r_   logexpr"   dimensionless_unscaledrw   r   r   r   CustomBlackBodyry   a  s=        	66)
 
 
r   r   N)	r"   AAr   KQuantityr_   r   rw   r   )r   mdl_baser   mdls       r   test_log_getterr   [  s     	qtATACZqz!}}EEEH
 
 
 
 
) 
 
 
 /dQSj
26!998M8M
N
N
NC9q		!!!!SSVVXXa[[11111r   c                  6   dt           j        z  } t          dt           j        z  dt           j        z            } G d dt                    } |t          j        dt           j        z            t          j        dt           j        z                      }|j        t          j        dt           j        z            k    sJ |j        j        t          j        d          dz  k    sJ |j        j        t           j        k    sJ |j        t          j        dt           j        z            k    sJ |j        j        t          j        d          dz  k    sJ |j        j        t           j        k    sJ t           ||            ||                      dS )	ru   r       r/   )r(   r)   c                       e Zd Z eddej        z  dej        ej        ej                  Z	 eddej        z  dej        ej        ej                  Z
dS )*test_sqrt_getter.<locals>.CustomGaussian1Dr(   r   rz   r{   r)   N)r   r   r   r   r"   r$   r_   sqrtsquarer(   r)   r   r   r   CustomGaussian1Dr   v  sx        yG79
 
 
 G79
 
 
r   r   r0   N)
r"   r$   r   r_   r   r(   _internal_value_internal_unitr)   r   )r   r   r   r   s       r   test_sqrt_getterr   p  so    	
ACArACxAC888H
 
 
 
 
: 
 
 
$ 
QS 1 1"'!ac':J:J
K
K
KC8rwrACx(((((( BGBKK1$444448"ac)))):QS))))))
"bgajjAo5555:$++++SSVVXXa[[11111r   )-__doc__numpyr_   r:   astropyr   rg   r   r"   astropy.modeling.corer   r   astropy.modeling.modelsr   r   r	   r
   r   r   astropy.modeling.parametersr   r   astropy.tests.helperr   astropy.unitsr   r   r,   r6   r>   r@   rD   rG   rL   rS   markparametrizer$   rY   r]   ra   rn   rs   r   r   r   r   r   <module>r      s@         ( ( ( ( ( (       F F F F F F F F                L K K K K K K K 9 9 9 9 9 9 $ $ $ $ $ $    O        / / /B  &	4 	4 	4  4% % %4! ! !:	8 	8 	8 ,SzD!ac'?.KLL. . ML.b     F& & &R  $ $ $2 2 2*#2 #2 #2 #2 #2r   