
[c           @` sm  d  Z  d d l m Z m Z m Z m Z d d l m Z d d l m	 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 m Z d d l m Z d d	 l m Z m Z d
 d l m Z m Z m Z m Z d
 d l m Z e j  r
d d l! Z! n  d d d d d d d d d d d d d d d d d d d g Z" d    Z# d!   Z$ d" e% f d#     YZ& d$ e% f d%     YZ' e&   g Z( d&   Z) d'   Z* d(   Z+ d)   Z, d*   Z- d+ e. f d,     YZ/ d- e/ e0 f d.     YZ1 d/ e/ e0 f d0     YZ2 d1 e/ e3 f d2     YZ4 d3 e f d4     YZ5 e j6 e  d5 e% f d6     Y Z7 d7 e7 f d8     YZ8 d9   Z9 d: e8 f d;     YZ: d< e: f d=     YZ; d> e f d?     YZ< e j6 e<  d@ e8 f dA     Y Z= dB e= f dC     YZ> dD e7 f dE     YZ? dF g dG g dH f dI g dJ g dK f dL g dM g dN f dO g dP g dQ f dR g dS g dT f dU g dV g dW f dX g dY g dZ f d[ g d\ g d] f d^ g d_ g d` f da g db dc g dd f de g df g dg f dh g di g dj f dk g dl g dm f dn g do g dp f dq g dr g ds f dt g du g dv f dw g dx g dy f dz g d{ g d| f d} g d~ g d f d g d g d f g Z@ d g d g d d f d g d g d d f d g d g d d f d g d g d d f d g d g d d f d g d g d d f g ZA g  eB eC d  ZD eB eB eB eC g  eB d  ZE d   ZF e? d
 g  g  d eC ZG eG ZH e1 e jI _1 d S(   u"   
Core units classes and functions
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   six(   t   zipN(   t   lazypropertyt
   deprecated(   t   AstropyWarning(   t
   isiterablet   InheritDocstringsi   (   t   is_effectively_unityt   sanitize_scalet   validate_powert   resolve_fractions(   t   formatu
   UnitsErroru   UnitsWarningu   UnitConversionErroru   UnitTypeErroru   UnitBaseu	   NamedUnitu   IrreducibleUnitu   Unitu   CompositeUnitu
   PrefixUnitu   UnrecognizedUnitu   def_unitu   get_current_unit_registryu   set_enabled_unitsu   add_enabled_unitsu   set_enabled_equivalenciesu   add_enabled_equivalenciesu   dimensionless_unscaledu   onec         C` s   t  |  t  s |  g }  n  t   } x |  D] } t  | t  rP | j |  q+ t  | t  rn | j   } n< t j |  r t	 |  j   } n t
 |  r+ | } n q+ x- | D]% } t  | t  r | j |  q q Wq+ W| S(   u   
    Given a list of sequences, modules or dictionaries of units, or
    single units, return a flat set of all the units found.
    (   t
   isinstancet   listt   sett   UnitBaset   addt   dictt   valuest   inspectt   ismodulet   varsR	   (   t   itemst   resultt   itemt   unitst   unit(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   _flatten_units_collection(   s"    		c         C` sP  |  d k r g  Sg  } x3t |   D]%\ } } t |  d k r] | \ } } d   } } ni t |  d k r | \ } } } | } n? t |  d k r | \ } } } } n t d j | |    | t |  k o| d k s | t |  k ot j |  ot j |  s/t d j | |    n  | j | | | | f  q# W| S(   u  
    Normalizes equivalencies, ensuring each is a 4-tuple of the form::

    (from_unit, to_unit, forward_func, backward_func)

    Parameters
    ----------
    equivalencies : list of equivalency pairs

    Raises
    ------
    ValueError if an equivalency cannot be interpreted
    i   c         S` s   |  S(   N(    (   t   x(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   <lambda>[   s    i   i   u$   Invalid equivalence entry {0}: {1!r}N(	   t   Nonet	   enumeratet   lent
   ValueErrorR   t   UnitR   t   callablet   append(   t   equivalenciest
   normalizedt   it   equivt   funitt   tunitt   at   b(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   _normalize_equivalenciesE   s,    	t   _UnitRegistryc           B` s   e  Z d  Z g  g  d  Z d   Z d   Z e d    Z e d    Z e d    Z	 d   Z
 d   Z d	   Z e d
    Z d   Z d   Z RS(   u2   
    Manages a registry of the enabled units.
    c         C` s   t  | t  ry | j j   |  _ | j j   |  _ | j j   |  _ | j j   |  _ d   t j | j	  D |  _	 n. |  j
   |  j   |  j |  |  j |  d  S(   Nc         S` s%   i  |  ] \ } } | j    |  q S(    (   t   copy(   t   .0t   kt   v(    (    s1   lib/python2.7/site-packages/astropy/units/core.pys
   <dictcomp>   s   	 (   R   R2   t   _equivalenciesR3   t
   _all_unitst	   _registryt   _non_prefix_unitsR   t	   iteritemst   _by_physical_typet   _reset_unitst   _reset_equivalenciest   add_enabled_unitst   add_enabled_equivalencies(   t   selft   initR)   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __init__t   s    

c         C` s.   t    |  _ t    |  _ i  |  _ i  |  _ d  S(   N(   R   R8   R:   R9   R<   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR=      s    	c         C` s   t    |  _ d  S(   N(   R   R7   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR>      s    c         C` s   |  j  S(   N(   R9   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   registry   s    c         C` s   |  j  S(   N(   R8   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt	   all_units   s    c         C` s   |  j  S(   N(   R:   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   non_prefix_units   s    c         C` s   |  j    |  j |  S(   u?  
        Sets the units enabled in the unit registry.

        These units are searched when using
        `UnitBase.find_equivalent_units`, for example.

        Parameters
        ----------
        units : list of sequences, dicts, or modules containing units, or units
            This is a list of things in which units may be found
            (sequences, dicts or modules), or units themselves.  The
            entire set will be "enabled" for searching through by
            methods like `UnitBase.find_equivalent_units` and
            `UnitBase.compose`.
        (   R=   R?   (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   set_enabled_units   s    
c         C` s   t  |  } x | D] } xK | j D]@ } | |  j k r# | |  j | k r# t d j |    q# q# Wx | j D] } | |  j | <qq W|  j j |  t | t  s |  j	 j |  n  | j
   } |  j j | t    j |  q Wd S(   uZ  
        Adds to the set of units enabled in the unit registry.

        These units are searched when using
        `UnitBase.find_equivalent_units`, for example.

        Parameters
        ----------
        units : list of sequences, dicts, or modules containing units, or units
            This is a list of things in which units may be found
            (sequences, dicts or modules), or units themselves.  The
            entire set will be added to the "enabled" set for
            searching through by methods like
            `UnitBase.find_equivalent_units` and `UnitBase.compose`.
        uw   Object with name {0!r} already exists in namespace. Filter the set of units to avoid name clashes before enabling them.N(   R   t   _namesR9   R%   R   R8   R   R   t
   PrefixUnitR:   t   _get_physical_type_idR<   t
   setdefaultR   (   RA   R   R   t   stt   hash(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR?      s    "c         C` s   |  j  j | j   t    S(   u   
        Get all units in the registry with the same physical type as
        the given unit.

        Parameters
        ----------
        unit : UnitBase instance
        (   R<   t   getRJ   R   (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   get_units_with_physical_type   s    	c         C` s   t  |  j  S(   N(   R   R7   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR)      s    c         C` s   |  j    |  j |  S(   u  
        Sets the equivalencies enabled in the unit registry.

        These equivalencies are used if no explicit equivalencies are given,
        both in unit conversion and in finding equivalent units.

        This is meant in particular for allowing angles to be dimensionless.
        Use with care.

        Parameters
        ----------
        equivalencies : list of equivalent pairs
            E.g., as returned by
            `~astropy.units.equivalencies.dimensionless_angles`.
        (   R>   R@   (   RA   R)   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   set_enabled_equivalencies   s    
c         C` s%   t  |  } |  j t |  O_ d S(   u  
        Adds to the set of equivalencies enabled in the unit registry.

        These equivalencies are used if no explicit equivalencies are given,
        both in unit conversion and in finding equivalent units.

        This is meant in particular for allowing angles to be dimensionless.
        Use with care.

        Parameters
        ----------
        equivalencies : list of equivalent pairs
            E.g., as returned by
            `~astropy.units.equivalencies.dimensionless_angles`.
        N(   R1   R7   R   (   RA   R)   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR@      s    (   t   __name__t
   __module__t   __doc__RC   R=   R>   t   propertyRD   RE   RF   RG   R?   RO   R)   RP   R@   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR2   o   s   				&		t   _UnitContextc           B` s)   e  Z g  g  d   Z d   Z d   Z RS(   c         C` s    t  j t d | d |   d  S(   NRB   R)   (   t   _unit_registriesR(   R2   (   RA   RB   R)   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRC     s    c         C` s   d  S(   N(    (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt	   __enter__  s    c         C` s   t  j   d  S(   N(   RV   t   pop(   RA   t   typet   valuet   tb(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __exit__  s    (   RQ   RR   RC   RW   R\   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRU     s   	c           C` s   t  d S(   Ni(   RV   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   get_current_unit_registry  s    c         C` s)   t  d t   j  } t   j |   | S(   uh  
    Sets the units enabled in the unit registry.

    These units are searched when using
    `UnitBase.find_equivalent_units`, for example.

    This may be used either permanently, or as a context manager using
    the ``with`` statement (see example below).

    Parameters
    ----------
    units : list of sequences, dicts, or modules containing units, or units
        This is a list of things in which units may be found
        (sequences, dicts or modules), or units themselves.  The
        entire set will be "enabled" for searching through by methods
        like `UnitBase.find_equivalent_units` and `UnitBase.compose`.

    Examples
    --------

    >>> from astropy import units as u
    >>> with u.set_enabled_units([u.pc]):
    ...     u.m.find_equivalent_units()
    ...
      Primary name | Unit definition | Aliases
    [
      pc           | 3.08568e+16 m   | parsec  ,
    ]
    >>> u.m.find_equivalent_units()
      Primary name | Unit definition | Aliases
    [
      AU           | 1.49598e+11 m   | au, astronomical_unit ,
      Angstrom     | 1e-10 m         | AA, angstrom          ,
      cm           | 0.01 m          | centimeter            ,
      earthRad     | 6.3781e+06 m    | R_earth, Rearth       ,
      jupiterRad   | 7.1492e+07 m    | R_jup, Rjup, R_jupiter, Rjupiter ,
      lyr          | 9.46073e+15 m   | lightyear             ,
      m            | irreducible     | meter                 ,
      micron       | 1e-06 m         |                       ,
      pc           | 3.08568e+16 m   | parsec                ,
      solRad       | 6.957e+08 m     | R_sun, Rsun           ,
    ]
    R)   (   RU   R]   R)   RG   (   R   t   context(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRG   "  s    -c         C` s#   t  t    } t   j |   | S(   u  
    Adds to the set of units enabled in the unit registry.

    These units are searched when using
    `UnitBase.find_equivalent_units`, for example.

    This may be used either permanently, or as a context manager using
    the ``with`` statement (see example below).

    Parameters
    ----------
    units : list of sequences, dicts, or modules containing units, or units
        This is a list of things in which units may be found
        (sequences, dicts or modules), or units themselves.  The
        entire set will be added to the "enabled" set for searching
        through by methods like `UnitBase.find_equivalent_units` and
        `UnitBase.compose`.

    Examples
    --------

    >>> from astropy import units as u
    >>> from astropy.units import imperial
    >>> with u.add_enabled_units(imperial):
    ...     u.m.find_equivalent_units()
    ...
      Primary name | Unit definition | Aliases
    [
      AU           | 1.49598e+11 m   | au, astronomical_unit ,
      Angstrom     | 1e-10 m         | AA, angstrom          ,
      cm           | 0.01 m          | centimeter            ,
      earthRad     | 6.3781e+06 m    | R_earth, Rearth       ,
      ft           | 0.3048 m        | foot                  ,
      fur          | 201.168 m       | furlong               ,
      inch         | 0.0254 m        |                       ,
      jupiterRad   | 7.1492e+07 m    | R_jup, Rjup, R_jupiter, Rjupiter ,
      lyr          | 9.46073e+15 m   | lightyear             ,
      m            | irreducible     | meter                 ,
      mi           | 1609.34 m       | mile                  ,
      micron       | 1e-06 m         |                       ,
      mil          | 2.54e-05 m      | thou                  ,
      nmi          | 1852 m          | nauticalmile, NM      ,
      pc           | 3.08568e+16 m   | parsec                ,
      solRad       | 6.957e+08 m     | R_sun, Rsun           ,
      yd           | 0.9144 m        | yard                  ,
    ]
    (   RU   R]   R?   (   R   R^   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR?   V  s    1c         C` s#   t  t    } t   j |   | S(   uE  
    Sets the equivalencies enabled in the unit registry.

    These equivalencies are used if no explicit equivalencies are given,
    both in unit conversion and in finding equivalent units.

    This is meant in particular for allowing angles to be dimensionless.
    Use with care.

    Parameters
    ----------
    equivalencies : list of equivalent pairs
        E.g., as returned by
        `~astropy.units.equivalencies.dimensionless_angles`.

    Examples
    --------
    Exponentiation normally requires dimensionless quantities.  To avoid
    problems with complex phases::

        >>> from astropy import units as u
        >>> with u.set_enabled_equivalencies(u.dimensionless_angles()):
        ...     phase = 0.5 * u.cycle
        ...     np.exp(1j*phase)  # doctest: +SKIP
        <Quantity  -1. +1.22464680e-16j>
    (   RU   R]   RP   (   R)   R^   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRP     s    c         C` s#   t  t    } t   j |   | S(   u/  
    Adds to the equivalencies enabled in the unit registry.

    These equivalencies are used if no explicit equivalencies are given,
    both in unit conversion and in finding equivalent units.

    This is meant in particular for allowing angles to be dimensionless.
    Since no equivalencies are enabled by default, generally it is recommended
    to use `set_enabled_equivalencies`.

    Parameters
    ----------
    equivalencies : list of equivalent pairs
        E.g., as returned by
        `~astropy.units.equivalencies.dimensionless_angles`.
    (   RU   R]   R@   (   R)   R^   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR@     s    t
   UnitsErrorc           B` s   e  Z d  Z RS(   u6   
    The base class for unit-specific exceptions.
    (   RQ   RR   RS   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR_     s   t   UnitScaleErrorc           B` s   e  Z d  Z RS(   ug   
    Used to catch the errors involving scaled units,
    which are not recognized by FITS format.
    (   RQ   RR   RS   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR`     s   t   UnitConversionErrorc           B` s   e  Z d  Z RS(   u}   
    Used specifically for errors related to converting between units or
    interpreting units in terms of other units.
    (   RQ   RR   RS   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRa     s   t   UnitTypeErrorc           B` s   e  Z d  Z RS(   u   
    Used specifically for errors in setting to units not allowed by a class.

    E.g., would be raised if the unit of an `~astropy.coordinates.Angle`
    instances were set to a non-angular unit.
    (   RQ   RR   RS   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRb     s   t   UnitsWarningc           B` s   e  Z d  Z RS(   u4   
    The base class for unit-specific warnings.
    (   RQ   RR   RS   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRc     s   R   c           B` ss  e  Z d  Z d Z d   Z d   Z d   Z e j r? e Z	 n  d   Z
 e j sZ e
 Z	 n  d   Z d   Z e d    Z e d	    Z e d
    Z e d    Z e d    Z e d    Z e j d  Z d   Z e d    Z d   Z d   Z d   Z e Z e Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( g  d  Z) g  d  Z* d    Z+ g  d!  Z, d"   Z- d# g  d$  Z. d# g  d%  Z/ e0   d&  Z1 g  g  d' d( d4 d)  Z3 g  d4 d' e4 d*  Z5 d+   Z6 e7 d,    Z8 e7 d-    Z9 e d.    Z: g  d/  Z; d0 e< f d1     YZ= g  d4 e4 d2  Z> d3   Z? RS(5   u   
    Abstract base class for units.

    Most of the arithmetic operations on units are defined in this
    base class.

    Should not be instantiated by users directly.
    i  c         C` s   |  S(   N(    (   RA   t   memo(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __deepcopy__  s    c         C` s   t  j j |   S(   u   
        Generate latex representation of unit name.  This is used by
        the IPython notebook to print a unit with a nice layout.

        Returns
        -------
        Latex string
        (   t   unit_formatt   Latext	   to_string(   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   _repr_latex_  s    	c         C` s   t  j j |   j d  S(   u%   Return string representation for unitu   unicode_escape(   Rf   t   GenericRh   t   encode(   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt	   __bytes__  s    c         C` s   t  j j |   S(   u%   Return string representation for unit(   Rf   Rj   Rh   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __unicode__  s    c         C` s:   t  j j |   } t j r- | j d  } n  d j |  S(   Nu   unicode_escapeu   Unit("{0}")(   Rf   Rj   Rh   R   t   PY2Rk   R   (   RA   t   string(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __repr__  s    	c         C` sG   |  j    } t g  | j D] } | j ^ q | j  } t |  } | S(   u   
        Returns an identifier that uniquely identifies the physical
        type of this unit.  It is comprised of the bases and powers of
        this unit, without the scale.  Since it is hashable, it is
        useful as a dictionary key.
        (   t	   decomposeR   t   basest   namet   powerst   tuple(   RA   R   R    t   r(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRJ     s    +c         C` s   t  d   d S(   uE   
        Returns all of the names associated with this unit.
        uD   Can not get names from unnamed units. Perhaps you meant to_string()?N(   t   AttributeError(   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   names-  s    c         C` s   t  d   d S(   uO   
        Returns the canonical (short) name associated with this unit.
        uD   Can not get names from unnamed units. Perhaps you meant to_string()?N(   Rw   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRs   6  s    c         C` s   t  d   d S(   u?   
        Returns the alias (long) names for this unit.
        uF   Can not get aliases from unnamed units. Perhaps you meant to_string()?N(   Rw   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   aliases?  s    c         C` s   d S(   u/   
        Return the scale of the unit.
        g      ?(    (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   scaleH  s    c         C` s   |  g S(   u/   
        Return the bases of the unit.
        (    (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRr   O  s    c         C` s   d g S(   u0   
        Return the powers of the unit.
        i   (    (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRt   V  s    c         C` s   t  j |  } | j |   S(   u  
        Output the unit in the given format as a string.

        Parameters
        ----------
        format : `astropy.units.format.Base` instance or str
            The name of a format or a formatter object.  If not
            provided, defaults to the generic format.
        (   Rf   t
   get_formatRh   (   RA   R   t   f(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRh   ]  s    c         C` s?   y |  j  d |  SWn$ t k
 r: t t j |   |  SXd S(   u&   Try to format units using a formatter.R   N(   Rh   R%   R   R   t	   text_type(   RA   t   format_spec(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt
   __format__k  s    c         C` s/   t  |   } |  d k	 r+ | t   j 7} n  | S(   u<  
        Normalizes equivalencies, ensuring each is a 4-tuple of the form::

        (from_unit, to_unit, forward_func, backward_func)

        Parameters
        ----------
        equivalencies : list of equivalency pairs, or `None`

        Returns
        -------
        A normalized list, including possible global defaults set by, e.g.,
        `set_enabled_equivalencies`, except when `equivalencies`=`None`,
        in which case the returned list is always empty.

        Raises
        ------
        ValueError if an equivalency cannot be interpreted
        N(   R1   R"   R]   R)   (   R)   R*   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR1   r  s    c         C` s   t  d |  g | g  S(   Ni   (   t   CompositeUnit(   RA   t   p(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __pow__  s    c         C` s   t  | t t j f  r' t |  } n  t  | t  rh | j   rF |  St d |  | g d d g d t Sy% d d l	 m
 } | d |   | SWn t k
 r t SXd  S(   Ni   it   _error_check(   t   Quantity(   R   t   bytesR   R}   R&   R   t   is_unityR   t   Falset   quantityR   t	   TypeErrort   NotImplemented(   RA   t   mR   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __div__  s    "c         C` s   t  | t t j f  r& t |  |  SyN d d l m } t | d  rb | |  } | |  } | S| | |  d  SWn t k
 r t	 SXd  S(   Ni   (   R   u   uniti(
   R   R   R   R}   R&   R   R   t   hasattrR   R   (   RA   R   R   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __rdiv__  s    
c         C` s   t  | t t j f  r' t |  } n  t  | t  rx | j   rF |  S|  j   rV | St d |  | g d d g d t Sy% d d l	 m
 } | d |   | SWn t k
 r t SXd  S(   Ni   R   (   R   (   R   R   R   R}   R&   R   R   R   R   R   R   R   R   (   RA   R   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __mul__  s    "c         C` s   t  | t t j f  r& t |  |  SyJ d d l m } t | d  rb | |  } | |  9} | S| | |   SWn t k
 r t	 SXd  S(   Ni   (   R   u   unit(
   R   R   R   R}   R&   R   R   R   R   R   (   RA   R   R   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __rmul__  s    
c         C` s%   t  t |  j  |  j t d  f  S(   Nu   1(   RM   t   strRz   Rs   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __hash__  s    c         C` s   |  | k r t  Sy t | d d } Wn t t t f k
 rC t SXt | t  sW t Sy t |  j	 |   SWn t k
 r t
 SXd  S(   Nt   parse_strictu   silent(   t   TrueR&   R%   R_   R   R   R   R   R   t   _toR   (   RA   t   other(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __eq__  s    c         C` s   |  | k S(   N(    (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __ne__  s    c         C` s+   |  j  t |   } | d k p* t |  S(   Ng      ?(   R   R&   R   (   RA   R   Rz   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __le__  s    c         C` s+   |  j  t |   } | d k p* t |  S(   Ng      ?(   R   R&   R   (   RA   R   Rz   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __ge__  s    c         C` s   |  | k S(   N(    (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __lt__  s    c         C` s   |  | k S(   N(    (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __gt__   s    c         C` s   |  d S(   Ng      (    (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __neg__  s    c         ` s]    j       t | t  r; t    f d   | D  St | d d }  j |    S(   u  
        Returns `True` if this unit is equivalent to ``other``.

        Parameters
        ----------
        other : unit object or string or tuple
            The unit to convert to. If a tuple of units is specified, this
            method returns true if the unit matches any of those in the tuple.

        equivalencies : list of equivalence pairs, optional
            A list of equivalence pairs to try if the units are not
            directly convertible.  See :ref:`unit_equivalencies`.
            This list is in addition to possible global defaults set by, e.g.,
            `set_enabled_equivalencies`.
            Use `None` to turn off all equivalencies.

        Returns
        -------
        bool
        c         3` s$   |  ] }  j  | d    Vq d S(   R)   N(   t   is_equivalent(   R4   t   u(   R)   RA   (    s1   lib/python2.7/site-packages/astropy/units/core.pys	   <genexpr>  s   R   u   silent(   R1   R   Ru   t   anyR&   t   _is_equivalent(   RA   R   R)   (    (   R)   RA   s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    c         C` s   t  | t  r t S|  j   | j   k r/ t St |  r |  j   } | j   } x | D] \ } } } } | d k r y | | j | g  t SWq t k
 r q XqZ | j	 |  r | j	 |  s | j	 |  rZ | j	 |  rZ t SqZ Wn  t S(   u  Returns `True` if this unit is equivalent to `other`.
        See `is_equivalent`, except that a proper Unit object should be
        given (i.e., no string) and that the equivalency list should be
        normalized using `_normalize_equivalencies`.
        N(
   R   t   UnrecognizedUnitR   RJ   R   R$   Rq   R"   t	   ExceptionR   (   RA   R   R)   R   R/   R0   t   forwardt   backward(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR   %  s&    	c         C` sK  d   } x| D] \ } } } } | d k r~ y9 | j   | j   j | g  }	 | |	 j | d  SWq
t k
 rz q
Xq y2 | j |  }
 | j |  } | |
 | |  SWn t k
 r n Xy2 | j |  }
 | j |  } | |
 | |  SWq t k
 r	q Xq Wd   } | |  } | |  } t d j | |    d S(   ud   
        Internal function (used from `_get_converter`) to apply
        equivalence pairs.
        c         ` s       f d   } | S(   Nc         ` s     t  |      S(   N(   t   _condition_arg(   R6   (   t   funct   scale1t   scale2(    s1   lib/python2.7/site-packages/astropy/units/core.pyt   convertJ  s    (    (   R   R   R   R   (    (   R   R   R   s1   lib/python2.7/site-packages/astropy/units/core.pyt   make_converterI  s    g      ?c         S` sL   |  j  d  } |  j } | d k r9 d j | |  } n d j |  } | S(   Nu   unscaledu   unknownu   '{0}' ({1})u   '{0}'(   Rh   t   physical_typeR   (   R   t   unit_strR   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   get_err_strd  s    	u   {0} and {1} are not convertibleN(   R"   Rq   Rz   R_   R   Ra   R   (   RA   R   R   R)   R   R-   R.   R/   R0   t   ratio_in_funitR   R   R   R   t	   other_str(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   _apply_equivalenciesD  s6    			
c         ` s   t  |  } y  j |   Wn t k
 r2 n X f d   Sy   j  |  j    SWn t k
 r } t | d  r x] | j D]O \ }  }   | | k r y      f d   SWq t k
 r q Xq q Wn  |  n Xd  S(   Nc         ` s     t  |   S(   N(   R   (   t   val(   Rz   (    s1   lib/python2.7/site-packages/astropy/units/core.pyR!   ~  s    u   equivalenciesc         ` s      j   d  |    S(   NR)   (   t   _get_converter(   R6   (   R0   R)   RA   R.   (    s1   lib/python2.7/site-packages/astropy/units/core.pyR!     s   	(   R&   R   R_   R   R1   R   R)   R   (   RA   R   R)   t   excR-   R/   (    (   R0   R)   Rz   RA   R.   s1   lib/python2.7/site-packages/astropy/units/core.pyR   u  s$    c         C` s   |  | k r d St  | t  r |  j   } | j   } | j | j k r t d   t | j | j  D  r | j | j Sn  t d j	 |  |    d S(   u   
        Returns the scale to the specified unit.

        See `to`, except that a Unit object should be given (i.e., no
        string), and that all defaults are used, i.e., no
        equivalencies and value=1.
        g      ?c         s` s!   |  ] \ } } | | k Vq d  S(   N(    (   R4   t	   self_baset
   other_base(    (    s1   lib/python2.7/site-packages/astropy/units/core.pys	   <genexpr>  s    u*   '{0!r}' is not a scaled version of '{1!r}'N(
   R   R   Rq   Rt   t   allR   Rr   Rz   Ra   R   (   RA   R   t   self_decomposedt   other_decomposed(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    	g      ?c         C` s   |  j  | d | |  S(   u  
        Return the converted values in the specified unit.

        Parameters
        ----------
        other : unit object or string
            The unit to convert to.

        value : scalar int or float, or sequence convertible to array, optional
            Value(s) in the current unit to be converted to the
            specified unit.  If not provided, defaults to 1.0

        equivalencies : list of equivalence pairs, optional
            A list of equivalence pairs to try if the units are not
            directly convertible.  See :ref:`unit_equivalencies`.
            This list is in addition to possible global defaults set by, e.g.,
            `set_enabled_equivalencies`.
            Use `None` to turn off all equivalencies.

        Returns
        -------
        values : scalar or array
            Converted value(s). Input value sequences are returned as
            numpy arrays.

        Raises
        ------
        UnitsError
            If units are inconsistent
        R)   (   R   (   RA   R   RZ   R)   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   to  s    c         C` s   |  j  | d | d | S(   uI   
        Alias for `to` for backward compatibility with pynbody.
        RZ   R)   (   R   (   RA   R   RZ   R)   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   in_units  s    c         C` s   t     d S(   uE  
        Return a unit object composed of only irreducible units.

        Parameters
        ----------
        bases : sequence of UnitBase, optional
            The bases to decompose into.  When not provided,
            decomposes down to any irreducible units.  When provided,
            the decomposed result will only contain the given units.
            This will raises a `UnitsError` if it's not possible
            to do so.

        Returns
        -------
        unit : CompositeUnit object
            New object containing only irreducible unit objects.
        N(   t   NotImplementedError(   RA   Rr   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRq     s    i   i    c          ` s    f d   } |  j    } t |  } | j |  }	 |	 d  k	 r^ t |	 t  rZ |	  n  |	 S| | k r~ | g | | <| g S| g }
 x | D] \ } } } } | d  k	 rM|  j |  r | j    j | j } |
 j t	 | d |  |  j     qu|  j |  ru| j    j | j } |
 j t	 | d |  |  j     quq |  j |  r |
 j t	 | j   q q Wg  } t
 | j  d k rt | g  t   g } n t   t   g } x   D] } | j    } x |
 D] } t
 | j  d k rLxM t | j | j  D]3 \ } } | j |  r| | } | | } PqqWn  | | j    } | | } t
 | j  } | |  r| d k r| | j |  q| j | | | f  qWqWx? | D]7 } t
 |  r| d j | d  } | | | <| SqW| j d t j d   g  } x | D] \ } } } y2 | j d | d   d | d	 | d d
 |  } Wn t k
 rg  } n Xx- | D]% } | j t
 | j  | | f  qWq'Wt
 |  r_| j d t j d   | d d } t   } xM | D]E \ } } } | | k rPq| | } | |  r| j |  qqWt
 |  r_| | | <| Sn  | |   st d j |    } | | | <|  n  |  g | | <|  g S(   Nc         ` s(   x! |  j  D] } |   k r
 t Sq
 Wt S(   N(   Rr   R   R   (   R   t   base(   t	   namespace(    s1   lib/python2.7/site-packages/astropy/units/core.pyt   is_final_result  s    g      ?i    i   t   keyR)   R   t	   max_deptht   deptht   cached_resultsu5   Cannot represent unit {0} in terms of the given units(   Rq   RM   RN   R"   R   R   R   Rz   R(   R&   R$   Rr   R   R   Rt   R   t   uniont   sortt   operatort
   itemgettert   _composeR_   R   (    RA   R)   R   R   R   R   R   R   R   t   cachedR   R-   R.   R/   R0   Rz   t   partial_resultst   final_resultst   tunit_decomposedR   R   t   powert   composedt   factoredt	   len_basest   final_resultt   resultst   composed_listt   subcomposedt
   min_lengtht
   subresultsR   (    (   R   s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    		*-"



	
!	


	c         ` s6  |  j     d      f d        f d   } |  j     | d k r | |  j d    } t |  d k r t   j } q nl t | t  r t	 | t
 j |    } n? t j |  r | t
 j t |    } n | t |   } d   } | |  j d  d | d | d	 d d
 i    S(   ug  
        Return the simplest possible composite unit(s) that represent
        the given unit.  Since there may be multiple equally simple
        compositions of the unit, a list of units is always returned.

        Parameters
        ----------
        equivalencies : list of equivalence pairs, optional
            A list of equivalence pairs to also list.  See
            :ref:`unit_equivalencies`.
            This list is in addition to possible global defaults set by, e.g.,
            `set_enabled_equivalencies`.
            Use `None` to turn off all equivalencies.

        units : set of units to compose to, optional
            If not provided, any known units may be used to compose
            into.  Otherwise, ``units`` is a dict, module or sequence
            containing the units to compose into.

        max_depth : int, optional
            The maximum recursion depth to use when composing into
            composite units.

        include_prefix_units : bool, optional
            When `True`, include prefixed units in the result.
            Default is `False`.

        Returns
        -------
        units : list of `CompositeUnit`
            A list of candidate compositions.  These will all be
            equally simple, but it may not be possible to
            automatically determine which of the candidates are
            better.
        c         S` sj   t  |  j  d k r. t  | j  d k r. t Sx5 |  j D]* } x! | j D] } | | k rH t SqH Wq8 Wt S(   Ni    (   R$   Rr   R   R   (   R/   R0   t   abt   bb(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   has_bases_in_common  s    *c         ` s    |  |  r t  Sx   D] \ } } } } | d  k	 r |  j |  rc  | j   |  r t  Sq |  j |  r  | j   |  r t  Sq q |  j |  r  t |  r t  Sq q Wt S(   N(   R   R"   R   Rq   t   dimensionless_unscaledR   (   R   R   R-   R.   R/   R0   (   R)   R   (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   has_bases_in_common_with_equiv  s    
c         ` sh   t    } xX |  D]P } t | t  r  s; t | t  r    | j    r | j |  q q W| S(   N(   R   R   R   RI   Rq   R   (   R   t   filtered_namespaceR.   (   t
   decomposedR   t   include_prefix_units(    s1   lib/python2.7/site-packages/astropy/units/core.pyt   filter_units  s    	R)   i    c         S` s   t  |   s g  St |   }  |  j d d    |  j d d    |  j d d    |  j d d    |  d } | g } x@ |  d D]4 } t |  t |  k r | j |  n  | } q W| S(   NR   c         S` s   t  j |  j  S(   N(   t   npt   absRz   (   R    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR!     s    c         S` s   t  j t  j |  j   S(   N(   R   t   sumR   Rt   (   R    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR!     s    c         S` s   t  j |  j  d k  S(   Ng        (   R   R   Rt   (   R    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR!     s    c         S` s   t  |  j  S(   N(   R   Rz   (   R    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR!     s    i    i   (   R$   R   R   R   R(   (   R   t   last_resultt   filteredR   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   sort_results  s    
	
R   R   R   R   N(   R1   Rq   R"   t"   _get_units_with_same_physical_typeR$   R]   RF   R   R   R   R   t
   itervaluesR   R   R   R   R   (   RA   R)   R   R   R   R   R   (    (   R   R)   R   R   R   s1   lib/python2.7/site-packages/astropy/units/core.pyt   composek  s&    &			c         ` s^   t  | j      f d   } |  j d    } | j d |  } t | d | d t } | S(   u  
        Converts this unit into ones belonging to the given system.
        Since more than one result may be possible, a list is always
        returned.

        Parameters
        ----------
        system : module
            The module that defines the unit system.  Commonly used
            ones include `astropy.units.si` and `astropy.units.cgs`.

            To use your own module it must contain unit objects and a
            sequence member named ``bases`` containing the base units of
            the system.

        Returns
        -------
        units : list of `CompositeUnit`
            The list is ranked so that units containing only the base
            units of that system will appear first.
        c         ` sj   |  j  } t |  d k r" t j Sd } x' | D] } |   k r/ | d 7} q/ q/ W| t t |   Sd  S(   Ni    i   (   Rr   R$   R   t   inft   float(   R   t   compose_basesR   R   (   Rr   (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   score  s    	Rr   R   R   t   reverse(   R   Rr   Rq   R   t   sortedR   (   RA   t   systemR   R    R   (    (   Rr   s1   lib/python2.7/site-packages/astropy/units/core.pyt	   to_system  s    c         C` s!   d d l  m } |  j |  d S(   uL   
        Returns a copy of the current `Unit` instance in SI units.
        i   (   t   sii    (   t    R   R   (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    c         C` s!   d d l  m } |  j |  d S(   uO   
        Returns a copy of the current `Unit` instance with CGS units.
        i   (   t   cgsi    (   R   R   R   (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    c         C` s   d d l  m } | j |   S(   u   
        Return the physical type on the unit.

        Examples
        --------
        >>> from astropy import units as u
        >>> print(u.m.physical_type)
        length

        i   (   t   physical(   R   R   t   get_physical_type(   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR   %  s    c         C` s   t    } t | j |    } x | D] \ } } } } | d k	 r |  j |  rw | | k rw | j | j |   n  |  j |  r | | k r | j | j |   q q% |  j |  r% | j t  q% q% W| S(   u  
        Return a list of registered units with the same physical type
        as this unit.

        This function is used by Quantity to add its built-in
        conversions to equivalent units.

        This is a private method, since end users should be encouraged
        to use the more powerful `compose` and `find_equivalent_units`
        methods (which use this under the hood).

        Parameters
        ----------
        equivalencies : list of equivalence pairs, optional
            A list of equivalence pairs to also pull options from.
            See :ref:`unit_equivalencies`.  It must already be
            normalized using `_normalize_equivalencies`.
        N(	   R]   R   RO   R"   R   t   updateR   R   R   (   RA   R)   t   unit_registryR   R-   R.   R/   R0   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR   4  s    	t   EquivalentUnitsListc           B` s   e  Z d  Z d   Z RS(   ub   
        A class to handle pretty-printing the result of
        `find_equivalent_units`.
        c   
      C` sq  t  |   d k r d Sg  } x] |  D]U } | j   j   } | | j k rS d } n  | j | j | d j | j  f  q# W| j   | j d d  d d d g } xH | D]@ } x7 t	 |  D]) \ } } t
 | | t  |   | | <q Wq Wd j |   } g  | D] } | j |   ^ q} | d d	 !d
 g g  | d	 D] }	 d j |	  ^ q=d g } d j |  Sd  S(   Ni    u   []u   irreducibleu   , u   Primary nameu   Unit definitionu   Aliasesu)     {{0:<{0}s}} | {{1:<{1}s}} | {{2:<{2}s}}i   u   [u   {0} ,u   ]u   
(   u   Primary nameu   Unit definitionu   Aliases(   R$   Rq   Rh   Rs   R(   t   joinRy   R   t   insertR#   t   maxR   (
   RA   t   linesR   t   irredt   widthst   lineR+   t   colR|   R    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRp   \  s&    	)
%"5
(   RQ   RR   RS   Rp   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR   V  s   c      	   C` sG   |  j  d | d | d d d |  } t d   | D  } |  j |  S(   u?  
        Return a list of all the units that are the same type as ``self``.

        Parameters
        ----------
        equivalencies : list of equivalence pairs, optional
            A list of equivalence pairs to also list.  See
            :ref:`unit_equivalencies`.
            Any list given, including an empty one, supercedes global defaults
            that may be in effect (as set by `set_enabled_equivalencies`)

        units : set of units to search in, optional
            If not provided, all defined units will be searched for
            equivalencies.  Otherwise, may be a dict, module or
            sequence containing the units to search for equivalencies.

        include_prefix_units : bool, optional
            When `True`, include prefixed units in the result.
            Default is `False`.

        Returns
        -------
        units : list of `UnitBase`
            A list of unit objects that match ``u``.  A subclass of
            `list` (``EquivalentUnitsList``) is returned that
            pretty-prints the list of units when output.
        R)   R   R   i   R   c         s` s1   |  ]' } t  | j  d  k r | j d Vq d S(   i   i    N(   R$   Rr   (   R4   R    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pys	   <genexpr>  s    (   R   R   R   (   RA   R)   R   R   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   find_equivalent_unitsv  s    		c         C` s   t  S(   uK   
        Returns `True` if the unit is unscaled and dimensionless.
        (   R   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    N(@   RQ   RR   RS   t   __array_priority__Re   Ri   Rl   R   Rn   t   __str__Rm   Rp   RJ   RT   Rx   Rs   Ry   Rz   Rr   Rt   Rf   Rj   Rh   R   t   staticmethodR1   R   R   R   t   __truediv__t   __rtruediv__R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   Rq   R"   R   R   R   R   R   R   R   R   R   R   R   R  R   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     sr   																													1	!!z	{	-	" #t	   NamedUnitc           B` s   e  Z d  Z d
 d
 d
 d  Z d   Z d   Z e d    Z e d    Z	 e d    Z
 e d    Z e d    Z d
 d	  Z RS(   uh  
    The base class of units that have a name.

    Parameters
    ----------
    st : str, list of str, 2-tuple
        The name of the unit.  If a list of strings, the first element
        is the canonical (short) name, and the rest of the elements
        are aliases.  If a tuple of lists, the first element is a list
        of short names, and the second element is a list of long
        names; all but the first short name are considered "aliases".
        Each name *should* be a valid Python identifier to make it
        easy to access, but this is not required.

    namespace : dict, optional
        When provided, inject the unit, and all of its aliases, in the
        given namespace dictionary.  If a unit by the same name is
        already in the namespace, a ValueError is raised.

    doc : str, optional
        A docstring describing the unit.

    format : dict, optional
        A mapping to format-specific representations of this unit.
        For example, for the ``Ohm`` unit, it might be nice to have it
        displayed as ``\Omega`` by the ``latex`` formatter.  In that
        case, `format` argument should be set to::

            {'latex': r'\Omega'}

    Raises
    ------
    ValueError
        If any of the given unit names are already in the registry.

    ValueError
        If any of the given unit names are not valid Python tokens.
    c         C` s  t  j |   t | t t j f  rI | g |  _ | g |  _ g  |  _ n t | t	  r t
 |  d k sy t d   n  | d g  | d D] } | | d k r | ^ q |  _ t
 |  j  s t d   n  | d |  _ | d |  _ nH t
 |  d k rt d   n  | |  _ | d g |  _ | d |  _ | d  k rKi  } n  | |  _ | d  k ro|  j   } n t j |  } t j |  } | |  _ |  j |  d  S(   Ni   u"   st must be string, list or 2-tuplei    i   u   must provide at least one nameu$   st list must have at least one entry(   R   RC   R   R   R   R}   RH   t   _short_namest   _long_namesRu   R$   R%   R"   t   _formatt   _generate_doct   textwrapt   dedentt   fillRS   t   _inject(   RA   RL   t   docR   R   t   n(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRC     s8    8
			c         C` s;   |  j  } t |  j   d k r/ d j | d    S| d Sd S(   u   
        Generate a docstring for the unit if the user didn't supply
        one.  This is only used from the constructor and may be
        overridden in subclasses.
        i   u	   {1} ({0})i   i    N(   Rx   R$   R   (   RA   Rx   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR    s    	c         C` s   |  j  j | |  j  S(   u}  
        Get a name for this unit that is specific to a particular
        format.

        Uses the dictionary passed into the `format` kwarg in the
        constructor.

        Parameters
        ----------
        format : str
            The name of the format

        Returns
        -------
        name : str
            The name of the unit for the given format.
        (   R
  RN   Rs   (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   get_format_name  s    c         C` s   |  j  S(   uE   
        Returns all of the names associated with this unit.
        (   RH   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRx     s    c         C` s   |  j  d S(   uO   
        Returns the canonical (short) name associated with this unit.
        i    (   RH   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRs     s    c         C` s   |  j  d S(   u?   
        Returns the alias (long) names for this unit.
        i   (   RH   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRy     s    c         C` s   |  j  S(   uK   
        Returns all of the short names associated with this unit.
        (   R  (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   short_names$  s    c         C` s   |  j  S(   uJ   
        Returns all of the long names associated with this unit.
        (   R	  (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt
   long_names+  s    c         C` s   | d k r d SxL |  j D]A } | | k r |  | | k r t d j | | |    q q Wx |  j D] } |  | | <qi Wd S(   uf   
        Injects the unit, and all of its aliases, in the given
        namespace dictionary.
        NuA   Object with name {0!r} already exists in given namespace ({1!r}).(   R"   RH   R%   R   (   RA   R   Rs   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR  2  s    N(   RQ   RR   RS   R"   RC   R  R  RT   Rx   Rs   Ry   R  R  R  (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR    s   &&		c         C` sX   t    j } | d | k r( | | d S|  |  } | rP t    j | g  n  | Sd S(   uV   
    This is used to reconstruct units when passed around by
    multiprocessing.
    i    N(   R]   RD   R?   (   t   clsRx   t
   registeredRD   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   _recreate_irreducible_unitG  s    t   IrreducibleUnitc           B` s5   e  Z d  Z d   Z e d    Z e   d  Z RS(   u   
    Irreducible units are the units that all other units are defined
    in terms of.

    Examples are meters, seconds, kilograms, amperes, etc.  There is
    only once instance of such a unit per type.
    c         C` s:   t    j } t |  j t |  j  |  j | k f |  j f S(   N(   R]   RD   R  t	   __class__R   Rx   Rs   t   __dict__(   RA   RD   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt
   __reduce__d  s    !c         C` s   |  S(   uk   The unit that this named unit represents.

        For an irreducible unit, that is always itself.
        (    (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt
   representsp  s    c         C` s   t  |  r |  | k r xa | D]Y } y |  j |  } Wn t k
 rK q Xt |  r\ | St | | g d g d t Sq Wt d j |     n  |  S(   Ni   R   u7   Unit {0} can not be decomposed into the requested bases(   R$   R   R_   R   R   R   Ra   R   (   RA   Rr   R   Rz   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRq   x  s    (   RQ   RR   RS   R  RT   R  R   Rq   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR  [  s   	R   c           B` s   e  Z d  Z e j Z d   Z d   Z e j r9 e Z	 n  d   Z
 e j sT e
 Z	 n  d d  Z d   Z e Z Z Z Z Z Z Z Z Z Z Z Z d   Z d   Z d d  Z d d	  Z d
   Z d   Z RS(   u   
    A unit that did not parse correctly.  This allows for
    roundtripping it as a string, but no unit operations actually work
    on it.

    Parameters
    ----------
    st : str
        The name of the unit.
    c         C` s   d j  t |    S(   Nu   UnrecognizedUnit({0})(   R   R   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRp     s    c         C` s   |  j  j d d  S(   Nu   asciiu   replace(   Rs   Rk   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRl     s    c         C` s   |  j  S(   N(   Rs   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRm     s    c         C` s   |  j  S(   N(   Rs   (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRh     s    c         O` s   t  d j |  j    d  S(   NuQ   The unit {0!r} is unrecognized, so all arithmetic operations with it are invalid.(   R%   R   Rs   (   RA   t   argst   kwargs(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   _unrecognized_operator  s    c         C` sY   y t  | d d } Wn t t t f k
 r3 t SXt | t |    oX |  j | j k S(   NR   u   silent(   R&   R%   R_   R   R   R   RY   Rs   (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s
    c         C` s   |  | k S(   N(    (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    c         C` s   |  j  |  |  | k S(   N(   R1   (   RA   R   R)   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    c         C` s)   |  j  |  t d j |  j    d  S(   NuH   The unit {0!r} is unrecognized.  It can not be converted to other units.(   R1   R%   R   Rs   (   RA   R   R)   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    c         C` s   |  j  S(   N(   Rs   (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR    s    c         C` s   t  S(   N(   R   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    N(    RQ   RR   RS   t   objectR  Rp   Rl   R   Rn   R  Rm   R"   Rh   R  R   R   R   R  R  R   R   R   R   R   R   R   R   R   R   R   R  R   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s$   
									2			t   _UnitMetaClassc           B` s&   e  Z d  Z d d d d d d  Z RS(   u   
    This metaclass exists because the Unit constructor should
    sometimes return instances that already exist.  This "overrides"
    the constructor before the new instance is actually created, so we
    can return an existing one.
    u   raisec      	   C` s  t  | d  r | Sd d l m } t | |  r t | j  rM | j } q t | j | j j d | j j	 d | j j
 } n  t | |  r t | j  r | j } q t | j | j j d | j j	 d | j j
 } n  t | t  rt t |   j | | d | d | d | St | t  r,| St | t t j f  r{t | j    d	 k r`t S| d  k rxt j } n  t j |  } t j rt | t  r| j d
  } n  y | j |  SWqt k
 rw}	 | d k rn | t j k	 r| j d }
 n d }
 d j | |
 t j |	   } | d k rBt |   n+ | d k rat  j! | t"  n t d   t# |  SXna t | t$ t% t& j' t& j( f  rt | g  g   S| d  k rt) d   n t) d j |    d  S(   Nu   _get_physical_type_idi   (   R   Rr   Rt   R   R   R  i    u   asciiu   silentu    u    u#   '{0}' did not parse as {1}unit: {2}u   raiseu   warnu2   'parse_strict' must be 'warn', 'raise' or 'silent'u   None is not a valid Unitu"   {0} can not be converted to a Unit(*   R   R   R   R   R   RZ   R   R   Rz   Rr   Rt   R   t   superR!  t   __call__R   R   R}   R$   t   stripR   R"   Rf   Rj   R{   Rn   t   decodet   parseR   Rs   R   R%   t   warningst   warnRc   R   t   intR   R   t   floatingt   integerR   (   RA   t   sR  R   R   R  R   R   R|   t   et   format_clauset   msg(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR#    sd    	!N(   RQ   RR   RS   R"   R#  (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR!    s   	R&   c           B` sb   e  Z d  Z d d d d d  Z e d    Z e   d  Z d   Z	 d   Z
 e d    Z RS(   u	  
    The main unit class.

    There are a number of different ways to construct a Unit, but
    always returns a `UnitBase` instance.  If the arguments refer to
    an already-existing unit, that existing unit instance is returned,
    rather than a new one.

    - From a string::

        Unit(s, format=None, parse_strict='silent')

      Construct from a string representing a (possibly compound) unit.

      The optional `format` keyword argument specifies the format the
      string is in, by default ``"generic"``.  For a description of
      the available formats, see `astropy.units.format`.

      The optional ``parse_strict`` keyword controls what happens when an
      unrecognized unit string is passed in.  It may be one of the following:

         - ``'raise'``: (default) raise a ValueError exception.

         - ``'warn'``: emit a Warning, and return an
           `UnrecognizedUnit` instance.

         - ``'silent'``: return an `UnrecognizedUnit` instance.

    - From a number::

        Unit(number)

      Creates a dimensionless unit.

    - From a `UnitBase` instance::

        Unit(unit)

      Returns the given unit unchanged.

    - From `None`::

        Unit()

      Returns the null unit.

    - The last form, which creates a new `Unit` is described in detail
      below.

    Parameters
    ----------
    st : str or list of str
        The name of the unit.  If a list, the first element is the
        canonical (short) name, and the rest of the elements are
        aliases.

    represents : UnitBase instance
        The unit that this named unit represents.

    doc : str, optional
        A docstring describing the unit.

    format : dict, optional
        A mapping to format-specific representations of this unit.
        For example, for the ``Ohm`` unit, it might be nice to have it
        displayed as ``\Omega`` by the ``latex`` formatter.  In that
        case, `format` argument should be set to::

            {'latex': r'\Omega'}

    namespace : dictionary, optional
        When provided, inject the unit (and all of its aliases) into
        the given namespace.

    Raises
    ------
    ValueError
        If any of the given unit names are already in the registry.

    ValueError
        If any of the given unit names are not valid Python tokens.
    c      	   C` s;   t  |  } | |  _ t j |  | d | d | d | d  S(   NR   R  R   (   R&   t   _representsR  RC   (   RA   RL   R  R  R   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRC     s    	c         C` s   |  j  S(   u)   The unit that this named unit represents.(   R0  (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR    s    c         C` s   |  j  j d |  S(   NRr   (   R0  Rq   (   RA   Rr   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRq     s    c         C` s   |  j  j   S(   N(   R0  R   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    c         C` s   t  |  j  t  |  j  S(   N(   RM   Rs   R0  (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    c         C` s   g  | D] \ } } |  |  ^ q } g  | D] \ } } | ^ q, } t  |  d k rs | d d k rs | d } n t d | |  } | S(   Ni   i    (   R$   R   (   R  t   physical_type_idR   t   _Rr   R   Rt   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   _from_physical_type_id  s    %"N(   RQ   RR   RS   R"   RC   RT   R  R   Rq   R   R   t   classmethodR3  (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR&   .  s   S		RI   c           B` s   e  Z d  Z RS(   u   
    A unit that is simply a SI-prefixed version of another unit.

    For example, ``mm`` is a `PrefixUnit` of ``.001 * m``.

    The constructor is the same as for `Unit`.
    (   RQ   RR   RS   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRI     s   R   c           B` s   e  Z d  Z e e   e d  Z d   Z d   Z e	 d    Z
 e	 d    Z e	 d    Z e e   d  Z d   Z e   d	  Z d
   Z RS(   u  
    Create a composite unit using expressions of previously defined
    units.

    Direct use of this class is not recommended. Instead use the
    factory function `Unit` and arithmetic operators to compose
    units.

    Parameters
    ----------
    scale : number
        A scaling factor for the unit.

    bases : sequence of `UnitBase`
        A sequence of units this unit is composed of.

    powers : sequence of numbers
        A sequence of powers (in parallel with ``bases``) for each
        of the base units.
    c   	      C` s   | rc t  |  } x, | D]$ } t | t  s t d   q q Wg  | D] } t |  ^ qH } n  | |  _ | |  _ | |  _ d  |  _	 |  j
 d | d |  d  |  _ d  S(   Nu,   bases must be sequence of UnitBase instancesRq   Rr   (   R   R   R   R   R   t   _scalet   _basest   _powersR"   t   _decomposed_cachet   _expand_and_gathert   _hash(	   RA   Rz   Rr   Rt   Rq   t   decompose_basesR   R   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRC     s    "				c         C` sI   t  |  j  r" t t |   j   S|  j d k rA d j |  j  Sd Sd  S(   Ng      ?u'   Unit(dimensionless with a scale of {0})u   Unit(dimensionless)(   R$   R6  R"  R   Rp   R5  R   (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRp     s    
c         C` s}   |  j  d  k rv t |  j  g g  |  j D] } | j ^ q( g  |  j D] } t |  ^ qE } t t |   |  _  n  |  j  S(   N(	   R:  R"   R   R5  R6  Rs   R7  RM   Ru   (   RA   R    t   parts(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s
    ,#c         C` s   |  j  S(   u9   
        Return the scale of the composite unit.
        (   R5  (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRz     s    c         C` s   |  j  S(   u9   
        Return the bases of the composite unit.
        (   R6  (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRr     s    c         C` s   |  j  S(   u:   
        Return the powers of the composite unit.
        (   R7  (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRt     s    c         ` s     f d   } i   |  j  } xt |  j |  j  D] \ } } | rj |   k rj | j d    } n  t | t  ry | | j | 9} Wn4 t k
 r | t	 j
 | t	 j | j   9} n Xxc t | j | j  D]7 \ } } t | |  \ }	 } | | |	 | |  } q Wq7 | | | |  } q7 Wg  t j   D] }
 |
 d d k r?|
 ^ q?  j d d    g   D] }
 |
 d ^ q{|  _ g   D] }
 t |
 d  ^ q|  _ t |  |  _ d  S(   Nc         ` s   |    k r x   D]| } y | |  j  |  | 9} WnQ t k
 rG q t k
 r | t j | t j |  j  |    9} | }  Pq X| }  Pq Wn  |   k r t  |  |  \ } } | |  |  <n
 |  |  <| S(   N(   R   R_   R%   t   cmatht   expt   logR   (   R   R   Rz   R   R/   R0   (   Rr   t	   new_parts(    s1   lib/python2.7/site-packages/astropy/units/core.pyt   add_unit  s"    )
Rr   i   i    R   c         S` s   |  d t  |  d d d  f S(   Ni   i    u   nameu    (   t   getattr(   R    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR!   6  s    (   Rz   R   Rr   Rt   Rq   R   R   R5  R%   R=  R>  R?  R6  R7  R   R   R;   R   R   R   (   RA   Rq   Rr   RA  Rz   R0   R   t   b_subt   p_subR/   R    (    (   Rr   R@  s1   lib/python2.7/site-packages/astropy/units/core.pyR9    s(    	"'"2 &c         C` s   t  |  j |  j |  j  S(   u<   
        For compatibility with python copy module.
        (   R   R5  R6  R7  (   RA   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   __copy__<  s    c         C` s   t  |  d k r( |  j d  k	 r( |  j Sx_ |  j D]2 } t | t  s` t  |  r2 | | k r2 Pq2 q2 Wt  |  d k r |  |  _ n  |  St |  j |  j |  j d t	 d | } t  |  d k r | |  _ n  | S(   Ni    Rq   R;  (
   R$   R8  R"   Rr   R   R  R   Rz   Rt   R   (   RA   Rr   R   R    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyRq   B  s    !	c         C` s.   |  j    } t | j  d k o- | j d k S(   Ni    g      ?(   Rq   R$   Rr   Rz   (   RA   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR   U  s    (   RQ   RR   RS   R   R   R   RC   Rp   R   RT   Rz   Rr   Rt   R9  RE  Rq   R   (    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s   	
	6	u   Yu   yottagyCxDu   Zu   zettagPKDu   Eu   exag NgmCu   Pu   petag  4&kCu   Tu   terag   mBu   Gu   gigag    eAu   Mu   megag    .Au   ku   kilog     @@u   hu   hectog      Y@u   dau   dekau   decag      $@u   du   decig?u   cu   centig{Gz?u   mu   milligMbP?u   uu   microgư>u   nu   nanog&.>u   pu   picog-q=u   fu   femtogV瞯<u   au   attogC]r2<u   zu   zeptogO
;u   yu   yoctogW:u   Kiu   kibig       @i
   u   Miu   mebii   u   Giu   gibii   u   Tiu   tebii(   u   Piu   pebii2   u   Eiu   exbii<   c      	   C` s  | t  k r t } n | t k r* g  } n  xg| D]_\ } } } g  } i  } x | D] }	 |	 | k rk qS n  x |  j D] }
 | j |	 |
  |	 d k r d |  j d  | d <d |  j d  | d <n  x4 t j |  j  D]  \ } } | j	 | |	 |  q Wqu WqS WxE | D]= }	 |	 | k r'qn  x" |  j
 D] }
 | j |	 |
  q1WqWt |  r1 t | t | |  g d g d t d | d	 | q1 q1 Wd
 S(   ud  
    Set up all of the standard metric prefixes for a unit.  This
    function should not be used directly, but instead use the
    `prefixes` kwarg on `def_unit`.

    Parameters
    ----------
    excludes : list of str, optional
        Any prefixes to exclude from creation to avoid namespace
        collisions.

    namespace : dict, optional
        When provided, inject the unit (and all of its aliases) into
        the given namespace dictionary.

    prefixes : list, optional
        When provided, it is a list of prefix definitions of the form:

            (short_names, long_tables, factor)
    u   uu   \mu u   latexu   μu   unicodei   R   R   R   N(   R   t   si_prefixesR   R  R(   R  R   R;   R
  RK   R  R$   RI   R   (   R   t   excludesR   t   prefixest   shortt   fullt   factorRx   R   t   prefixt   aliasR   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   _add_prefixes|  s4    		 	c      	   C` sw   | d k	 r0 t |  | d | d | d | } n t |  d | d | d | } | rs t | d | d | d | n  | S(   u  
    Factory function for defining new units.

    Parameters
    ----------
    s : str or list of str
        The name of the unit.  If a list, the first element is the
        canonical (short) name, and the rest of the elements are
        aliases.

    represents : UnitBase instance, optional
        The unit that this named unit represents.  If not provided,
        a new `IrreducibleUnit` is created.

    doc : str, optional
        A docstring describing the unit.

    format : dict, optional
        A mapping to format-specific representations of this unit.
        For example, for the ``Ohm`` unit, it might be nice to
        have it displayed as ``\Omega`` by the ``latex``
        formatter.  In that case, `format` argument should be set
        to::

            {'latex': r'\Omega'}

    prefixes : bool or list, optional
        When `True`, generate all of the SI prefixed versions of the
        unit as well.  For example, for a given unit ``m``, will
        generate ``mm``, ``cm``, ``km``, etc.  When a list, it is a list of
        prefix definitions of the form:

            (short_names, long_tables, factor)

        Default is `False`.  This function always returns the base
        unit object, even if multiple scaled versions of the unit were
        created.

    exclude_prefixes : list of str, optional
        If any of the SI prefixes need to be excluded, they may be
        listed here.  For example, ``Pa`` can be interpreted either as
        "petaannum" or "Pascal".  Therefore, when defining the
        prefixes for ``a``, ``exclude_prefixes`` should be set to
        ``["P"]``.

    namespace : dict, optional
        When provided, inject the unit (and all of its aliases and
        prefixes), into the given namespace dictionary.

    Returns
    -------
    unit : `UnitBase` object
        The newly-defined unit, or a matching unit that was already
        defined.
    R   R  R   RG  RH  N(   R"   R&   R  RN  (   R,  R  R  R   RH  t   exclude_prefixesR   R   (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   def_unit  s    :
c         C` s{   t  |  t t j t f  r |  St  |  t j  rG |  j j d k rG |  St j	 |   } | j j d k rw t
 d   n  | S(   ut  
    Validate value is acceptable for conversion purposes.

    Will convert into an array if not a scalar, and can be converted
    into an array

    Parameters
    ----------
    value : int or float value, or sequence of such values

    Returns
    -------
    Scalar value or numpy array

    Raises
    ------
    ValueError
        If value is not as expected
    u   iu   fu   cuM   Value not scalar compatible or convertible to an int, float, or complex array(   u   iu   fu   c(   u   iu   fu   c(   R   R   R   t   integer_typest   complexR   t   ndarrayt   dtypet   kindt   arrayR%   (   RZ   t   avalue(    (    s1   lib/python2.7/site-packages/astropy/units/core.pyR     s    $R   (J   RS   t
   __future__R    R   R   R   t   externR   t   extern.six.movesR   R   R   R  R'  t   numpyR   t   utils.decoratorsR   R   t   utils.exceptionsR   t
   utils.miscR	   R
   t   utilsR   R   R   R   R   R   Rf   Rn   R=  t   __all__R   R1   R   R2   RU   RV   R]   RG   R?   RP   R@   R   R_   R%   R`   Ra   R   Rb   Rc   t   add_metaclassR   R  R  R  R   R!  R&   RI   R   RF  t   binary_prefixesR"   R   RN  RP  R   R   t   onet   fits(    (    (    s1   lib/python2.7/site-packages/astropy/units/core.pyt   <module>   s   ""			*		4	7	$		   	2E\y
:F	!