
    1huE                     F   d dl Z 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
Z
dddddd	d
ddddddZ G d de      Zd Zd Zd Ze
j"                  dfdZ G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Z e j                   ej6                  j9                  e      d'z         D ];  Zej6                  j=                  e      j?                  d(d)      Z  e!d*e d+e       = [[ y),    N)datetime)strptime                        	   
         )JanFebMarAprMayJunJulAugSepOctNovDecc                       e Zd Zy)DatumN)__name__
__module____qualname__     :D:\jyotish\venv\Lib\site-packages\ephem/tests/test_usno.pyr   r      s    r#   r   c                 p   | j                  dd      j                  dd      } | j                  dd      j                  dd      } | j                         }t        j                         }d	j	                  t        j                  d
|d               |_        d	j	                  t        j                  d
|d               |_        |d   j                  d      r|xj                  dz  c_        |d   j                  d      r|xj                  dz  c_        t        |d   dd       |_        t        |       |S )u   Return the Observer represented by a line from a USNO file.
              Location:  W 84°24'36.0", N33°45'36.0",   322m
    zW WzE EzN NzS S:z[0-9.]+r   r   N)replacesplitephemObserverjoinrefindalllonlat
startswithfloat	elevationsetup_horizon)linefieldsobservers      r$   interpret_observerr<      s     <<c"**45D<<c"**45DZZ\F~~H88BJJz6!9=>HL88BJJz6!9=>HLayC ayC vbz#2/H(Or#   c                      d| _         d| _        y )Nr   z-0:34)pressurehorizon)r;   s    r$   r8   r8   )   s    HHr#   c                    t        j                  d|       }|d   dd j                         }t        t        |d            |d<   dj	                  |      }t        t        |d      dd  }t        j                  |      }t        j                  d	j	                  |d   j                                     }|d
   j                  dd      \  }}t        j                  |d	j	                  |j                               z         }	|||	fS )z6Read the date, RA, and dec from a USNO data file line.z   +r   Nr    z%Y %m %d %H:%M:%Sr
   r*   r   )r1   r-   str
month_intsr0   r   r   r.   Datehoursdegrees)
r9   r:   datestrfieldsdatestrdtdaterasignmagdecs
             r$   standard_parserP   -   s     XXgt$F1IcrN((*M:mA&678M!hh}%G	8G%89!A>	?B::b>D	SXXfQioo/0	1Bq	a(ID#
--sxx		44
5CS=r#   c                 b    t        | |z
        |kD  r|dnd|z  }d|| d|}t        |      y)z=Raise an exception if two values are not within an arcsecond.N z%s at zthe USNO says z but PyEphem says )absAssertionError)nmerrormoveatmsgs         r$   is_nearr[   ;   s?     1q5zE<RX_:<aCS!! r#   c                   *    e Zd Zd Zd Zd Zd Zd Zy)Trialc                 v    t        t        |      r t        t        |             S t        j                  |      S )z;Return solar system bodies and stars for USNO computations.)hasattrr.   getattrstar)selfnames     r$   select_bodyzTrial.select_bodyD   s-    5$'75$'))::d##r#   c                 n    | j                   d   }|j                         }| j                  |      | _        y)a  Return the object named on the first line of the file.

        Since most USNO files name a heavenly body on their first
        line, this generic examine_content looks for it and sets
        "self.body" accordingly.  If when you subclass Trial you are
        dealing with a file that does not follow this convention, then
        both override examine_content with one of your own, and
        neglect to call this one.

        r   N)linesstriprd   body)rb   	firstlinerc   s      r$   examine_contentzTrial.examine_contentK   s/     JJqM	 $$T*	r#   c                      y)a(  Conclude the test.

        By overriding this function, the author of a Trial can do
        processing at the end of his test run.  Commonly, this is used
        when check_data_line() just stores what it finds in each data
        line, and the results need to be checked as a unit.

        Nr"   rb   s    r$   finishzTrial.finishZ   s    r#   c                 N    |d   j                         r| j                  |       y y )Nr   )isdigitcheck_data_linerb   r9   s     r$   
check_linezTrial.check_lined   s#    7??  & r#   c                      fd}| _         |j                  d       _         j                          t	        t         j                              D ]C   _         j                   j                     }|j                         s2	  j                  |       E 	  j                          y #   |       xY w# t        $ r} |       d }~ww xY w)Nc                      t        dj                  j                  dz   t        j                         fz        } d | _        | S )Nz.USNO Test file %r line %d raised exception:
%sr   )RuntimeErrorpathlineno	traceback
format_exc	__cause__)excrb   s    r$   report_errorzTrial.run.<locals>.report_errori   sD    A99dkkAoy/C/C/EFGHC !CMJr#   
)contentr-   rf   rj   rangelenrw   rg   rr   rm   	Exception)rb   r~   r|   r9   es   `    r$   runz	Trial.runh   s    	 ]]4(
 TZZ1DK::dkk*Dzz|)OOD)	 2	!KKM)&.(  	!. 	!s$   B*B6 *	B36	C?CCN)r   r    r!   rd   rj   rm   rr   r   r"   r#   r$   r]   r]   C   s    $+'!r#   r]   c                   "    e Zd Zed        Zd Zy)Astrometric_Trialc                 
    d|v S )NzAstrometric Positionsr"   clsr~   s     r$   matcheszAstrometric_Trial.matches   s    &'11r#   c                     t        |      \  }}}| j                  j                  |       t        || j                  j                         t        || j                  j
                         y N)rP   rh   computer[   a_raa_decrb   r9   rK   rL   rO   s        r$   rp   z!Astrometric_Trial.check_data_line   sH    &t,b#		$DIINN#TYY__%r#   Nr   r    r!   classmethodr   rp   r"   r#   r$   r   r      s    2 2&r#   r   c                   "    e Zd Zed        Zd Zy)Apparent_Geocentric_Trialc                 
    d|v S )NzApparent Geocentric Positionsr"   r   s     r$   r   z!Apparent_Geocentric_Trial.matches   s    .'99r#   c                 N   t        |      \  }}}| j                  j                  |       t        || j                  j                         t        || j                  j
                         | j                  j                  ||       t        || j                  j                         t        || j                  j
                         | j                  j                  | j                  j                  k(  sJ | j                  j
                  | j                  j                  k(  sJ y )N)epoch)rP   rh   r   r[   g_rag_decrL   rO   r   s        r$   rp   z)Apparent_Geocentric_Trial.check_data_line   s    &t,b#		$DIINN#TYY__% 			$d+DIINN#TYY__% yy~~---yy$))--///r#   Nr   r"   r#   r$   r   r      s    : :0r#   r   c                   (    e Zd Zed        Zd Zd Zy)Apparent_Topocentric_Trialc                 
    d|v S )NzApparent Topocentric Positionsr"   r   s     r$   r   z"Apparent_Topocentric_Trial.matches   s    /7::r#   c                     t         j                  |        | j                  D ]%  }d|v st        |j	                               | _        ' y )N	Location:)r]   rj   rf   r<   rg   r;   rq   s     r$   rj   z*Apparent_Topocentric_Trial.examine_content   s8    d#JJDd" 24::< @ r#   c                    t        |      \  }}}|| j                  _        | j                  j	                  | j                         t        || j                  j                         t        || j                  j                         y r   )rP   r;   rK   rh   r   r[   rL   rO   r   s        r$   rp   z*Apparent_Topocentric_Trial.check_data_line   sX    &t,b#!		$--(DIILL!TYY]]#r#   Nr   r    r!   r   r   rj   rp   r"   r#   r$   r   r      s    ; ;A$r#   r   c                   4    e Zd Zd Zed        Zd Zd Zd Zy)Rise_Transit_Set_Trialc                     g | _         y r   )datarl   s    r$   __init__zRise_Transit_Set_Trial.__init__   s	    	r#   c                 
    d|v S )Nz+Rise  Az.       Transit Alt.       Set  Az.r"   r   s     r$   r   zRise_Transit_Set_Trial.matches   s    <GGr#   c                 .   t         j                  |        | j                  D ]q  }d|v rt        |j	                               | _        &d|v s+d|v s0t        |j                         d   j	                  d             t        j                  z  | _
        s y )Nr   z
Time Zone:zwest of Greenwichr   h)r]   rj   rf   r<   rg   r;   intr-   r.   hourtzrq   s     r$   rj   z&Rise_Transit_Set_Trial.examine_content   su    d#JJDd" 24::< @%&$. #DJJLO$9$9#$> ??%**LDG r#   c           	         t               }|j                         }t        t        |d            |d<   t	        t        dj                  |dd       d      dd  }t        j                  t        j                  |      | j                  z
        |_
        fd} ||d      \  |_        |_         ||d      \  |_        |_         ||d	      \  |_        |_        | j"                  j%                  |       y
)u  Determine if our rise/transit/set data match the USNO's.

The file looks something like:
      Date               Rise  Az.       Transit Alt.       Set  Az.
     (Zone)
                          h  m   °         h  m  °          h  m   °
2006 Apr 29 (Sat)        10:11 100        15:45 42S        21:19 260
2006 Apr 30 (Sun)        10:07 100        15:41 42S        21:15 260
2006 May 01 (Mon)        10:03 100        15:37 42S        21:11 260

        Here we save the data in self.data for examination by finish().
        r   rB   r   r   z%Y %m %dc                 t   t        |       |dz   k  ry| ||dz    \  }}|dk(  ry|j                  d      D cg c]  }t        |       c}\  }}t        j                  	|t        j
                  z  z   |t        j                  z  z         }t        j                  |j                  d            }||fS c c}w )Nr   )NNz*****r*   NS)	r   r-   r   r.   rE   r   minuterG   rg   )
r:   rU   timestranglestrsr   rV   rK   anglemidnights
            r$   parsez5Rise_Transit_Set_Trial.check_data_line.<locals>.parse   s    6{QU"!"(1Q3-Wh'!!%,]]3%79%7SV%79DAq::hUZZ7!ell:JJKDMM(.."67E; :s   B5r   r
   r   N)r   r-   rC   rD   r   r   r0   r.   rE   r   r   rising	rising_aztransittransit_altsetting
setting_azr   append)rb   r9   datumr:   rJ   r   r   s         @r$   rp   z&Rise_Transit_Set_Trial.check_data_line   s     
6!9-.q	x! 5zB1QGH::ejjntww67!		 ).fa(8%eo+0+;(u(*/*:'u'		r#   c                 ~  
 | j                   | j                  
| j                  }
fd}t        t	        |            D ]~  }||   dD ]r  }t        |      }|t        d|z         }t        d|z         } |
j                        _         ||        |
j                  dz         _         ||       t  dD ]t  }d}t        t	        |            D ]Y  }||   t        |      }|d}|j                  _         t        d|z         
      _         ||       j                  }[ v dD ]|  }d}	t        t	        |      dz
  dd      D ]\  }||   t        |      }|d}	|	j                  dz   _         t        d|z         
      _         ||       j                  }	^ ~ y)	z2Go back through and verify the data we have saved.c                    t        t        |       j                  t        j                  |        | dk(  r| dz  } j
                  }n| dz  } j                  }t        t        |       |t        j                  |        y )Nr   _alt_az)r[   r`   rK   r.   r   altazdegree)attr	our_anglerh   r   r;   s     r$   checkz,Rise_Transit_Set_Trial.finish.<locals>.check  se    GE4((--tLy  HH	 GG	GE4()U\\4Hr#   )r   r   r   Nnext_	previous_r   r   r+   )r;   rh   r   r   r   r`   r   rK   )rb   r   r   ir   
datum_date	next_funcprevious_funcprevnextrh   r   r;   s             @@@r$   rm   zRise_Transit_Set_Trial.finish   s    ==yyyy	I s4y!AGE8$UD1
) ''D. AI$+HkD6H$IM$-dENN$CHM$K$1$8J$KHM$K 9 "" 5DD3t9%Q$UD1
%D|(-$EGHgn$Ed$KHM$K#==D & 5 5DD3t9q=!R0Q$UD1
%D|(-(:$IGHkD6H$I$$OHM$K#==D 1 5r#   N)	r   r    r!   r   r   r   rj   rp   rm   r"   r#   r$   r   r      s/     H HM$ LE)r#   r   c                   (    e Zd Zed        Zd Zd Zy)Rise_Set_Trialc                 
    d|v S )NzRise and Set forr"   r   s     r$   r   zRise_Set_Trial.matches@  s    !W,,r#   c                    t        j                  d| j                        j                         \  }}|j	                  d      r|dd  }| j                  |      | _        t        |      | _        t        j                  d| j                        j                         \  }}|j                  dd      j                  dd      j                  d	      }|j                  dd      j                  d
d      j                  d      }t        j                         x| _        }||_        ||_        d|_        t#        |       t        j$                  | _        y )NzRise and Set for (.*) for (\d+)zthe r   z&Location: (.\d\d\d \d\d), (.\d\d \d\d)rB   r*   r&   -r'   r)   r(   r   )r1   searchr~   groupsr5   rd   rh   r   yearr,   rg   r.   r/   r;   r4   r3   r7   r8   r   rW   )rb   rc   r   longstrlatstros         r$   rj   zRise_Set_Trial.examine_contentD  s   YYA#||--3VX 	d??6"8D$$T*	I	))$M$(LL228&( 	//#s+33C=CCCHS)11#s;AA#F!NN,,a\\
r#   c                 .     fd} j                    j                  } j                  t        |dd       }t	        dd      D cg c]  }t        |       c}D ]+  }|d|d||dz  dz
  }|||d	z    j                         }||d
z   |dz    j                         }	t        j                  |||f      d
t        j                  z  z   }
|
_	        j                         |rO|
dz   _	        j                        _	         |d|       |
_	        j                        _	         |d|       |	s|
dz   _	        j                        _	         |d|	       |
_	        j                        _	         |d|	       . yc c}w )a  Determine whether PyEphem rising times match those of the USNO.
        Lines from this data file look like:

               Jan.       Feb.       Mar.       Apr.       May    ...
        Day Rise  Set  Rise  Set  Rise  Set  Rise  Set  Rise  Set ...
             h m  h m   h m  h m   h m  h m   h m  h m   h m  h m ...
        01  0743 1740  0734 1808  0707 1834  0626 1858  0549 1921 ...
        02  0743 1741  0734 1809  0705 1835  0624 1859  0548 1922 ...

        Note that times in this kind of file are in Eastern Standard
        Time, so we have to variously add and subtract fives hours
        from our UT times to perform a valid comparison.
        c                 (   |d d dz   |dd  z   }t        j                  d|      }j                  |dt         j                  z  z   z
  }t	        |      j
                  kD  r.t        ddj                  d| d|dj                  
      y )	Nr   r*   rB   r	   zOn z, the USNO thinks that z happens at z but PyEphem finds )r.   rE   rK   r   rS   rW   
ValueErrorrc   )	eventusno_digits
usno_hrmin	usno_date
differencerh   r   rb   usno_datestrs	        r$   two_digit_comparez9Rise_Set_Trial.check_data_line.<locals>.two_digit_compareh  s    $Ra3.QR@J

lJ#GHI9q5::~#=>J:+ $0$))U$."8 9 9 ,r#   r   r   r      /r   r   r   r	   r   risesetN)r;   r   rh   r   r   rg   r.   rE   r   rK   r   previous_risingnext_risingprevious_settingnext_setting)rb   r9   r   r   dayrV   monthoffset	usno_riseusno_setstart_of_dayrh   r   r   s   `          @@@r$   rp   zRise_Set_Trial.check_data_lineY  su   		9 MMyyyy$q)n',Qr{4{!s1v{4E)-uc:LRZ!^FVfqj1779IFQJ!4::<H ::tUC&89A

NJL!AFLLO%)**40!&)4%t,!&)4%)++D1!%2%-!%29 54s   FNr   r"   r#   r$   r   r   ?  s    - -"*:3r#   r   c                   .    e Zd Zed        Zd Zd Zd Zy)Moon_Phasesc                 
    d|v S )NzPhases of the Moonr"   r   s     r$   r   zMoon_Phases.matches  s    #w..r#   c                     t        | j                  d   j                         d         | _        t	        j
                  | j                  f      | _        d| _        y )Nr   F)r   rf   r-   r   r.   rE   rK   past_headingrl   s    r$   rj   zMoon_Phases.examine_content  sB    

1++-a01	JJ		|,	!r#   c                 r   | j                   sd|v rd| _         y d|dd fd|dd fd	|d
d fd|dd ffD ]  \  }}|j                         st        t        d|z        }| j	                  ||       | xj
                  | j
                  dz  z  c_        t        t        d|z        }| j	                  ||        y )Nzd  h  mTnewr      first_quarter       full$   0   last_quarter4   @   znext_%s_moong      =@zprevious_%s_moon)r   rg   r`   r.   verifyrK   )rb   r9   phaserI   funcs        r$   rr   zMoon_Phases.check_line  s       D $(! !&tAbz2 /b= &R4 .R<!NE7
 }}unu&<=D'*		TYY_,	u&85&@AD'*!r#   c                 `   |j                         }t        t        |d            |d<   dj                  |      }t	        t        d| j                  |fz  d      dd  }t        j                  |      } || j                        | _	        t        || j                  t        j                         y )Nr   rB   z%d %sz%Y %m %d %H %Mr	   )r-   rC   rD   r0   r   r   r   r.   rE   rK   r[   r   )rb   r  rI   rH   rJ   rK   s         r$   r  zMoon_Phases.verify  s    z-*:;<a((=)x499g*> > 0223A7 8zz"~O	dii.r#   N)r   r    r!   r   r   rj   rr   r  r"   r#   r$   r   r     s#    / /"
+6/r#   r   c                       e Zd Zd Zy)Mixinc                 N   t        | j                  d      }	 |j                         }|j                          |j	                  d      }t
        j                  dk  r|j                  dd      }t               }|j                         D ]o  }t        |t              st        |t              s%t        |d      s2|j                  |      sD|} |       }| j                  |_        |j!                  |        y  t#        d| j                  z        # |j                          w xY w)Nrbzutf-8)r   r   asciir,   r   z+Cannot find a test trial that recognizes %r)openrv   readclosedecodesysversion_infoencodeglobalsvalues
isinstancetype
issubclassr]   r_   r   r   r   )rb   fr~   gobjtrial_classtrials          r$   	test_usnozMixin.test_usno  s    D!	ffhGGGI..)f$nnWi8GI88:C3%*S%*@C+G0D!#!YY
		'"  F99% & 	& GGIs   D D$N)r   r    r!   r  r"   r#   r$   r  r    s    &r#   r  z/usno/*.txtz.txtrR   zclass Test_z#(unittest.TestCase, Mixin): path = )"globos.pathosr1   r  rx   unittestr   timer   r.   rD   objectr   r<   r8   rP   	arcsecondr[   r]   r   r   r   r   r   r   r  rv   dirname__file__basenamer,   rc   execr"   r#   r$   <module>r)     s.   3 2 2   
 Qq1QQqBr
	F 	$ d ":!F :!|
& 
&0 08$ $(|)U |)@T3U T3p-/% -/b&F &: DIIbggooh/-?@D77D!))&"5Dt	LM A 	$r#   