U
    e»{jµ$  ã                   @   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„ }ddddddd	d
dddddddh}t tƒ ¡ D ]<\}}t|tjƒr6| d¡r6| d¡r6||kr6||ƒ||< q6tƒ  	| |||¡S )Nc                    s   t  ˆ ¡‡ fdd„ƒ}|S )Nc              	      s¸   | j  ¡ }| j| }| jsb| ¡ D ]8}z| j |j¡ W q" tk
rX   | j 	|¡ Y q"X q"d| _| j
s¨|| jkr¨tdd„ |D ƒƒ}td| j›d| j› d|d › d�ƒ‚ˆ | f|ž|ŽS )	NTc                 s   s   | ]}|r|V  qd S ©N© )Ú.0Úxr   r   úY/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/constants/constant.pyÚ	<genexpr>0   s      zFConstantMeta.__new__.<locals>.wrap.<locals>.wrapper.<locals>.<genexpr>ú	Constant z‘ 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Ú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__Ú__)
Úvarsr   ÚitemsÚ
isinstanceÚtypesÚFunctionTypeÚ
startswithÚendswithÚsuperr,   )Úmclsr   ÚbasesÚdr+   ÚexcludeÚattrÚvalue©Ú	__class__r   r   r,   !   s8    ñ
ÿþýüzConstantMeta.__new__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r,   Ú__classcell__r   r   rI   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   a©  A physical or astronomical constant.

    These objects are quantities that are meant to represent physical
    constants.

    Parameters
    ----------
    abbrev : str
        A typical ASCII text abbreviation of the constant, generally
        the same as the Python variable used for this constant.
    name : str
        Full constant name.
    value : numbers.Real
        Constant value. Note that this should be a bare number, not a
        |Quantity|.
    unit : str
        String representation of the constant units.
    uncertainty : numbers.Real
        Absolute uncertainty in constant value. Note that this should be
        a bare number, not a |Quantity|.
    reference : str, optional
        Reference where the value is taken from.
    system : str
        System of units in which the constant is defined. This can be
        `None` when the constant's units can be directly converted
        between systems.
    Nc              	   C   s  |d kr*t | dd ƒ}|d kr*t| › d�ƒ‚| ¡ }| j |i ¡}	t |¡ | ¡}
||	krxt 	d|›d|›d|›d�t
¡ |	 ¡ D ]J}|d k	r¤t|j|ƒs¤t|||
ƒ |jd k	r€t|
j|jƒs€t|
|j|ƒ q€|
|	|< ||
_||
_||
_||
_||
_||
_||
_d|
_|
S )NZdefault_referencez requires a reference.r   z! already has a definition in the z system from z
 referenceF)Úgetattrr   r   r   Ú
setdefaultÚnpÚarrayÚviewÚwarningsÚwarnr   r   ÚhasattrrJ   Úsetattrr   Ú_abbrevÚ_nameÚ_valueÚ_unit_stringÚ_uncertaintyÚ
_referenceÚ_systemr   )Úclsr   r   rH   r   ÚuncertaintyÚ	referencer   r#   r$   r%   Úcr   r   r   r,   {   s6    ýzConstant.__new__c                 C   s:   d| j › d| j›d| j› d| j› dt| jƒ›d| j›d�S )Nú<z name=z value=z uncertainty=z unit=z reference=ú>)rJ   r   rH   ra   Ústrr   rb   ©r    r   r   r   r2   ¡   s    8ÿzConstant.__repr__c              
   C   s,   d| j › d| j› d| j› d| j› d| j› �
S )Nz  Name   = z
  Value  = z
  Uncertainty  = z
  Unit  = z
  Reference = )r   rH   ra   r   rb   rg   r   r   r   r1   «   s    *ÿzConstant.__str__c                    s   t ƒ  |¡d dfS )Nr   F)rB   r8   )r    r   rI   r   r   r8   ´   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   rg   r   r   r   Úcopy·   s    zConstant.copyc                 C   s   | j S )zŠA typical ASCII text abbreviation of the constant, also generally
        the same as the Python variable used for this constant.
        )rY   rg   r   r   r   r   Á   s    zConstant.abbrevc                 C   s   | j S )zThe full name of the constant.)rZ   rg   r   r   r   r   É   s    zConstant.namec                 C   s
   t | jƒS )z.The unit(s) in which this constant is defined.)r   r\   rg   r   r   r   Ú_unitÏ   s    zConstant._unitc                 C   s   | j S )z8The known absolute uncertainty in this constant's value.)r]   rg   r   r   r   ra   Õ   s    zConstant.uncertaintyc                 C   s   | j S )z/The source used for the value of this constant.)r^   rg   r   r   r   rb   Û   s    zConstant.referencec                 C   s   | j S )z¬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).
        )r_   rg   r   r   r   r   á   s    zConstant.systemc                    s6   | j | j ¡  }| |¡}|d k	r&|S ttƒ |ƒS d S r
   )r   r   r   ÚgetrP   rB   )r    Úkeyr$   r%   rI   r   r   Ú_instance_or_superê   s
    
zConstant._instance_or_superc                 C   s
   |   d¡S )zš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.
        Úsi©rl   rg   r   r   r   rm   ò   s    zConstant.sic                 C   s
   |   d¡S )zœ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.
        Úcgsrn   rg   r   r   r   ro   ú   s    zConstant.cgsc                 C   s0   dD ]}t | |t||d ƒƒ qt|ddƒ| _d S )N)rY   rZ   r[   r\   r]   r^   r_   r   F)rX   rP   r   )r    ÚobjrG   r   r   r   r-     s    	zConstant.__array_finalize__)NN)rK   rL   rM   rN   r   Úsetr   r,   r2   r1   r8   rh   Ú__deepcopy__Ú__copy__Úpropertyr   r   r   ri   ra   rb   r   rl   rm   ro   r-   rO   r   r   rI   r   r   [   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.
        zã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   rg   r   r   r   ro     s    ÿzEMConstant.cgsN)rK   rL   rM   rN   rt   ro   r   r   r   r   r     s   )r)   r>   rU   ÚnumpyrR   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   J 7