ó
 m[c           @` sN   d  Z  d d l m Z m Z m Z m Z d d l Z d e f d „  ƒ  YZ d S(   u   UnitDbl module.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNt   UnitDblc           B` s!  e  Z d  Z i d# d 6d$ d 6d% d 6d& d 6d' d	 6d( d
 6d) d 6d* d 6Z i d d 6d d 6d d
 6Z d „  Z d „  Z d „  Z d „  Z d „  Z	 e
 j r¤ e	 Z n  d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d+ d  „ Z e e ƒ Z d! „  Z d" „  Z RS(,   u!   Class UnitDbl in development.
   gü©ñÒMbP?u   kmu   mi   g 8€~ß¿ù?u   mileu   radg:R¢Fß‘?u   degu   secg      N@u   mini  u   houru   distanceu   angleu   timec         C` sB   |  j  | ƒ |  j | } t | | d ƒ |  _ | d |  _ d S(   u,  Create a new UnitDbl object.

      Units are internally converted to km, rad, and sec.  The only
      valid inputs for units are [ m, km, mile, rad, deg, sec, min, hour ].

      The field UnitDbl.value will contain the converted value.  Use
      the convert() method to get a specific type of units back.

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

      = INPUT VARIABLES
      - value    The numeric value of the UnitDbl.
      - units    The string name of the units the value is in.
      i    i   N(   t
   checkUnitst   allowedt   floatt   _valuet   _units(   t   selft   valuet   unitst   data(    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   __init__3   s    c         C` sw   |  j  | k r |  j S|  j | ƒ |  j | } |  j  | d k rh d t |  ƒ | f } t | ƒ ‚ n  |  j | d S(   ul  Convert the UnitDbl to a specific set of units.

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

      = INPUT VARIABLES
      - units    The string name of the units to convert to.

      = RETURN VALUE
      - Returns the value of the UnitDbl in the requested units as a floating
        point number.
      i   uk   Error trying to convert to different units.
   Invalid conversion requested.
   UnitDbl: %s
   Units:   %s
i    (   R	   R   R   R   t   strt
   ValueError(   R
   R   R   t   msg(    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   convertJ   s    c         C` s   t  t |  j ƒ |  j ƒ S(   u*   Return the absolute value of this UnitDbl.(   R   t   absR   R	   (   R
   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   __abs__g   s    c         C` s   t  |  j |  j ƒ S(   u*   Return the negative value of this UnitDbl.(   R   R   R	   (   R
   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   __neg__l   s    c         C` s'   t  j r |  j j ƒ  S|  j j ƒ  Sd S(   up   Test a UnitDbl for a non-zero value.

      = RETURN VALUE
      - Returns true if the value is non-zero.
      N(   t   sixt   PY3R   t   __bool__t   __nonzero__(   R
   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyR   q   s    	c         C` s#   |  j  | d ƒ t |  j | j ƒ S(   u5  Compare two UnitDbl's.

      = ERROR CONDITIONS
      - If the input rhs units are not the same as our units,
        an error is thrown.

      = INPUT VARIABLES
      - rhs    The UnitDbl to compare against.

      = RETURN VALUE
      - Returns -1 if self < rhs, 0 if self == rhs, +1 if self > rhs.
      u   compare(   t   checkSameUnitst   cmpR   (   R
   t   rhs(    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   __cmp__€   s    c         C` s*   |  j  | d ƒ t |  j | j |  j ƒ S(   u  Add two UnitDbl's.

      = ERROR CONDITIONS
      - If the input rhs units are not the same as our units,
        an error is thrown.

      = INPUT VARIABLES
      - rhs    The UnitDbl to add.

      = RETURN VALUE
      - Returns the sum of ourselves and the input UnitDbl.
      u   add(   R   R   R   R	   (   R
   R   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   __add__‘   s    c         C` s*   |  j  | d ƒ t |  j | j |  j ƒ S(   u,  Subtract two UnitDbl's.

      = ERROR CONDITIONS
      - If the input rhs units are not the same as our units,
        an error is thrown.

      = INPUT VARIABLES
      - rhs    The UnitDbl to subtract.

      = RETURN VALUE
      - Returns the difference of ourselves and the input UnitDbl.
      u   subtract(   R   R   R   R	   (   R
   R   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   __sub__¢   s    c         C` s   t  |  j | |  j ƒ S(   uŸ   Scale a UnitDbl by a value.

      = INPUT VARIABLES
      - rhs    The scalar to multiply by.

      = RETURN VALUE
      - Returns the scaled UnitDbl.
      (   R   R   R	   (   R
   R   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   __mul__³   s    	c         C` s   t  |  j | |  j ƒ S(   uŸ   Scale a UnitDbl by a value.

      = INPUT VARIABLES
      - lhs    The scalar to multiply by.

      = RETURN VALUE
      - Returns the scaled UnitDbl.
      (   R   R   R	   (   R
   t   lhs(    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   __rmul__¿   s    	c         C` s   t  |  j | |  j ƒ S(   už   Divide a UnitDbl by a value.

      = INPUT VARIABLES
      - rhs    The scalar to divide by.

      = RETURN VALUE
      - Returns the scaled UnitDbl.
      (   R   R   R	   (   R
   R   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   __div__Ë   s    	c         C` s   d |  j  |  j f S(   u   Print the UnitDbl.u   %g *%s(   R   R	   (   R
   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   __str__×   s    c         C` s   d |  j  |  j f S(   u   Print the UnitDbl.u   UnitDbl( %g, '%s' )(   R   R	   (   R
   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   __repr__Ü   s    c         C` s   |  j  |  j S(   u    Return the type of UnitDbl data.(   t   _typesR	   (   R
   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   typeá   s    c         C` ss   | d k r! t d |  j ƒ } n  g  } d } x? t rn |  | | } | | k rT Pn  | j | ƒ | d 7} q0 W| S(   u  Generate a range of UnitDbl objects.

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

      = INPUT VARIABLES
      - start    The starting value of the range.
      - stop     The stop value of the range.
      - step     Optional step to use.  If set to None, then a UnitDbl of
                 value 1 w/ the units of the start is used.

      = RETURN VALUE
      - Returns a list contianing the requested UnitDbl values.
      i   i    N(   t   NoneR   R	   t   Truet   append(   t   startt   stopt   stept   elemst   it   d(    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   rangeæ   s    	c         C` sJ   | |  j  k rF d | t t t j |  j  ƒ ƒ ƒ f } t | ƒ ‚ n  d S(   uã   Check to see if some units are valid.

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

      = INPUT VARIABLES
      - units    The string name of the units to check.
      u9   Input units '%s' are not one of the supported types of %sN(   R   R   t   listR   t   iterkeysR   (   R
   R   R   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyR   	  s    	%c         C` s>   |  j  | j  k r: d | |  j  | j  f } t | ƒ ‚ n  d S(   u0  Check to see if units are the same.

      = ERROR CONDITIONS
      - If the units of the rhs UnitDbl are not the same as our units,
        an error is thrown.

      = INPUT VARIABLES
      - rhs    The UnitDbl to check for the same units
      - func   The name of the function doing the check.
      u3   Cannot %s units of different types.
LHS: %s
RHS: %sN(   R	   R   (   R
   R   t   funcR   (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyR     s    (   gü©ñÒMbP?u   km(   i   u   km(   g 8€~ß¿ù?u   km(   i   u   rad(   g:R¢Fß‘?u   rad(   i   u   sec(   g      N@u   sec(   i  u   secN(   t   __name__t
   __module__t   __doc__R   R&   R   R   R   R   R   R   R   R   R   R   R   R    R"   R#   R$   R%   R'   R(   R1   t   staticmethodR   R   (    (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyR      sD   

																 	(	   R7   t
   __future__R    R   R   R   R   t   objectR   (    (    (    sC   lib/python2.7/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyt   <module>   s   "