
    HR-e$                         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	e          Z G d
 de	e          Z G d de          ZdS )    N)Unit
UnitsError)Quantity)lazyproperty)AstropyUserWarningConstant
EMConstantc                   "     e Zd ZdZ fdZ x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                 ^   d }h d}t          t                                                    D ][\  }}t          |t          j                  r<|                    d          r'|                    d          r||vr ||          ||<   \t                      	                    | |||          S )Nc                 F     t          j                    fd            }|S )Nc           	         | j                                         }| j        |         }| j        sh|                                D ]L}	 | j                            |j                   ## t          $ r | j        	                    |           Y Iw xY wd| _        | j
        sK|| j        v rBt          d |D                       }t          d| j        d| j         d|d          d           | g|R i |S )NTc              3      K   | ]}||V  	d S N ).0xs     :lib/python3.11/site-packages/astropy/constants/constant.py	<genexpr>zFConstantMeta.__new__.<locals>.wrap.<locals>.wrapper.<locals>.<genexpr>0   s'      $?$?1Q$?Q$?$?$?$?$?$?    	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instsystemsmeths          r   wrapperz3ConstantMeta.__new__.<locals>.wrap.<locals>.wrapper#   sV   !Y__..
 N:6	* / ) 0 0 2 2 I II ILL3333) I I I 8<<ZHHHHHI*.D'{ zT5Q'Q'Q$$?$?	$?$?$???G#CDK C C (,{C C 6=QZC C C   tD242226222s   A&&$BB)	functoolswraps)r.   r/   s   ` r   wrapz"ConstantMeta.__new__.<locals>.wrap"   s8    _T""3 3 3 3 #"3, Nr   >   __dir____len____new____str____bool____hash____init____iter____repr____getattr____getitem____setstate____array_wrap____array_finalize____quantity_subclass____)
varsr   items
isinstancetypesFunctionType
startswithendswithsuperr5   )	mclsr   basesdr2   excludeattrvalue	__class__s	           r   r5   zConstantMeta.__new__!   s    	 	 	8
 
 
"  >>//11 	& 	&KD%5%"455&OOD))& MM$''& ''$u++$wwtT5!444r   )__name__
__module____qualname____doc__r5   __classcell__rQ   s   @r   r   r      sB         75 75 75 75 75 75 75 75 75r   r   c                       e Zd ZdZi Z e            Z	 ddZd Zd Z	 fdZ
d ZexZZed             Zed	             Zed
             Zed             Zed             Zed             Z fdZed             Zed             Zd Z x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           	         |%t          | dd           }|t          |  d          |                                }| j                            |i           }	t          j        |                              |           }
||	v r$t          j	        d|d|d|dt                     |	                                D ]a}|&t          |j        |          st          |||
           |j        0t          |
j        |j                  st          |
|j        |           b|
|	|<   ||
_        ||
_        ||
_        ||
_        ||
_        ||
_        ||
_        d|
_        |
S )N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   hasattrrQ   setattrr#   _abbrev_name_value_unit_string_uncertainty
_reference_systemr   )clsr&   r   rP   r   uncertainty	referencer#   r*   r+   r,   cs               r   r5   zConstant.__new__{   s    %8$??I 3 > > >???ZZ\\
M,,Z<<	 x##C((YMFD F FF F.7F F F"  
 !!## 	+ 	+A!'!+v*F*F!64(((x#GDNAH,M,M#ah*** 	&
 '##r   c                     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=>)rQ   r   rP   rl   strr   rm   r'   s    r   r;   zConstant.__repr__   sw    - - -I- -Z- -  +- - 	NN	- -
 - - -	
r   c           
      V    d| j          d| j         d| j         d| j         d| j         
S )Nz  Name   = z
  Value  = z
  Uncertainty  = z
  Unit  = z
  Reference = )r   rP   rl   r   rm   rs   s    r   r6   zConstant.__str__   s[    .$) . .*. . $ 0. . . . "^	. .	
r   c                 V    t                                          |          d         dfS )Nr   F)rJ   rA   )r'   r   rQ   s     r   rA   zConstant.__quantity_subclass__   s%    ww,,T2215u<<r   c                     | S )z
        Return a copy of this `Constant` instance.  Since they are by
        definition immutable, this merely returns another reference to
        ``self``.
        r   rs   s    r   copyzConstant.copy   s	     r   c                     | j         S )zA typical ASCII text abbreviation of the constant, also generally
        the same as the Python variable used for this constant.
        )rd   rs   s    r   r&   zConstant.abbrev   s    
 |r   c                     | j         S )zThe full name of the constant.)re   rs   s    r   r   zConstant.name   s     zr   c                 *    t          | j                  S )z.The unit(s) in which this constant is defined.)r   rg   rs   s    r   _unitzConstant._unit   s     D%&&&r   c                     | j         S )z8The known absolute uncertainty in this constant's value.)rh   rs   s    r   rl   zConstant.uncertainty   s       r   c                     | j         S )z/The source used for the value of this constant.)ri   rs   s    r   rm   zConstant.reference   s     r   c                     | 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).
        )rj   rs   s    r   r#   zConstant.system   s     |r   c                     | j         | j                                                 }|                    |          }||S t	          t                      |          S r   )r   r   r   getr[   rJ   )r'   keyr+   r,   rQ   s       r   _instance_or_superzConstant._instance_or_super   sK    N49??#4#45	}}S!!K577C(((r   c                 ,    |                      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r   rs   s    r   r   zConstant.si   s    
 &&t,,,r   c                 ,    |                      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.
        cgsr   rs   s    r   r   zConstant.cgs   s    
 &&u---r   c           
      |    dD ]"}t          | |t          ||d                      #t          |dd          | _        d S )N)rd   re   rf   rg   rh   ri   rj   r   F)rc   r[   r   )r'   objrO   s      r   r@   zConstant.__array_finalize__   sQ    
 		: 		:D D$T4 8 89999%c+;UCCr   )NN)rR   rS   rT   rU   r   setr!   r5   r;   r6   rA   rw   __deepcopy____copy__propertyr&   r   r   r{   rl   rm   r#   r   r   r   r@   rV   rW   s   @r   r   r   [   s        8 I!cee MQ$ $ $ $L
 
 

 
 
= = = = =   #"L8  X   X ' ' \' ! ! X!   X   X) ) ) ) ) - - X- . . X.D D D D D D Dr   )	metaclassc                   (    e Zd ZdZed             ZdS )r	   zAn electromagnetic constant.c                      t          d          )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.).)r%   rs   s    r   r   zEMConstant.cgs  s    
 2
 
 	
r   N)rR   rS   rT   rU   r   r   r   r   r   r	   r	   	  s3        &&

 

 X

 

 

r   )r0   rF   r`   numpyr]   astropy.units.corer   r   astropy.units.quantityr   astropy.utilsr   astropy.utils.exceptionsr   __all__typer   r   r	   r   r   r   <module>r      s4             / / / / / / / / + + + + + + & & & & & & 7 7 7 7 7 7|
$G5 G5 G5 G5 G54 G5 G5 G5TkD kD kD kD kDx< kD kD kD kD\
 
 
 
 
 
 
 
 
 
r   