
    IR-e0                         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
 ddlmZmZmZmZ ddlmZ ddlmZ d	Zd
 Zd Z G d de
          Z G d d          Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#dS )zA
Tests that relate to evaluating models with quantity parameters
    N)assert_allclose)units)Model)
Gaussian1DPix2Sky_TANScaleShift)assert_quantity_allclose)
UnitsErrorzT{}: Units of input 'x', {}.*, could not be converted to required input units of {}.*c                     t          ddd          } t          dt          j        z  dt          j        z  dt          j        z            }t	           |dt          j        z             | d          t          j        z             t          j        t          t          	                    ddd                    5   |d           ddd           n# 1 swxY w Y   t	           |d           | d          t          j        z             t           |d	t          j        z            j         | d
                     t          j        t          t          	                    ddd                    5   |dt          j        z             ddd           n# 1 swxY w Y   t          j        t          d          5   | dt          j        z             ddd           dS # 1 swxY w Y   dS )zn
    Test evaluation of a single model with Quantity parameters that do
    not explicitly require units.
       g?r    zm matchNr   gMb@?      ?sm   zACan only apply 'subtract' function to dimensionless quantities .*)r   uJr   r
   pytestraisesr   MESSAGEformatr   kmvaluer   )ggqs     Qlib/python3.11/site-packages/astropy/modeling/tests/test_quantities_evaluation.pytest_evaluate_with_quantitiesr       sk    	1aA	AGQWcACi	0	0B RRAC[[!!A$$*555 
zb$)O)O	P	P	P  
1               RRUUAAaDD13J/// BBv}%%+QQsVV444 
zc3)O)O	P	P	P  
1qs7               
R
 
 
   	
!ac'


	                 s6   ;CCC6FF"FG''G+.G+c                     t          dt          j        z  dt          j        z  dt          j        z            } t	          j        t          t                              ddd                    5   | dt          j	        z             d	d	d	           n# 1 swxY w Y   t           | dt          j	        z  d
t          j                    i           | dt          j        z                       d	S )zN
    We now make sure that equivalencies are correctly taken into account
    r   
      r   PHznmr      Nxequivalenciesg3<u#@)r   r   Jyr%   r   r   r   r   r   r$   r
   spectral)r   s    r   /test_evaluate_with_quantities_and_equivalenciesr,   E   s   
 	1qt8R!$YAD11A 
zeT)R)R	S	S	S  	"qu*               	"qu*S!*,,$7888!!<MPQPT<T:U:U    s   .BBBc                       e Zd ZdZdZd ZdS )MyTestModelr#   r   c                 L    t          d|           t          d|           ||z  S )Nab)print)selfr0   r1   s      r   evaluatezMyTestModel.evaluateZ   s%    c1c11u    N)__name__
__module____qualname__n_inputs	n_outputsr4    r5   r   r.   r.   V   s-        HI    r5   r.   c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
TestInputUnitsc                 ,    t                      | _        d S N)r.   model)r3   methods     r   setup_methodzTestInputUnits.setup_methoda   s     ]]


r5   c                 F   t          |                     dd          d           t          |                     dt          j        z  d          dt          j        z             t          |                     dt          j        z  d          dt          j        z             d S )Nr               )r
   r@   r   r   degr3   s    r   test_evaluatezTestInputUnits.test_evaluated   sz     Aq!1!12666 AGQ!7!7acBBB AIq!9!92:FFFFFr5   c                    dt           j        i| j        _        t	          |                     dt           j        z  d          dt           j        z             t	          |                     dt           j        z  d          dt           j        z             t	          |                     dt           j        z  dt           j        z            dt           j        z  t           j        z             t          j        t          t                              ddd	          
          5  |                     dt           j        z  d           d d d            n# 1 swxY w Y   t          j        t          t                              ddd	          
          5  |                     dd           d d d            d S # 1 swxY w Y   d S )Nr'   r   rF      r#      r.   r   rH   r   r   )r   rH   r@   _input_unitsr
   radr   r   r   r   r   r   rI   s    r   test_input_unitszTestInputUnits.test_input_unitsj   s   #&,
 AIq!9!92:FFF AIq!9!91qu9EEE AIq13w!?!?QUQSQQQ]:W^^M3PU-V-VWWW 	# 	#JJq13w"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# ]:W^^M2u-U-UVVV 	 	JJq!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s$   "$EEEF66F:=F:c                 n   dt           j        i| j        _        d| j        _        t          |                     dt           j        z  d          dt           j        z             t          |                     dt           j        z  d          dt           j        z             t          j        t          t                              dd	d
                    5  |                     dt           j        z  d           d d d            n# 1 swxY w Y   t          |                     dd          d           d S )Nr'   Tr   rF   rL   r#   rM   r.   r   rH   r   	   )r   rH   r@   rN    _input_units_allow_dimensionlessr
   rO   r   r   r   r   r   r   rI   s    r   $test_input_units_allow_dimensionlessz3TestInputUnits.test_input_units_allow_dimensionlessw   s+   #&,
6:
3 AIq!9!92:FFF AIq!9!91qu9EEE]:W^^M3PU-V-VWWW 	# 	#JJq13w"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	!Aq!1!1155555s   $DD
D
c                    dt           j        i| j        _        d| j        _        t          |                     dt           j        z  d          dt           j        z             |                     t          j        t           j        z  d          }t          |dt           j        z             |j	        t           j        u sJ d S )Nr'   Tr   rF   rL   r#   ih  )
r   rH   r@   rN   _input_units_strictr
   nppirO   unitr3   results     r   test_input_units_strictz&TestInputUnits.test_input_units_strict   s    #&,
)-
& AIq!9!92:FFFBEAEM1-- qu555{ae######r5   c           	      6   dt           j        i| j        _        t	          j        t          t                              ddd                    5  |                     dt           j	        z  d           d d d            n# 1 swxY w Y   dt          j
                    i| j        _        t          |                     dt           j	        z  d          ddt           j	        z                      t           j        t          j
                              z             d S )Nr'   r.   r$   micronr   r   r(   )r   r^   r@   rN   r   r   r   r   r   r$   r+   input_units_equivalenciesr
   torI   s    r   test_input_units_equivalenciesz-TestInputUnits.test_input_units_equivalencies   s   #&/
]gnn]E8LL
 
 
 	% 	% JJq15y!$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%
 14QZ\\/B
, JJq15y!$$QUqxqz||DDD	
 	
 	
 	
 	
s   $A>>BBc                    dt           j        i| j        _        dt           j        i| j        _        |                     dt           j        z  d          }t          |dt           j        z             |j        t           j        u sJ d S )Nzr   rF   rL   r   rH   r@   rN   rO   _return_unitsr
   rY   rZ   s     r   test_return_unitsz TestInputUnits.test_return_units   sl    #&,
$'<
 AIq)) ae444{ae######r5   c                    dt           j        i| j        _        t           j        | j        _        |                     dt           j        z  d          }t          |dt           j        z             |j        t           j        u sJ d S )Nr'   r   rF   rL   rd   rZ   s     r   test_return_units_scalarz'TestInputUnits.test_return_units_scalar   sj     $',
#$5
 AIq)) ae444{ae######r5   N)r6   r7   r8   rB   rJ   rP   rT   r\   ra   rf   rh   r;   r5   r   r=   r=   `   s        # # #G G G  
6 
6 
6$ $ $
 
 
$ $ $
$ 
$ 
$ 
$ 
$r5   r=   c                     t          dt          j        z            } t          dt          j        z            }| |z  } |dt          j        z  dt          j        z            }t	          |d         dt          j        z  dt          j        z  z              t	          |d         dt          j        z  dt          j        z  z              dS )-
    Test units to first model in chain.
    r"   rG   r   r   Nr	   r   rH   	arcsecondr
   arcsecs1s2csouts       r   test_and_input_unitsrs      s     
rAEz		B	rAEz		B	bB
"R!+rAK/
0
0CSVR!%Z"qx-%?@@@SVR!%Z"qx-%?@@@@@r5   c                  
   t          dt          j        z            } t          dt          j        z            }| |z   } |dt          j        z            }t	          |dt          j        z  dt          j        z  z              dS rj   r"   rG   Nrk   rn   s       r   test_plus_input_unitsrv      p     
rAEz		B	rAEz		B	bB
"R!+

CS"qu*rAH}"<=====r5   c                  
   t          dt          j        z            } t          dt          j        z            }| |z  } |dt          j        z            }t	          |dt          j        z  dt          j        z  z              dS ru   rk   rn   s       r   test_compound_input_unitsry      rw   r5   c                  L   t          dt          j        z            } t          dt          j        z            }| |z  }t          j        t
          t                              ddd                    5   |dt          j        z             ddd           dS # 1 swxY w Y   dS )z:
    Test incompatible units to first model in chain.
    r"   r	   pixrH   r   N)	r	   r   rH   r   r   r   r   r   r{   ro   rp   rq   s      r   test_compound_input_units_failr}           
rAEz		B	rAEz		B	bB	z)N)N	O	O	O  
2:                    3BB Bc                  L   t          dt          j        z            } t          dt          j        z            }| |z  }t	          j        t          t                              ddd                    5   |dt          j        z             ddd           dS # 1 swxY w Y   dS )z1
    Test incompatible model units in chain.
    r"   r	   r{   rH   r   N)	r	   r   r{   rH   r   r   r   r   r   r|   s      r   %test_compound_incompatible_units_failr      r~   r   c                  J   t          dt          j        z            } t          dt          j        z            }| |z  } |dt          j        z  dt          j        dt          j        z  t          j        z            i          }t          |dt          j        z             dS )zo
    Check that equivalencies work when passed to evaluate, for a chained model
    (which has one input).
    r"   r'   r   r(      Nr	   r   rH   r{   pixel_scaler
   rn   s       r   test_compound_pipe_equiv_callr      s    
 
rAEz		B	rAEz		B	bB
"R!%ZQ]3;;N-O-O'P
Q
Q
QCS"qu*-----r5   c            	         t          dt          j        z            } t          dt          j        z            }| |z  } |dt          j        z  dt          j        z  t          j        dt          j        z  t          j        z            t          j        dt          j        z  t          j        z            d          }t          |d         dt          j        z             t          |d         dt          j        z             dS )	zk
    Check that equivalencies work when passed to evaluate, for a composite model
    with two inputs.
    r"   r   x0x1r(   r   rE   r   Nr   rn   s       r   test_compound_and_equiv_callr     s    
 
rAEz		B	rAEz		B	bB
"
QU

QU
-aeae 344-aeae 344
 
  C SVR!%Z000SVR!%Z00000r5   c                     t          dt          j        z            } dt          j        dt          j        z  t          j        z            i| _        t          dt          j        z            }t          dt          j        z            }| |z  }|j        dt          j        dt          j        z  t          j        z            ik    sJ  |dt          j        z            }t          |dt          j        z             || z  }|j        J  |dt          j        z            }t          |dt          j        z             | |z  }|j        dt          j        dt          j        z  t          j        z            ik    sJ |                    d          } |dt          j        z  dt          j        z            }t          |dt          j        z             t          j	        t          t                              d	d
d                    5   |dt          j        z  dt          j        z            }ddd           dS # 1 swxY w Y   dS )zF
    Test setting input_units_equivalencies on one of the models.
    r"   r'   r   r   NrG   r   	TestModelr	   r{   rH   r   )r	   r   rH   r   r{   r_   r
   renamer   r   r   r   r   )ro   rp   sprq   rr   s        r   'test_compound_input_units_equivalenciesr     s'   
 
rAEz		B$'sQU{QU7J)K)K#LB 	rAEz		B	rAEz		B	bB'CsQU{QU?R1S1S+TTTTT
"R!%Z..CS"qu*---	bB'///
"R!%Z..CS"qu*---	bB'D!-aeae@S2T2T+UUUUU	;		B
"R!%Zae
$
$CS"qu*---	z)N)N	O	O	O ) )baeR!%Z(() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )s   'II
Ic                      G d dt                     }  | d          }t          d          }||z  } |dt          j        z            }t          |dt          j        z             |j        t          j        u sJ ||z  } |dt          j        z            }t          |dt          j        z             |j        t          j        u sJ ||z  } |dt          j        z  dt          j        z            }t          |dt          j        z             |d         j        t          j        u sJ |d         j        t          j        u sJ d	S )
z?
    Test setting input_units_strict on one of the models.
    c                        e Zd Zdej        iZdS )6test_compound_input_units_strict.<locals>.ScaleDegreesr'   Nr6   r7   r8   r   rH   input_unitsr;   r5   r   ScaleDegreesr   A          AElr5   r   r#   r"   (   rG   r   r   N)r   r   rm   r
   rY   rH   r   ro   rp   rq   rr   s        r    test_compound_input_units_strictr   <  sL   
# # # # #u # # # 
aB	qB	bB
"R!(]

CS"qx-0008qu	bB
"R!(]

CS"qx-0008qu	bB
"R!(]BM
*
*CS"qx-000q6;!%q6;!(""""""r5   c                      G d dt                     }  | d          }d|_        t          d          }||z  }|                    d          } |d          }t          |dt          j        z              |dt          j        z            }t          |dt          j        z             t          j        t          t                              ddd	          
          5   |dt          j        z            }ddd           n# 1 swxY w Y   d|_        ||z  }|                    d          }t          j        t          t                              ddd	          
          5   |d          }ddd           n# 1 swxY w Y   d|_        ||z  }|                    d          } |d          }t          |dt          j        z              |dt          j        z            }t          |dt          j        z             t          j        t          t                              ddd	          
          5   |dt          j        z            }ddd           n# 1 swxY w Y   d|_        ||z  }t          j        t          t                              ddd	          
          5   |d          }ddd           n# 1 swxY w Y   d|_         | d          }d|_         | d          }d|_        ||z  }|                    d          } |ddt          j        z            }t          |d         dt          j        z             t          |d         dt          j        z             t          j        t          t                              ddd	          
          5   |dd          }ddd           dS # 1 swxY w Y   dS )zL
    Test setting input_units_allow_dimensionless on one of the models.
    c                        e Zd Zdej        iZdS )Ctest_compound_input_units_allow_dimensionless.<locals>.ScaleDegreesr'   Nr   r;   r5   r   r   r   `  r   r5   r   r#   Tr   r"   r   r   rH   r   NFr   r   rG   r   )r   rS   r   r
   r   onerm   r   r   r   r   r   r   r   s        r   -test_compound_input_units_allow_dimensionlessr   [  s   
# # # # #u # # # 
aB*.B'	qB	bB	;		B
"R&&CS"qu*---
"R!(]

CS"qx-000	zU)S)S	T	T	T  bacll               +0B'	bB	;		B	zE)R)R	S	S	S  bff               +/B'	bB	;		B
"R&&CS"qu*---
"R!(]

CS"qx-000	zU)S)S	T	T	T  bacll               +0B'	bB	zE)R)R	S	S	S  bff               +/B'	aB*.B'	aB*/B'	bB	;		B
"Rah

CSVR!%Z000SVR!(]333	zE)R)R	S	S	S  bRjj                 sZ   !DD
D
'E??FF=I""I&)I&.KK
K
*OOOc                       G d dt                     } t                       |             z  }t           |dt          j        z  dt          j        z            dt          j        z             dS )zn
    Test that return_units on the first model in the chain is respected for the
    input to the second.
    c                   X     e Zd ZdZdZ fdZed             Zed             Zd Z	 xZ
S )-test_compound_return_units.<locals>.PassModelr#   c                 :     t                      j        |i | d S r?   )super__init__)r3   argskwargs	__class__s      r   r   z6test_compound_return_units.<locals>.PassModel.__init__  s%    EGGd-f-----r5   c                 4    t           j        t           j        dS )zInput units.r   r   rH   rI   s    r   r   z9test_compound_return_units.<locals>.PassModel.input_units       %qu---r5   c                 4    t           j        t           j        dS )zOutput units.r   r   rI   s    r   return_unitsz:test_compound_return_units.<locals>.PassModel.return_units  r   r5   c                     |j         |j         fS r?   )r   )r3   r'   ys      r   r4   z6test_compound_return_units.<locals>.PassModel.evaluate  s    7AG##r5   )r6   r7   r8   r9   r:   r   propertyr   r   r4   __classcell__)r   s   @r   	PassModelr     s        		. 	. 	. 	. 	. 
	. 	. 
	. 
	. 	. 
	.	$ 	$ 	$ 	$ 	$ 	$ 	$r5   r   r   )r   Z   N)r   r   r
   r   rH   )r   rq   s     r   test_compound_return_unitsr     sv    $ $ $ $ $E $ $ $( 
	$BRRAE	1qu955wGGGGGr5   )$__doc__numpyrW   r   numpy.testingr   astropyr   r   astropy.modeling.corer   astropy.modeling.modelsr   r   r   r	   astropy.tests.helperr
   astropy.unitsr   r   r    r,   r.   r=   rs   rv   ry   r}   r   r   r   r   r   r   r   r;   r5   r   <module>r      s         ) ) ) ) ) )       ' ' ' ' ' ' I I I I I I I I I I I I 9 9 9 9 9 9 $ $ $ $ $ $ $ $ $T  "    %   O$ O$ O$ O$ O$ O$ O$ O$dA A A> > >> > >
 
 

 
 
. . .1 1 1,) ) )B# # #>C C CLH H H H Hr5   