U
    e»{jÈ-  ã                   @   sÄ   d dl Z d dlZ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 d dlmZ e jejddd�Ze jejd	d
d�Ze jejd	dd�Zdd„ ZG dd„ dƒZG dd„ dƒZG dd„ dƒZdS )é    N)Úunits)ÚTime)ÚSIDEREAL_TIME_MODELS)ÚiersgVçž¯Ò<g+i¤)+`>©ZrtolÚatolç      ð?gß¼šxV42?gß¼šxV4B?c                  C   s,   dD ]"} t |  D ]}|tjjkst‚qqdS )z?The doc string is formatted; this ensures this remains working.©ÚmeanÚapparentN)r   r   Úsidereal_timeÚ__doc__ÚAssertionError)ÚkindÚmodel© r   ú_/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/time/tests/test_sidereal.pyÚtest_doc_string_contains_models   s    r   c                   @   s>   e Zd ZdZdd„ Zdd„ Zej dd¡dd	„ ƒZ	d
d„ Z
dS )ÚTestERFATestCaseszBTest that we reproduce the test cases given in erfa/src/t_erfa_c.cc                 C   s\   t ddddd�| _t ddddd�| _d| j_d| jjj| jj | jjj| jj   | j_d S )	Nç   @€OBAg     =ê@Úut1Újd)ÚscaleÚformatÚttç        i€Q )r   Útime_ut1Útime_ttZdelta_ut1_utcr   Újd1Újd2©Úclsr   r   r   Úsetup_class   s    ÿýÿzTestERFATestCases.setup_classc                 C   s8   t j| jjj| jj | jjj| jj  ddd�s4t‚d S )Nr   g›+¡†›„=)r   )ÚnpÚallcloser   r   r   r   r   r   ©Úselfr   r   r   Ú
test_setup/   s    ÿüzTestERFATestCases.test_setupÚerfa_test_input))gžµ‘Æü?çê-�™—q=Z	eraGmst00)gÙLzÆü?r)   Z	eraGmst06)gÙ(Éü?r)   Z	eraGmst82)gR (ƒü?r)   Z	eraGst00a)gTÁ‚ü?r)   Z	eraGst00b)g–	ƒü?r)   Z	eraGst06a)g‰YŸ‚ü?r)   ZeraGst94c                 C   sÈ   |\}}}|d dkrFd}d|d dkr,dndd	›|dd … d
›�}n2d}d|d dkr\dndd	›|dd …   ¡ d
›�}|t ¡ ksˆt‚|t| ks˜t‚| j |d|¡}tj| d¡|d|d�sÄt‚d S )Né   Úmr
   ZIAUé   Ú0é   é   Z2dÚsr   é   Ú	greenwichÚradianr   r   )	Úupperr   Úkeysr   r   r   r#   r$   Úto_value)r&   r(   ÚresultÚ	precisionÚnamer   Z
model_nameÚgstr   r   r   Útest_iau_models7   s    
,.z!TestERFATestCases.test_iau_modelsc                 C   s@   t ddddd�}| d¡}d}t | tj¡| ¡dk s<t‚d S )	Nr   ç    €Žê@r   r   )r   r   Útioç#ˆ“;¿Ù?r)   )r   Úearth_rotation_angler#   Úabsr6   Úur3   r   )r&   r   ÚeraÚexpectedr   r   r   Útest_eraR   s    
zTestERFATestCases.test_eraN)Ú__name__Ú
__module__Ú__qualname__r   r"   r'   ÚpytestÚmarkÚparametrizer;   rD   r   r   r   r   r      s   þ
r   c                   @   sŽ   e Zd ZdZedd„ ƒZedd„ ƒZdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zej dd¡dd„ ƒZdd„ Zdd„ Zdd„ ZdS )ÚTestSTzµTest Greenwich Sidereal Time.  Unlike above, this is relative to
    what was found earlier, so checks changes in implementation, including
    leap seconds, rather than correctnessc                 C   s>   t jj| _dt j_tdddddgdd�| _t| jd	d
�| _d S )NFú2012-06-30 12:00:00z2012-06-30 23:59:59z2012-06-30 23:59:60z2012-07-01 00:00:00z2012-07-01 12:00:00Úutc)r   ©Ú120dZ10d)Úlocation)r   ÚconfÚauto_downloadÚorig_auto_downloadr   Út1Út2r    r   r   r   r"   _   s    
ûø
zTestST.setup_classc                 C   s   | j tj_d S ©N©rS   r   rQ   rR   r    r   r   r   Úteardown_classp   s    zTestST.teardown_classc                 C   s6   t  dddddg¡}| j dd¡}t|j|ƒs2t‚dS )	z@Compare Greenwich Mean Sidereal Time with what was found earlierg"¥Y—,c@gŠ?¶"¡2@g&,ÏS4¡2@g»è”F¡2@g¹5x¿¦@r
   r2   N©r#   ÚarrayrT   r   Úallclose_hoursÚvaluer   )r&   Zgmst_compareÚgmstr   r   r   Ú	test_gmstt   s    ûÿ	zTestST.test_gmstc                 C   s6   t  dddddg¡}| j dd¡}t|j|ƒs2t‚dS )	zDCompare Greenwich Apparent Sidereal Time with what was found earliergà«ó™rc@g	'õ£3¡2@g’/åE¡2@g8'&X¡2@gÊá:¢§@r   r2   NrY   )r&   Zgst_comparer:   r   r   r   Útest_gst‚   s    ûÿ	zTestST.test_gstc                 C   sB  t dddddd�}| ¡ }dtj }t || ¡dtj k s@t‚t |j	j
|j	j¡}tj ¡ }d	d
„ | |¡D ƒ\}}t | t | t |t d¡¡¡¡}|t |d |d ¡tj>  }	t ||	 ¡dtj k sÖt‚t dddddd�}
|
 ¡ }t t d¡|¡}|t |d |d ¡tj>  }t || ¡dtj k �s>t‚dS )z,Comare ERA relative to erfa.era00 test case.r   r<   r   )r   r   r   )r   rP   r   r>   ç»½×Ùß|Û=c                 s   s   | ]}|  tj¡V  qd S rV   )r6   rA   Zrad)Ú.0Úcr   r   r   Ú	<genexpr>š   s     z"TestST.test_era.<locals>.<genexpr>é   )r   é   r)   )é-   r   rf   N)r   r?   rA   r3   r#   r@   r   ÚerfaZsp00r   r   r   r   Zearth_orientation_tableÚgetZpm_xyÚrxZryZrzÚeyeZarctan2Zdeg2rad)r&   ÚtrB   rC   ÚspZ
iers_tableZxpZypÚrZ	expected1rU   Zera2Úr2Z	expected2r   r   r   rD   �   s    

&zTestST.test_erac                 C   s2   | j  dd¡}| j  dd¡}t|j|jƒs.t‚dS )z6Check that Mean and Apparent are within a few seconds.r
   r2   r   N)rT   r   Úwithin_2_secondsr\   r   )r&   r]   r:   r   r   r   Útest_gmst_gst_close¥   s    zTestST.test_gmst_gst_closec                 C   s0   | j  dd¡}| j  d¡}t|j|jƒs,t‚dS )zACheck that mean sidereal time and earth rotation angle are close.r
   r2   r=   N)rT   r   r?   ro   r\   r   )r&   r]   rB   r   r   r   Útest_gmst_era_close«   s    zTestST.test_gmst_era_closec                 C   s2   | j  dd¡}| j dd¡}t|j|jƒs.t‚dS )z:Check that Greenwich time does not depend on self.locationr
   r2   N©rT   r   rU   r[   r\   r   )r&   Zgmst1Úgmst2r   r   r   Ú&test_gmst_independent_of_self_location±   s    z-TestST.test_gmst_independent_of_self_locationc                 C   sT   | j  dd¡}| j  dd¡}t|j|jƒs.t‚t t || ¡dtj	 k¡sPt‚dS )z4Check that Greenwich and local sidereal time differ.r
   r2   r   r`   N)
rT   r   r[   r\   r   r#   Úallr@   rA   Ú	hourangle)r&   r]   Zlmstr   r   r   Útest_gmst_vs_lmst·   s    zTestST.test_gmst_vs_lmstr   r	   c                 C   sª   t  dddddg¡t  dddd	d
g¡dœ}| j |d¡}| j |¡}t|j|| ƒsXt‚t||  d¡j| jjj	 
d¡ƒs~t‚| j || jjj	¡}t|j|| ƒs¦t‚dS )ztCompare Local Sidereal Time with what was found earlier,
        as well as with what is expected from GMST
        g’Ò¬K–1-@gHü±•	@g(ayž¢	@gØÅ@§4
@gÞ¼†_S-@gñÕùL¹1-@gH8©�	@gˆ|q(/
@gˆÀ91Á
@gæpÑ‚S-@r	   r2   Ú12hrv   N)r#   rZ   rU   r   r[   r\   r   Úwrap_atrP   Úlonr6   rT   )r&   r   Zlst_comparers   Úlmst2Úlmst1r   r   r   Útest_lst¾   s4    ûÿ	ûÿöþzTestST.test_lstc                 C   s2   | j jddd�}| j d¡}t|j|jƒs.t‚d S )Nr
   rO   )Z	longituderr   )r&   r|   r{   r   r   r   Útest_lst_string_longitudeã   s    z TestST.test_lst_string_longitudec              	   C   sJ   t  t¡� | j d¡ W 5 Q R X t  t¡� | j dd ¡ W 5 Q R X d S )Nr
   )rH   ÚraisesÚ
ValueErrorrT   r   r%   r   r   r   Útest_lst_needs_locationè   s    zTestST.test_lst_needs_locationc                 C   s„   t  dddddg¡}| j d¡}| j ¡ }t|j|ƒs:t‚t||  d¡j| jjj	 
d¡ƒs`t‚| j | jj¡}t|j|ƒs€t‚d S )	NgË²èW,-@g^,+4ó@gC×ò3Æó@g9P¹<Xô@gKÒDèM-@r=   rx   rv   )r#   rZ   rU   r?   r[   r\   r   ry   rP   rz   r6   rT   )r&   Zlera_compareZgera2Zlera2Zlera1r   r   r   Ú	test_leraî   s"    ûÿ	
þzTestST.test_leraN)rE   rF   rG   r   Úclassmethodr"   rX   r^   r_   rD   rp   rq   rt   rw   rH   rI   rJ   r}   r~   r�   r‚   r   r   r   r   rK   Z   s"   


$rK   c                   @   sT   e Zd ZdZedd„ ƒZedd„ ƒZej 	dd¡dd	„ ƒZ
ej 	d
d¡dd„ ƒZdS )ÚTestModelInterpretationzECheck that models are different, and that wrong models are recognizedc                 C   s(   t jj| _dt j_tdgddd�| _d S )NFrL   rM   rN   )r   rP   )r   rQ   rR   rS   r   rk   r    r   r   r   r"     s    
z#TestModelInterpretation.setup_classc                 C   s   | j tj_d S rV   rW   r    r   r   r   rX     s    z&TestModelInterpretation.teardown_classr   r	   c                 C   s²   t  t|  ¡ d¡D ]˜\}}| j |d|¡}| j |d|¡}t |j|jk¡sRt	‚t
|j|jƒsdt	‚| j |d|¡}| j |d|¡}t |j|jk¡sšt	‚t
|j|jƒst	‚qdS )z3Check models give different answers, yet are close.é   r2   N)Ú	itertoolsÚcombinationsr   r5   rk   r   r#   ru   r\   r   Úwithin_1_second)r&   r   Zmodel1Zmodel2Zgst1Zgst2Zlst1Zlst2r   r   r   Útest_model_uniqueness  s    
 ÿz-TestModelInterpretation.test_model_uniqueness)r   Úother)r	   )r   r
   c              
   C   sœ   t  t¡� | j |dd¡ W 5 Q R X tt|  ¡ ƒtt|  ¡ ƒ D ]P}t  t¡� | j |d|¡ W 5 Q R X t  t¡� | j |d |¡ W 5 Q R X qFd S )Nr2   Znonsense)rH   r   r€   rk   r   Úsetr   r5   )r&   r   rŠ   r   r   r   r   Ú"test_wrong_models_raise_exceptions"  s    
ÿ
z:TestModelInterpretation.test_wrong_models_raise_exceptionsN)rE   rF   rG   r   rƒ   r"   rX   rH   rI   rJ   r‰   rŒ   r   r   r   r   r„     s   


 ÿr„   )Ú	functoolsr†   rg   Únumpyr#   rH   Zastropyr   rA   Zastropy.timer   Zastropy.time.corer   Zastropy.utilsr   Úpartialr$   r[   rˆ   ro   r   r   rK   r„   r   r   r   r   Ú<module>   s    ? ,