
    IR-ez0                        d dl mZ d dlmZm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 d dlmZ ej                            ddd	d
ddej        ddddf         g dg dgg dg dgfg dg dg dgg dg dg dggg dg dg dgg dg dg dggfg          d             Zej                            dd d!d"g dg dgg dg dgfg dg dg dgg dg dg dggg dg dg dgg dg dg dggfg          d#             Zd$ Zd% Zd& Zd' Zd( Zd) Zg d*Z ej                            d+e           d,             Z!d- Z"d. Z#d/ Z$d0 Z%d1 Z&d2 Z'd3 Z(d4 Z)dS )5    N)cossin)assert_allclose)models	rotations)assert_quantity_allclose)wcsinpr   r   )i  (\4)g     F33333F@r   Z   )r                  )r      r   )      	   )
         r   r   r   r   )r   r   r   r   )r   r   r   r   )            )            )            )            )             )!   "   #   $   )%   &   '   (   ))   *   +   ,   )-   .   /   0   c                    t          j                    }ddg}||j         _        ddg|j         _        d}t	          j                    }t	          j        |d         |d         |          }t	          j        |d         |d         |          }||z  }||j        z  }|	                    | d         | d         d          }	|
                    |	d         |	d         d          }
t           ||  |	d	           t           ||	 |
d	           d S )
Ng90oOi@gXLjG@zRA---TANzDEC--TAN   r   r   -q=atol)r	   WCScrvalctyper   Pix2Sky_TANRotateNative2CelestialRotateCelestial2Nativeinversewcs_pix2worldwcs_world2pixr   )r
   wrI   lonpoletann2cc2nmminvradecxys              Elib/python3.11/site-packages/astropy/modeling/tests/test_rotations.pytest_against_wcslibr[      s   . 			A+&EAEKz*AEKG



C

'a%(G
D
DC

'a%(G
D
DCc	ADOOCFCFA..E	
q58Q	/	/BAAsGU////DD%L"5111111    )gh㈵>g-C6?)r:   r   )g     5@r   c                     d\  }}}t          j        |||          }t          j        |||          }t           |j         ||   | d           t           |j         ||   | d           d S )N)r<   r=   r>   gvIh%<=rF   )r   rL   rM   r   rN   )r
   lonlatlon_polerT   rU   s         rZ   test_roundtrip_sky_rotationra   ;   s    ( $Ch

'S(
;
;C

'S(
;
;CKCKc+Su====KCKc+Su======r\   c                      t          j        ddd          }  | dd          \  }}t          |d           t          |d           d S )Nr   r   r      )r   rL   r   )rT   alphadeltas      rZ   test_native_celestial_lat90rf   V   sO    

'2q
1
1C3q!99LE5E1E3r\   c                  z    t          j        d          }  | dd          \  }}t          ||gddgd           d S Nr   angler   r   绽|=rF   )r   
Rotation2Dr   modelxys      rZ   test_Rotation2Drq   ]   sK    B'''E5A;;DAqQFQF//////r\   c                      t          j        dt          j        z            }  | dt          j        z  dt          j        z            \  }}t          ||gddgt          j        z  dt          j        z             d S rh   )r   rl   udegarcsecr   rm   s      rZ   test_Rotation2D_quantityrv   c   sk    BJ///E5QUAL))DAqaVaVae^%!%-HHHHHHr\   c                      t          j        d          }  | j         | dd           \  }}t          ||gddgd           d S )Ng䠄Gm@ri   r   r   rk   rF   )r   rl   rN   r   rm   s      rZ   test_Rotation2D_inverserx   i   sT    I...E5=%%1++&DAqQFQF//////r\   c                     t          j        dt          j        z            } t	          j        ddg          }t	          j        g d          }d}t          j        t          |          5  | 	                    ||| j
                   d d d            n# 1 swxY w Y   t          j        t          |          5  | 	                    ||| j
                   d d d            n# 1 swxY w Y   t	          j        ddg          }t	          j        ddg          }d}t          j        t          j        |          5  | 	                    |t          j        z  || j
                   d d d            d S # 1 swxY w Y   d S )	Nr   ri   r   r   r   ,Expected input arrays to have the same shapematchz"x and y must have compatible units)r   rl   rs   rt   nparraypytestraises
ValueErrorevaluaterj   
UnitsErrorrV   )rn   ro   rp   MESSAGEs       rZ   test_Rotation2D_errorsr   o   s   BJ///E 	!QA
A=G	z	1	1	1 * *q!U[)))* * * * * * * * * * * * * * *	z	1	1	1 * *q!U[)))* * * * * * * * * * * * * * * 	!QA
!QA3G	q|7	3	3	3 0 0q13w5;///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s6   ,BBB;C$$C(+C(=*E44E8;E8c                  "   d} d}d}d}d}t          j        dddd          }t           || |d	
           t          j        dddd          }t           || |d	
           t          j        dddd          }t           ||  |d	
           d S )Nr   )r   r   r   )rD   r   )r   r   r   r   zxzrE   rF   zyzyzy)r   EulerAngleRotationr   )ro   rp   znegxnegyrn   s         rZ   test_euler_angle_rotationsr      s    AAADD %aQ66EEE1Iqw////%aQ66EEE1It'2222%aQ66EEE1It'222222r\   r   r   r   yxyxyxxzx
axes_orderc                    t          j        d          }t          j        d          }t          j        d          }t          |          }t          |          }t          |          }t          |          }t          |          }t          |          }	t          j        ||z  ||z  |	z  z
  | |	z  ||z  |z  z
  ||z  g||z  ||z  |	z  z   ||z  |z  ||	z  z
  | |z  g||	z  ||z  |gg          t          j        ||z  |z  ||	z  z
  | |z  ||z  |	z  z
  ||z  g||	z  ||z  |z  z   ||z  ||z  |	z  z
  ||z  g| |z  ||	z  |gg          t          j        ||z  |z  ||	z  z
  | |z  ||z  ||z  |	z  z   g||z  |||	z  g| |	z  ||z  |z  z
  ||z  ||z  ||z  |	z  z
  gg          t          j        ||z  ||z  |	z  z
  ||z  ||	z  ||z  |z  z   g||	z  || |z  g| |z  ||z  |	z  z
  ||z  ||z  |z  ||	z  z
  gg          t          j        |||	z  ||z  g||z  ||z  ||z  |	z  z
  | |	z  ||z  |z  z
  g| |z  ||z  ||z  |	z  z   ||z  |z  ||	z  z
  gg          t          j        || |z  ||	z  g||z  ||z  |z  ||	z  z
  | |z  ||z  |	z  z
  g||z  ||	z  ||z  |z  z   ||z  ||z  |	z  z
  gg          d}
t          j        |||g|           }t          |j        |
|                     dS )zg
    Tests against all Euler sequences.
    The rotation matrices definitions come from Wikipedia.
    gffffff7@gffffff(@r4   r   N)	r}   deg2radr   r   r~   r   _create_matrixr   T)r   phithetapsic1c2c3s1s2s3matricesmats               rZ   test_euler_anglesr      s    *T

CJtE
*R..C	SB	UB	SB	SB	UB	SB xr'BGbL(RC"HrBw|,CrBwPr'BGbL(BGbL27,BrcBhPr'R"W,
 
 xr'B,b(RC"HrBw|,CrBwPr'BGbL(BGb2gl,Bb2gO#(b2g-
 
 xr'B,b(RC"HR"r'B,8NPr'R27,#(R"Wr\)R"WR"r'B,8NP
 
 xr'BGbL(BGrBwb27MOr'RB38-#(R"Wr\)R"WR"rBw8NP
 
 xR27,r'R"WrBw|3sRx"r'B,7NP#(b2gR"4R"rBw8NP
 
 xbBG-r'R"Wr\BG3sRx"r'B,7NPr'R"WrBw|3rBwb27MO
 
I+ +HX 
"C#4j
A
ACCE8J/00000r\   c                  ,   d } d}d}d}d}d}t          j        d          }t          j        d          }|| ||| g}d}	t          j        t          j        |          t          j        z  |	          }
 | |
||          }t          ||d	           d
S )z
    A sanity test - when V2_REF = 0 and V3_REF = 0,
    for V2, V3 close to the origin
    ROLL_REF should be approximately PA_V3 .

    (Test taken from JWST SIAF report.)
    c                 *   | d         t          j        |          z  | d         t          j        |          z  z    t          j        |          z  | d         t          j        |          z  z   }| d         | d         z  | d         | d         z  z
  t          j        |          z  | d         | d         z  | d	         | d         z  z
  t          j        |          z  z   }t          j        t          j        ||                    }|d
k     r|dz  }|S )N)r   r   )r   r   )r   r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   ih  )r}   r   r   rad2degarctan2)matrixv2v3XYnew_rolls         rZ   _roll_angle_from_matrixz1test_rotation_3d.<locals>._roll_angle_from_matrix   s   TlRVBZZ'&,*CCDrvH
 H
 
4L26"::%& D\F4L(6$<&,+FF"&QS**T4L6$<'&,*EEF2JJX  :bjA..//a<<OHr\      6   r   r7   g34>zyxyzgMbP?rF   N)r}   r   r   r   rs   rt   r   )r   ra_refdec_refv2_refv3_refpa_v3r   r   anglesaxesM
roll_angles               rZ   test_rotation_3dr      s    
 
 
 FGFFE	F		B	F		Bvgugw7FD F!3!3ae!;TBBA((B33JJD111111r\   c                     d} d}d}d}d}d}d}d}t          j        || |||  g          }d	}	t          j        ||	
          }
t          j        ||          \  }}} |
|||          \  }}}t          j        |||          }t          ||d           t          j        ||	
          }
 |
||          }t          ||d           dS )zh
    Test taken from JWST INS report - converts
    JWST telescope (V2, V3) coordinates to RA, DEC.
    r   r   gM=_gkSދr7      i)g
2Z@g7g]Ar   r   rk   rF   N)r}   r~   r   RotationSequence3Dspherical2cartesiancartesian2sphericalr   SphericalRotationSequence)r   r   r   r   r0r   r   expected_ra_decr   r   v2sro   rp   r   x1y1z1rX   s                     rZ   test_spherical_rotationr      s    
 FGFF	B	B	B>OXvwGfW=>>FD

&v$
?
?
?C+B33GAq!Q1JBB)"b"55EE?7777

-f
F
F
FCCBKKEE?777777r\   c            	         t          j        t          d          5  t          j        t          j                    d           d d d            n# 1 swxY w Y   d} t          j        t          |           5  t          j        g dd           d d d            n# 1 swxY w Y   t          j        g dd          }d	} t          j        t          |           5  |                    t          j	        g d          t          j	        d
dg          t          j	        d
dg          g d           d d d            n# 1 swxY w Y   t          j        t          |           5  |                    t          j	        d
dg          t          j	        g d          t          j	        d
dg          g d           d d d            n# 1 swxY w Y   t          j        t          |           5  |                    t          j	        d
dg          t          j	        d
dg          t          j	        g d          g d           d d d            d S # 1 swxY w Y   d S )N.Unrecognized axis label .* should be one of .*r{   abcr   z8The number of angles 4 should match the number of axes 3r   zyxr   rz   r   r   )
r   r   r   r   r   mk	MagicMockr   r}   r~   )r   rn   s     rZ   test_RotationSequence3D_errorsr     s   	K
 
 
 G G 	$R\^^FFFFG G G G G G G G G G G G G G G JG	z	1	1	1 E E$\\\eDDDDE E E E E E E E E E E E E E E (uEEEE=G	z	1	1	1 
 
HYYY1a&!1!128QF3C3CYYY	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
z	1	1	1 
 
HaVbhyyy1128QF3C3CYYY	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
z	1	1	1 
 
HaVbh1v..0C0CYYY	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s\   (AAA8BB!$B!AE  EE&AG		GG/AIIIc                      t          j        g dd          } t          | j        j        j        g d           | j        j        dk    sJ d S )Nr   r   r   )xyz)r   r   r   rN   r   valuer   rn   s    rZ   test_RotationSequence3D_inverser   8  sS    (uEEEEEM(.====#u,,,,,,r\   c                     d} t          j        t          |           5  t          j        t          j                    t          j                    t          j                    d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          j        t          j                    t          j                    t          j                    d           d d d            n# 1 swxY w Y   d} t          j        t          |           5  t          j        dt          j	        z  d	d
d           d d d            n# 1 swxY w Y   t          j        t          |           5  t          j        dd	t          j	        z  d
d           d d d            n# 1 swxY w Y   t          j        t          |           5  t          j        dd	d
t          j	        z  d           d d d            d S # 1 swxY w Y   d S )NzDExpected axes_order to be a character sequence of length 3, got xyzxr{   xyzxr   r   r   =All parameters should be of the same type - float or Quantityr   r   r   r   )
r   r   	TypeErrorr   r   r   r   r   rs   rV   r   s    rZ   test_EulerAngleRotation_errorsr   ?  s<   UG	y	0	0	0 
 
$LNNBLNNBLNNv	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
K
 
 
 
 
 	$LNNBLNNBLNNu	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 OG	y	0	0	0 F F$QWauEEEEF F F F F F F F F F F F F F F	y	0	0	0 F F$QACuEEEEF F F F F F F F F F F F F F F	y	0	0	0 F F$Q1qs7uEEEEF F F F F F F F F F F F F F F F F Fs[   AA66A:=A:AC44C8;C8&EEE4&F&&F*-F*&G??HHc                      t          j        dddd          } t          | j        j        d           t          | j        j        d           t          | j        j        d           | j        j        dk    sJ d S )	Nr   r   r   r   r   r   r   r   )r   r   r   rN   r   r   r   r   r   s    rZ   test_EulerAngleRotation_inverser   Y  ss    (Aq%88EEM%r***EM',,,EM%r***=#u,,,,,,r\   c                     d} t          j        t          |           5  t          j        dt
          j        z  dd           d d d            n# 1 swxY w Y   t          j        t          |           5  t          j        ddt
          j        z  d           d d d            n# 1 swxY w Y   t          j        t          |           5  t          j        dddt
          j        z             d d d            d S # 1 swxY w Y   d S )Nr   r{   r   r   r   )r   r   r   r   _SkyRotationrs   rV   r   s    rZ   test__SkyRotation_errorsr   b  s   NG	y	0	0	0 . .q13w1---. . . . . . . . . . . . . . .	y	0	0	0 . .q!ac'1---. . . . . . . . . . . . . . .	y	0	0	0 . .q!QW---. . . . . . . . . . . . . . . . . .s5   $AAA4$B$$B(+B(
$C;;C?C?c                  :   t          j        ddd          } t          j                    }t          j                    }t          j                    }t          j                    }t          j                    }d}t          j                    }t          j                            t           j        dd||f          5 }d|f|                     |||||          k    sJ |j        t          j	        | |||||d	          gk    sJ 	 d d d            d S # 1 swxY w Y   d S )
Nr   r   r   r   r   T)autospecreturn_valueim  r   )
r   r   r   r   patchobject_EulerRotation	_evaluatecall_args_listcall)	rn   r   r   r^   r_   r`   rd   re   mkEvals	            rZ   test__SkyRotation__evaluater   m  sQ   "1a++E
,..CLNNE
,..C
,..C|~~HELNNE	 *t5RW. 
 
 
 
	U|usE3XNNNNNN$GE3sC5AA)
 
 
 
 
 
	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   :ADDD)*unittest.mockmockr   mathr   r   numpyr}   r   numpy.testingr   astropy.unitsunitsrs   astropy.modelingr   r   astropy.tests.helperr   astropy.wcsr	   markparametrizemgridr[   ra   rf   rq   rv   rx   r   r   euler_axes_orderr   r   r   r   r   r   r   r   r    r\   rZ   <module>r      s                      ) ) ) ) ) )       . . . . . . . . 9 9 9 9 9 9       		"1"bqb&	
))YYY	)))\\\!:; |||___=!!!#3#3#35E5E5EF
 "!!#3#3#35E5E5EF!!!#3#3#35E5E5EF		
 ,2 2- ,2( 	
))YYY	)))\\\!:; |||___=!!!#3#3#35E5E5EF
 "!!#3#3#35E5E5EF!!!#3#3#35E5E5EF		
 &> >' &>     0 0 0I I I0 0 00 0 0*3 3 3$ >==  '788=1 =1 98=1@#2 #2 #2L8 8 86
 
 
:- - -F F F4- - -. . .
 
 
 
 
r\   