σ
ίΘ[c           @` s  d  d l  m Z m Z m Z 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 m Z m Z d d l m Z d d l m Z d d l m Z d d	 l m Z d
 d g Z d e f d     YZ e j e  d e f d     Y Z d e f d     YZ d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   sixN(   t   Unitt
   UnitsError(   t   Quantity(   t   lazyproperty(   t   AstropyUserWarning(   t   InheritDocstringsu   Constantu
   EMConstantt   ConstantMetac           B` s   e  Z d  Z d   Z RS(   u-  Metaclass for the :class:`Constant`. The primary purpose of this is to
    wrap the double-underscore methods of :class:`Quantity` which is the
    superclass of :class:`Constant`.

    In particular this wraps the operator overloads such as `__add__` to
    prevent their use with constants such as ``e`` from being used in
    expressions without specifying a system.  The wrapper checks to see if the
    constant is listed (by name) in ``Constant._has_incompatible_units``, a set
    of those constants that are defined in different systems of units are
    physically incompatible.  It also performs this check on each `Constant` if
    it hasn't already been performed (the check is deferred until the
    `Constant` is actually used in an expression to speed up import times,
    among other reasons).
    c         C` sΣ   d   } t  d d d d d d d d	 d
 d d d d d g  } xr t j t t   D][ \ } } t | t j  rU | j d  rU | j	 d  rU | | k rU | |  | | <qU qU Wt
 t |   j |  | | |  S(   Nc         ` s"   t  j      f d    } | S(   Nc         ` sό   |  j  j   } |  j | } |  j s xR t j |  D]A } y |  j j | j  Wq5 t k
 ru |  j	 j
 |  q5 Xq5 Wt |  _ n  |  j rμ | |  j	 k rμ t g  | D] } | r© | ^ q©  } t d j |  j |  j | d    n    |  | |  S(   Nu§   Constant {0!r} does not have physically compatible units across all systems of units and cannot be combined with other values without specifying a system (eg. {1}.{2})i    (   t   namet   lowert	   _registryt   _checked_unitsR   t
   itervaluest   unitt   toR   t   _has_incompatible_unitst   addt   Truet   systemt   sortedt	   TypeErrort   formatt   abbrev(   t   selft   argst   kwargst
   name_lowert	   instancest   instt   xt   systems(   t   meth(    s9   lib/python2.7/site-packages/astropy/constants/constant.pyt   wrapper&   s"    	
%(   t	   functoolst   wraps(   R#   R$   (    (   R#   s9   lib/python2.7/site-packages/astropy/constants/constant.pyt   wrap%   s    u   __new__u   __array_finalize__u   __array_wrap__u   __dir__u   __getattr__u   __init__u   __str__u   __repr__u   __hash__u   __iter__u   __getitem__u   __len__u   __nonzero__u   __quantity_subclass__u   __(   t   setR   t	   iteritemst   varsR   t
   isinstancet   typest   FunctionTypet
   startswitht   endswitht   superR   t   __new__(   t   mclsR   t   basest   dR'   t   excludet   attrt   value(    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyR1   $   s    	"(   t   __name__t
   __module__t   __doc__R1   (    (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyR      s   t   Constantc           B` sδ   e  Z d  Z i  Z e   Z d d d  Z d   Z d   Z	 d   Z
 d   Z e Z Z e d    Z e d    Z e d    Z e d	    Z e d
    Z e d    Z d   Z e d    Z e d    Z d   Z RS(   u   A physical or astronomical constant.

    These objects are quantities that are meant to represent physical
    constants.
    c         C` s  | d  k rE t |  d d   } | d  k rE t d j |     qE n  | j   } |  j j | i   }	 t j |  j	 |   }
 | |	 k r¬ t
 j d j | | |  t  n  x t j |	  D]s } | d  k	 rτ t | j |  rτ t | | |
  n  | j d  k	 rΌ t |
 j | j  rΌ t |
 | j |  qΌ qΌ W|
 |	 | <| |
 _ | |
 _ | |
 _ | |
 _ | |
 _ | |
 _ | |
 _ t |
 _ |
 S(   Nu   default_referenceu   {} requires a reference.uP   Constant {0!r} already has a definition in the {1!r} system from {2!r} reference(   t   Nonet   getattrR   R   R   R   t
   setdefaultt   npt   arrayt   viewt   warningst   warnR	   R   R   t   hasattrt	   __class__t   setattrR   t   _abbrevt   _namet   _valuet   _unit_stringt   _uncertaintyt
   _referencet   _systemt   FalseR   (   t   clsR   R   R7   R   t   uncertaintyt	   referenceR   R   R   R    t   c(    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyR1   Y   s2    %
								c         C` s4   d j  |  j |  j |  j |  j t |  j  |  j  S(   NuE   <{0} name={1!r} value={2} uncertainty={3} unit={4!r} reference={5!r}>(   R   RE   R   R7   RP   t   strR   RQ   (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyt   __repr__|   s    c         C` s(   d j  |  j |  j |  j |  j |  j  S(   NuR     Name   = {0}
  Value  = {1}
  Uncertainty  = {2}
  Unit  = {3}
  Reference = {4}(   R   R   R7   RP   R   RQ   (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyt   __str__   s    c         C` s    t  t |   j |  d t f S(   Ni    (   R0   R;   t   __quantity_subclass__RN   (   R   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyRV      s    c         C` s   |  S(   u¨   
        Return a copy of this `Constant` instance.  Since they are by
        definition immutable, this merely returns another reference to
        ``self``.
        (    (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyt   copy   s    c         C` s   |  j  S(   u   A typical ASCII text abbreviation of the constant, also generally
        the same as the Python variable used for this constant.
        (   RG   (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyR      s    c         C` s   |  j  S(   u   The full name of the constant.(   RH   (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyR      s    c         C` s   t  |  j  S(   u.   The unit(s) in which this constant is defined.(   R   RJ   (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyt   _unit₯   s    c         C` s   |  j  S(   u/   The known uncertainty in this constant's value.(   RK   (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyRP   «   s    c         C` s   |  j  S(   u/   The source used for the value of this constant.(   RL   (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyRQ   ±   s    c         C` s   |  j  S(   u¬   The system of units in which this constant is defined (typically
        `None` so long as the constant's units can be directly converted
        between systems).
        (   RM   (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyR   ·   s    c         C` sO   |  j  |  j j   } | j |  } | d  k	 r5 | St t t |   |  Sd  S(   N(   R   R   R   t   getR<   R=   R0   R;   (   R   t   keyR   R    (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyt   _instance_or_superΐ   s
    c         C` s   |  j  d  S(   u   If the Constant is defined in the SI system return that instance of
        the constant, else convert to a Quantity in the appropriate SI units.
        u   si(   R[   (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyt   siΘ   s    c         C` s   |  j  d  S(   u   If the Constant is defined in the CGS system return that instance of
        the constant, else convert to a Quantity in the appropriate CGS units.
        u   cgs(   R[   (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyt   cgsΠ   s    c         C` sF   x* d	 D]" } t  |  | t | | d    q Wt | d t  |  _ d  S(
   Nu   _abbrevu   _nameu   _valueu   _unit_stringu   _uncertaintyu
   _referenceu   _systemu   _checked_units(   u   _abbrevu   _nameu   _valueu   _unit_stringu   _uncertaintyu
   _referenceu   _system(   RF   R=   R<   RN   R   (   R   t   objR6   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyt   __array_finalize__Ψ   s    
 N(   R8   R9   R:   R   R(   R   R<   R1   RT   RU   RV   RW   t   __deepcopy__t   __copy__t   propertyR   R   R   RX   RP   RQ   R   R[   R\   R]   R_   (    (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyR;   O   s&   	"					
		t
   EMConstantc           B` s   e  Z d  Z e d    Z RS(   u   An electromagnetic constant.c         C` s   t  d   d S(   u{   Overridden for EMConstant to raise a `TypeError`
        emphasizing that there are multiple EM extensions to CGS.
        uγ   Cannot convert EM constants to cgs because there are different systems for E.M constants within the c.g.s system (ESU, Gaussian, etc.). Instead, directly use the constant with the appropriate suffix (e.g. e.esu, e.gauss, etc.).N(   R   (   R   (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyR]   γ   s    (   R8   R9   R:   Rb   R]   (    (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyRc   ΰ   s   (   t
   __future__R    R   R   R   t   externR   R%   R,   RB   t   numpyR?   t
   units.coreR   R   t   units.quantityR   t   utilsR   t   utils.exceptionsR	   t
   utils.miscR
   t   __all__R   t   add_metaclassR;   Rc   (    (    (    s9   lib/python2.7/site-packages/astropy/constants/constant.pyt   <module>   s   ";