B
    d!                 @   s   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gZG dd	 d	eZG d
d de	edZG dd deZdS )    N)Unit
UnitsError)Quantity)lazyproperty)AstropyUserWarningConstant
EMConstantc                   s    e Zd ZdZ fddZ  ZS )ConstantMetaaI  Metaclass for `~astropy.constants.Constant`. The primary purpose of this
    is to wrap the double-underscore methods of `~astropy.units.Quantity`
    which is the superclass of `~astropy.constants.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                s   dd }t ddddddd	d
dddddddg}xLtt D ]<\}}t|tjr<|dr<|dr<||kr<||||< q<W t	 
| |||S )Nc                s   t   fdd}|S )Nc          	      s   | j  }| j| }| jsfxD| D ]8}y| j|j W q$ tk
rZ   | j	| Y q$X q$W d| _| j
s|| jkrtdd |D }td| j| j|d  | f||S )NTc             S   s   g | ]}|r|qS  r
   ).0xr
   r
   g/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/astropy/constants/constant.py
<listcomp>0   s    zGConstantMeta.__new__.<locals>.wrap.<locals>.wrapper.<locals>.<listcomp>zConstant {!r} does not have physically compatible units across all systems of units and cannot be combined with other values without specifying a system (eg. {}.{})r   )namelower	_registry_checked_unitsvaluesunittor   _has_incompatible_unitsaddsystemsorted	TypeErrorformatabbrev)selfargskwargs
name_lower	instancesinstZsystems)methr
   r   wrapper"   s"    


z3ConstantMeta.__new__.<locals>.wrap.<locals>.wrapper)	functoolswraps)r#   r$   r
   )r#   r   wrap!   s    z"ConstantMeta.__new__.<locals>.wrap__new____array_finalize__Z__array_wrap____dir____getattr____init____str____repr____hash____iter____getitem____len____bool____quantity_subclass____setstate____)setvarsr   items
isinstancetypesFunctionType
startswithendswithsuperr(   )mclsr   basesdr'   excludeattrvalue)	__class__r
   r   r(       s    zConstantMeta.__new__)__name__
__module____qualname____doc__r(   __classcell__r
   r
   )rF   r   r	      s   r	   c                   s   e Zd ZdZi Ze Zd!ddZdd Zdd Z	 fd	d
Z
dd Ze ZZedd Zedd Zedd Zedd Zedd Zedd Z fddZedd Zedd Zdd  Z  ZS )"r   zA physical or astronomical constant.

    These objects are quantities that are meant to represent physical
    constants.
    Nc             C   s  |d kr*t | dd }|d kr*t|  d| }| j|i }	t|| }
||	krnt	d
|||t xV|	 D ]J}|d k	rt|j|st|||
 |jd k	rxt|
j|jsxt|
|j| qxW |
|	|< ||
_||
_||
_||
_||
_||
_||
_d|
_|
S )NZdefault_referencez requires a reference.zMConstant {!r} already has a definition in the {!r} system from {!r} referenceF)getattrr   r   r   
setdefaultnparrayviewwarningswarnr   r   r   hasattrrF   setattrr   _abbrev_name_value_unit_string_uncertainty
_reference_systemr   )clsr   r   rE   r   uncertainty	referencer   r    r!   r"   cr
   r
   r   r(   U   s2    zConstant.__new__c             C   s$   d | j| j| j| jt| j| jS )Nz?<{} name={!r} value={} uncertainty={} unit={!r} reference={!r}>)r   rF   r   rE   r]   strr   r^   )r   r
   r
   r   r.   x   s    zConstant.__repr__c             C   s   d | j| j| j| j| jS )NzM  Name   = {}
  Value  = {}
  Uncertainty  = {}
  Unit  = {}
  Reference = {})r   r   rE   r]   r   r^   )r   r
   r
   r   r-   ~   s    zConstant.__str__c                s   t  |d dfS )Nr   F)r?   r4   )r   r   )rF   r
   r   r4      s    zConstant.__quantity_subclass__c             C   s   | S )z
        Return a copy of this `Constant` instance.  Since they are by
        definition immutable, this merely returns another reference to
        ``self``.
        r
   )r   r
   r
   r   copy   s    zConstant.copyc             C   s   | j S )zA typical ASCII text abbreviation of the constant, also generally
        the same as the Python variable used for this constant.
        )rU   )r   r
   r
   r   r      s    zConstant.abbrevc             C   s   | j S )zThe full name of the constant.)rV   )r   r
   r
   r   r      s    zConstant.namec             C   s
   t | jS )z.The unit(s) in which this constant is defined.)r   rX   )r   r
   r
   r   _unit   s    zConstant._unitc             C   s   | j S )z8The known absolute uncertainty in this constant's value.)rY   )r   r
   r
   r   r]      s    zConstant.uncertaintyc             C   s   | j S )z/The source used for the value of this constant.)rZ   )r   r
   r
   r   r^      s    zConstant.referencec             C   s   | j S )zThe system of units in which this constant is defined (typically
        `None` so long as the constant's units can be directly converted
        between systems).
        )r[   )r   r
   r
   r   r      s    zConstant.systemc                s6   | j | j  }||}|d k	r&|S tt |S d S )N)r   r   r   getrL   r?   )r   keyr!   r"   )rF   r
   r   _instance_or_super   s
    
zConstant._instance_or_superc             C   s
   |  dS )zIf the Constant is defined in the SI system return that instance of
        the constant, else convert to a Quantity in the appropriate SI units.
        si)re   )r   r
   r
   r   rf      s    zConstant.sic             C   s
   |  dS )zIf the Constant is defined in the CGS system return that instance of
        the constant, else convert to a Quantity in the appropriate CGS units.
        cgs)re   )r   r
   r
   r   rg      s    zConstant.cgsc             C   s4   x dD ]}t | |t||d  qW t|dd| _d S )N)rU   rV   rW   rX   rY   rZ   r[   r   F)rT   rL   r   )r   objrD   r
   r
   r   r)      s    
zConstant.__array_finalize__)NN)rG   rH   rI   rJ   r   r7   r   r(   r.   r-   r4   ra   __deepcopy____copy__propertyr   r   r   rb   r]   r^   r   re   rf   rg   r)   rK   r
   r
   )rF   r   r   L   s&   
"		)	metaclassc               @   s   e Zd ZdZedd ZdS )r   zAn electromagnetic constant.c             C   s   t ddS )z{Overridden for EMConstant to raise a `TypeError`
        emphasizing that there are multiple EM extensions to CGS.
        zCannot 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   r
   r
   r   rg      s    zEMConstant.cgsN)rG   rH   rI   rJ   rk   rg   r
   r
   r
   r   r      s   )r%   r;   rQ   numpyrN   Zastropy.units.corer   r   Zastropy.units.quantityr   Zastropy.utilsr   Zastropy.utils.exceptionsr   __all__typer	   r   r   r
   r
   r
   r   <module>   s   < 