Ñò
Ž²Kc           @   sÒ  d  d k  Z  d  d k Z d  d k Td  d k l Z d  d k i Z d  d k Z d  d k Te	 d d d g ƒ Z
 e	 d d d g ƒ Z e	 d d d g ƒ Z d Z d Z d Z d Z e ƒ  \ Z Z Z d	 Z d
 „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e e e  d „ Z! d „  Z" d „  Z# d „  Z$ d „  Z% e d „ Z& d „  Z' d „  Z( d „  Z) d „  Z* e d „ Z+ d „  Z, e- d j o,d  d k. Te  i/ ƒ  Z0 e0 i1 e2 d  ƒ ƒ e  i3 d! d" ƒ i4 e0 ƒ d  d k Z e i5 d# ƒ y e i6 d$ Z7 Wn e8 j
 o d# Z7 n Xx“ d% d& d' d( d) g D]| Z9 d* Ge9 GHe: d+ d, d- ƒ Z; d. Ge; GHe! e; e9 d/ e ƒZ< d0 Ge< GHe# e< e9 ƒ Z= d1 Ge= GHe e< e9 ƒ Z> d2 Ge> e; GHq@We7 d3 j oýd Z? d4 Z@ d% ZA d ZB d eC d5 d6 eC d5 d5 eC d5 d7 eC d5 d8 eC d5 g ZD d9 d: d; d< d= d> g ZE d% d& d? d' d( g ZF d" d@ dA dB d g ZG e: e? e@ eA ƒ Z; xReG D]FZH x=eF D]5Z9 d$ ZI x&eD D]ZJ e iK ƒ  e iL eE eI d$ dC e9 eH f ƒ e iM dD ƒ e iN e; e& e e; e9 eJ eB dE eH ƒdF ƒ e iN e; e% e e; e9 eJ ƒ dG ƒ e iO e? e@ e d e d g ƒ e iM dH ƒ e iN e; e% e e; e9 eJ ƒ e& e e; e9 eJ eB dE eH ƒdI ƒ e iP dJ eI e9 eH f ƒ eI d$ 7ZI qœWq‰Wq|WqÎn d S(K   iÿÿÿÿN(   t   *(   t   jng      ð?g        gVçž¯Ò<iè  i    g—ÿ~õàî@c         C   s   t  t |  |  ƒ ƒ S(   N(   t   sqrtt   dot(   t   x(    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt   norm%   s    c         C   s   |  t  d S(   Ng     €f@(   t   pi(   R   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt   deg2rad(   s    c      	   C   s8  |  \ } } } } } } }	 |	 d j p t  ‚ t |	 | d ƒ }
 d } | } x” t d ƒ D]† } t | | | | | | | |	 ƒ \ } } | | } | p Pn t | ƒ } | t } | |
 } t | | ƒ d j  o Pn | } q\ W| t | ƒ :} | d t | d t | d t	 } t
 | ƒ \ } } | | f S(	   NgUgÌ\”d3?i   g        id   gê-™—q=i    i   i   (   t   AssertionErrorR   t   ranget-   phase_space_coordinates_from_orbital_elementsR   t   c_au_per_yrt   abst   Equinoxt   Solsticet   EclipticPolet
   xyztoradec(   t   Et   observert   light_travelt   at   et   it   Omegat   pomegat   Mt   GMt   meanfrequencyt   dMt   lastdMt   iiR   t   vt   dxt   rt   travelt   edxt   rrt   dd(    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt   orbital_elements_to_radec0   s*     (



&c         C   s”   t  | ƒ t t | ƒ t } t t | ƒ } t  |  ƒ t t |  ƒ | } t | | ƒ } t  | ƒ | t | ƒ | } t | | ƒ } | | | f S(   N(   t   cost   ihatt   sint   jhatt   crosst   khat(   R   R   R   t   ascendingnodevectort   tmpydirt   zhatt   xhatt   yhat(    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt%   orbital_vectors_from_orbital_elementsN   s    c   
      C   sa   t  | | ƒ } t | ƒ } t | ƒ } | t d | d ƒ } | | | |  | | | }	 |	 S(   Ng      ð?i   (   t#   eccentric_anomaly_from_mean_anomalyR'   R)   R   (
   R0   R1   R   R   R   R   t   cosEt   sinEt   bR   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt   position_from_orbital_vectorsW   s    c         C   sÏ   t  | | | ƒ \ } } }	 t | |  d ƒ }
 t | | ƒ } t | ƒ } t | ƒ } d d | | |
 } |  t d | d ƒ } |  | | | | | | } |  | | | | | | | } | | f S(   Ni   g      ð?i   (   R2   R   R3   R'   R)   (   R   R   R   R   R   R   R   R0   R1   R/   t   dMdtR   R4   R5   t   dEdtR6   R   R   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyR
   i   s    #c         C   sø  d t  | | ƒ | t |  ƒ } | d j  p t ‚ t |  | ƒ } | t | ƒ } t | | ƒ | |  t |  ƒ } t | ƒ } | d j o# t t | ƒ } | t | ƒ :} n | | } t | | ƒ }	 d | | }
 t | |
 d ƒ } t | d t | ƒ ƒ } | d j o
 d } nd t | d | d ƒ d t } | d j  o | d t 7} n | d j  o | d	 9} | t 7} n t	 | ƒ } t
 | ƒ } | d j o d | } n. t t d
 | d | | d | | ƒ ƒ } | | d | d | | d | d | | d | d | | d | d } | d j  o d t | } n | d j  o | d t 7} n | d t j o | d t 8} n t t  |	 |  ƒ t  | |  ƒ ƒ } t | | ƒ } | d j  o | d t 7} n |
 | | | | | f S(   Ng      à?g        i    g      à¿i   i   i   g       @g      ð¿g      ð?(   R   R   R   R+   R*   R   t   arccost   arctan2R   R'   R)   t   mint   mean_anomaly_from_true_anomaly(   R   R   R   t   energyt   angmomR/   t   evecR   R0   R1   R   R8   R   R   t   cosOmegat   sinOmegaR   t   horriblescalart   fR   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt-   orbital_elements_from_phase_space_coordinates{   sN    !!


-R!c         C   s   |  | t  |  ƒ S(   N(   R)   (   R   R   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt#   mean_anomaly_from_eccentric_anomaly¯   s    c         C   s   t  t |  | ƒ | ƒ S(   N(   RF   t#   eccentric_anomaly_from_true_anomaly(   RD   R   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyR=   ²   s    c         C   s™   |  | t  |  ƒ } d } d } x^ | | j  oP t | ƒ | j o= |  t | | ƒ } | | d | t | ƒ } | d 7} q# W| o d G| GHn | S(   Ni    g      Y@g      ð?i   s   eccentric anomaly iterations:(   R)   R   RF   R'   (   R   R   t	   tolerancet   maximum_iterationt   verboseR   t	   iterationt   deltaM(    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyR3   »   s       c         C   sR   t  t |  ƒ | d | t |  ƒ ƒ } | t t |  ƒ ƒ t t | ƒ ƒ 9} | S(   Ng      ð?(   R:   R'   t   signR)   (   RD   R   R   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyRG   Ç   s    (&c         C   sR   t  t |  ƒ | d | t |  ƒ ƒ } | t t | ƒ ƒ t t |  ƒ ƒ 9} | S(   Ng      ð?(   R:   R'   RM   R)   (   R   R   RD   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt#   true_anomaly_from_eccentric_anomalyÐ   s    (&c         C   s    |  t  | | ƒ | t  | ƒ S(   N(   R)   (   t   KRD   R   R   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt   radial_velocityÛ   s    c         C   sš   | | t  | ƒ } t | ƒ t d | d ƒ t  | ƒ d | t | ƒ } t  | ƒ t | ƒ | d | t | ƒ } | t  | ƒ } |  | | | S(   Ni   i   (   R)   R'   R   (   RO   R   R   R   R   t   term1t   term2t   term3(    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt   radial_velocity_from_Mä   s
    :,c      	   C   s   d } xr t  d | d d ƒ D]Z } | |  t | | | | ƒ t | | | ƒ t | | | | ƒ t | | | ƒ 7} q W| S(   Ng        i    i   (   t   aranget   fourier_coeff_AR'   t   fourier_coeff_BR)   (   RO   R   R   R   t   phit   ordert   vrt   n(    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt   radial_velocity_fourier_seriesó   s     *.c         C   sR   t  d | d ƒ t  d | d ƒ d | t |  |  | ƒ t |  d |  | ƒ S(   Ng      ð?i   i   (   R   R   (   R[   R   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt   aprime   s    c         C   sR   t  d | d ƒ t  d | d ƒ d | t |  |  | ƒ t |  d |  | ƒ S(   Ng      ð?i   i   (   R   R   (   R[   R   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt   bprime  s    c         C   sB   d t  |  | ƒ t | |  | ƒ t |  | ƒ t | |  | ƒ S(   Ng      à?(   R]   R)   R^   (   R[   R   RX   R   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyRV     s    c         C   sB   d t  |  | ƒ t | |  | ƒ t |  | ƒ t | |  | ƒ S(   Ng      à?(   R]   R'   R^   (   R[   R   RX   R   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyRW   	  s    c         C   sR   g  } xE t  | ƒ D]7 } | i t | | | | ƒ t | | | | ƒ f ƒ q W| S(   N(   R	   t   appendRV   RW   (   RO   RX   R   R   RY   t
   amplitudesR[   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt"   radial_velocity_fourier_amplitudes  s
     5c         C   sT   t  t d d t d d ƒ } t t d t d ƒ } d } d } | | | | f S(   Ni    i   i   (   R   t	   amplitudet   arctan(   R`   RO   RX   R   R   (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt$   eccentricity_from_fourier_amplitudes  s
     t   __main__t   testAgainstJPL_2t	   verbosityi   i    i   g{®Gáz„?gš™™™™™¹?gÍÌÌÌÌÌì?g®Gáz®ï?g+‡ÙÎ÷ï?s   eccentricity:gHáz®G	Àg…ëQ¸	Àgü©ñÒMbP?s   mean anomaly input:RJ   s   eccentric anomaly output:s   true anomaly output:s   round-trip error:t   plotg      4@g      @g      @g      @g      "@s   pomega = $0.0$s   pomega = $\pi/5$s   pomega = $3\pi/5$s   pomega = $\pi$s   pomega = $7\pi/5$s   pomega = $9\pi/5$g      à?i   i   i   s   , e = %.2f, n = %iiÓ   RY   R!   s   k--iÔ   t   ks3   celestial_mechanics_plots/pomega_%i_e_%.2f_n_%i.png(Q   t   unittestt   numpyt   scipy.specialR   t   matplotlib.pyplott   pyplott   pltt   syst   astrometry.util.starutil_numpyt   arrayR(   R*   R,   t   default_tolerancet   default_maximum_iterationt   default_ordert	   default_Kt   ecliptic_basisR   R   R   R   R   R   t   TrueR&   R2   R7   R
   RE   RF   R=   t   FalseR3   RG   RN   RP   RT   R\   R]   R^   RV   RW   Ra   Rd   t   __name__t   test_celestial_mechanicst	   TestSuitet   suitet   addTestt   TestOrbitalElementst   TextTestRunnert   runt   exitt   argvt   arg1t
   IndexErrorR   RU   R   R   RD   t   M2t	   range_mint	   range_maxt	   step_sizet   phaseR   t   pomegast   pomegas_strt   eccenst   ordersR[   R   R   t   clft   suptitlet   subplotRh   t   axist   savefig(    (    (    s<   /home/dstn/astrometry/projects/holmes/celestial_mechanics.pyt   <module>   s°   

							4														

 				<   
#+""#
