σ
 m[c           @` sv   d  Z  d d l m Z m Z m Z m Z d d l Z d d l Z d d l Z	 d d l
 m Z d e f d     YZ d S(   u   Epoch module.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   date2numt   Epochc           B` s¦   e  Z i i d  
d 6d 6i d d 6d 6Z d d d d d  Z d   Z d   Z d   Z d   Z d	   Z	 d
   Z
 d   Z d   Z d   Z d   Z e e  Z RS(   g oΕP@u   UTCu   ETg oΕPΐc         C` s+  | d k r | d k	 sί | d k	 r0 | d k sί | d k	 rT | d k	 sί | d k	 sί | d k r | d k r | d k sί | d k sί | d k	 r | d k	 sί | d k	 rΐ | d k	 sί | d k	 sί | d k	 rt | t j  rd t |  t |  t |  t |  f } t |   n  | |  j k rbd | t t t j	 |  j    f } t |   n  | |  _
 | d k	 rt |  } n  | d k	 rΛt |  d } t j |  |  _ | |  j d |  _ n\ t |  |  _ t |  |  _ t t j |  j d   } |  j | 7_ |  j | d 8_ d S(   uz  Create a new Epoch object.

      Build an epoch 1 of 2 ways:

      Using seconds past a Julian date:
      #   Epoch( 'ET', sec=1e8, jd=2451545 )

      or using a matplotlib day number
      #   Epoch( 'ET', daynum=730119.5 )


      = ERROR CONDITIONS
      - If the input units are not in the allowed list, an error is thrown.

      = INPUT VARIABLES
      - frame    The frame of the epoch.  Must be 'ET' or 'UTC'
      - sec      The number of seconds past the input JD.
      - jd       The Julian date of the epoch.
      - daynum   The matplotlib day number of the epoch.
      - dt       A python datetime instance.
      u   Invalid inputs.  Must enter sec and jd together, daynum by itself, or dt (must be a python datetime).
Sec = %s
JD  = %s
dnum= %s
dt  = %su9   Input frame '%s' is not one of the supported frames of %sg   QD:Ag     υ@N(   t   Nonet
   isinstancet   DTt   datetimet   strt
   ValueErrort   allowedt   listt   sixt   iterkeyst   _frameR   t   floatt   matht   floort   _jdt   _secondst   int(   t   selft   framet   sect   jdt   daynumt   dtt   msgt	   deltaDays(    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyt   __init__'   s4    $0$+%	c         C` sA   |  j  | k r |  S|  j |  j  | } t | |  j | |  j  S(   N(   R   R   R   R   R   (   R   R   t   offset(    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyt   convertd   s    c         C` s   |  j  S(   N(   R   (   R   (    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyR   m   s    c         C` s9   |  } | |  j  k r' |  j |  } n  | j | j d S(   Ng     υ@(   R   R!   R   R   (   R   R   t   t(    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyt
   julianDateq   s    c         C` sC   |  } | |  j  k r' |  j |  } n  | j | } | j | d S(   NiQ (   R   R!   R   R   (   R   R   R   R"   t   delta(    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyt   secondsPasty   s
    c         C` se   |  } |  j  | j  k r- |  j | j   } n  | j | j k rR t | j | j  St | j | j  S(   u½   Compare two Epoch's.

      = INPUT VARIABLES
      - rhs    The Epoch to compare against.

      = RETURN VALUE
      - Returns -1 if self < rhs, 0 if self == rhs, +1 if self > rhs.
      (   R   R!   R   t   cmpR   (   R   t   rhsR"   (    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyt   __cmp__   s    	c         C` sY   |  } |  j  | j   k r0 |  j | j   } n  | j | j   } t | j  | | j  S(   uΈ   Add a duration to an Epoch.

      = INPUT VARIABLES
      - rhs    The Epoch to subtract.

      = RETURN VALUE
      - Returns the difference of ourselves and the input Epoch.
      (   R   R   R!   R   t   secondsR   R   (   R   R'   R"   R   (    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyt   __add__   s
    	c         C` s   d d l  j j } t | | j  r- |  | S|  } |  j | j k rZ |  j | j  } n  | j | j } | j | j } | j | j | d |  S(   ug  Subtract two Epoch's or a Duration from an Epoch.

      Valid:
      Duration = Epoch - Epoch
      Epoch = Epoch - Duration

      = INPUT VARIABLES
      - rhs    The Epoch to subtract.

      = RETURN VALUE
      - Returns either the duration between to Epoch's or the a new
        Epoch that is the result of subtracting a duration from an epoch.
      i    NiQ (	   t   matplotlib.testing.jpl_unitst   testingt	   jpl_unitsR   t   DurationR   R!   R   R   (   R   R'   t   UR"   t   daysR   (    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyt   __sub__§   s    	c         C` s   d |  j  |  j  |  j f S(   u   Print the Epoch.u
   %22.15e %s(   R#   R   (   R   (    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyt   __str__Ζ   s    c         C` s
   t  |   S(   u   Print the Epoch.(   R
   (   R   (    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyt   __repr__Λ   s    c         C` sR   g  } d } x? t  rM |  | | } | | k r3 Pn  | j |  | d 7} q W| S(   u­  Generate a range of Epoch objects.

      Similar to the Python range() method.  Returns the range [
      start, stop ) at the requested step.  Each element will be a
      Epoch object.

      = INPUT VARIABLES
      - start    The starting value of the range.
      - stop     The stop value of the range.
      - step     Step to use.

      = RETURN VALUE
      - Returns a list contianing the requested Epoch values.
      i    i   (   t   Truet   append(   t   startt   stopt   stept   elemst   it   d(    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyt   rangeΠ   s    	N(   t   __name__t
   __module__R   R   R   R!   R   R#   R%   R(   R*   R1   R2   R3   R<   t   staticmethod(    (    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyR      s"   =												(   t   __doc__t
   __future__R    R   R   R   R   R   R	   R   t   matplotlib.datesR   t   objectR   (    (    (    sA   lib/python2.7/site-packages/matplotlib/testing/jpl_units/Epoch.pyt   <module>   s   "