
    IR-e;                     \   d dl Z d dlZd dlmZmZmZmZmZm	Z	m
Z
 ddlmZmZ ddlmZmZmZ g dZ G d de          Z G d	 d
e          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Zee_        ee_        ee_         ee
j                  Zde_         ee
j                  Z de _         ee
j!                  Z"de
j!        j#         e"_         ee
j$                  Z%de
j$        j#         e%_        dS )    N)CompositeUnitUnitUnitConversionError
UnitsErrorUnitTypeErrordimensionless_unscaledphotometric   )FunctionQuantityFunctionUnitBase)dBdexmag)LogUnitMagUnitDexUnitDecibelUnitLogQuantity	MagnitudeDecibelDexSTmagABmagM_bolm_bolc                   n    e Zd ZdZed             Zed             Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd ZdS )r   a!  Logarithmic unit containing a physical one.

    Usually, logarithmic units are instantiated via specific subclasses
    such `~astropy.units.MagUnit`, `~astropy.units.DecibelUnit`, and
    `~astropy.units.DexUnit`.

    Parameters
    ----------
    physical_unit : `~astropy.units.Unit` or `string`
        Unit that is encapsulated within the logarithmic function unit.
        If not given, dimensionless.

    function_unit :  `~astropy.units.Unit` or `string`
        By default, the same as the logarithmic unit set by the subclass.

    c                     t           S Nr   selfs    Blib/python3.11/site-packages/astropy/units/function/logarithmic.py_default_function_unitzLogUnit._default_function_unit6       
    c                     t           S r   )r   r    s    r"   _quantity_classzLogUnit._quantity_class:   s    r%   c                 Z    t          j        | j        t          j        |                    S )zjTransformation from value in physical to value in logarithmic units.
        Used in equivalency.
        )r   to_function_unitnplog10r!   xs     r"   from_physicalzLogUnit.from_physical>   s!     vd)28A;;777r%   c                 H    d| j                             t          |          z  S )zjTransformation from value in logarithmic to value in physical units.
        Used in equivalency.
        
   )r*   r)   r   r-   s     r"   to_physicalzLogUnit.to_physicalD   s"     T(++C3333r%   c                 @   	 t          |d|                              | j                   n/# t          $ r
 t          cY S t
          $ r t          d          w xY wt          |dt                    }t          d| j        |g||g          }| 	                    |          S )u  Add/subtract LogUnit to/from another unit, and adjust physical unit.

        self and other are multiplied by sign_self and sign_other, resp.

        We wish to do:   ±lu_1 + ±lu_2  -> lu_f          (lu=logarithmic unit)
                  and     pu_1^(±1) * pu_2^(±1) -> pu_f  (pu=physical unit)

        Raises
        ------
        UnitsError
            If function units are not equivalent.
        function_unitz;Can only add/subtract logarithmic units of compatible type.physical_unitr
   )
getattr_tor*   AttributeErrorNotImplementedr   r   r   _physical_unit_copy)r!   other	sign_self
sign_otherother_physical_unitr5   s         r"   _add_and_adjust_physical_unitz%LogUnit._add_and_adjust_physical_unitN   s     	E?E2266t7JKKKK 	" 	" 	"!!!! 	 	 	M  	
 &e_>TUU%#%89Iz;R
 
 zz-(((s   ), AAc                 <    |                      | j        dz            S )N)r;   r5   r    s    r"   __neg__zLogUnit.__neg__o   s    zz$,4555r%   c                 0    |                      |dd          S Nr
   r@   r!   r<   s     r"   __add__zLogUnit.__add__r        11%R@@@r%   c                 0    |                      |dd          S rE   rF   rG   s     r"   __radd__zLogUnit.__radd__w       11%R@@@r%   c                 0    |                      |dd          S )Nr
   rB   rF   rG   s     r"   __sub__zLogUnit.__sub__z   rL   r%   c                 0    |                      |dd          S )NrB   r
   rF   rG   s     r"   __rsub__zLogUnit.__rsub__}   rI   r%   N)__name__
__module____qualname____doc__propertyr#   r'   r/   r2   r@   rC   rH   rK   rN   rP    r%   r"   r   r   #   s         $   X   X8 8 84 4 4) ) )B6 6 6A A A
A A AA A AA A A A Ar%   r   c                   >    e Zd ZdZed             Zed             ZdS )r   a  Logarithmic physical units expressed in magnitudes.

    Parameters
    ----------
    physical_unit : `~astropy.units.Unit` or `string`
        Unit that is encapsulated within the magnitude function unit.
        If not given, dimensionless.

    function_unit :  `~astropy.units.Unit` or `string`
        By default, this is ``mag``, but this allows one to use an equivalent
        unit such as ``2 mag``.
    c                     t           S r   )r   r    s    r"   r#   zMagUnit._default_function_unit   r$   r%   c                     t           S r   )r   r    s    r"   r'   zMagUnit._quantity_class   s    r%   NrQ   rR   rS   rT   rU   r#   r'   rV   r%   r"   r   r      sT            X   X  r%   r   c                   P     e Zd ZdZed             Zed             Zd fd	Z xZS )r   a  Logarithmic physical units expressed in magnitudes.

    Parameters
    ----------
    physical_unit : `~astropy.units.Unit` or `string`
        Unit that is encapsulated within the magnitude function unit.
        If not given, dimensionless.

    function_unit :  `~astropy.units.Unit` or `string`
        By default, this is ``dex``, but this allows one to use an equivalent
        unit such as ``0.5 dex``.
    c                     t           S r   r   r    s    r"   r#   zDexUnit._default_function_unit   r$   r%   c                     t           S r   )r   r    s    r"   r'   zDexUnit._quantity_class   r$   r%   genericc                     |dk    r1| j         t          k    rdS d| j                             |           dS t                                                      S )Ncdsz[-][)format])r5   r   	to_stringsuper)r!   rb   	__class__s     r"   rd   zDexUnit.to_string   s[    U??!%;;;uI4-77v7FFIIII77$$&&&r%   )r^   )	rQ   rR   rS   rT   rU   r#   r'   rd   __classcell__rf   s   @r"   r   r      s}            X   X' ' ' ' ' ' ' ' ' 'r%   r   c                   >    e Zd ZdZed             Zed             ZdS )r   a  Logarithmic physical units expressed in dB.

    Parameters
    ----------
    physical_unit : `~astropy.units.Unit` or `string`
        Unit that is encapsulated within the decibel function unit.
        If not given, dimensionless.

    function_unit :  `~astropy.units.Unit` or `string`
        By default, this is ``dB``, but this allows one to use an equivalent
        unit such as ``2 dB``.
    c                     t           S r   )r   r    s    r"   r#   z"DecibelUnit._default_function_unit   s    	r%   c                     t           S r   )r   r    s    r"   r'   zDecibelUnit._quantity_class   s    r%   NrZ   rV   r%   r"   r   r      sT            X   X  r%   r   c                        e Zd ZdZeZd Zd Zd Zd Z	d Z
d Z fdZd	 Z fd
Z fdZ fdZd Zd ZddZddZddZddZddZej        d dD             z  Z xZS )r   a  A representation of a (scaled) logarithm of a number with a unit.

    Parameters
    ----------
    value : number, `~astropy.units.Quantity`, `~astropy.units.LogQuantity`, or sequence of quantity-like.
        The numerical value of the logarithmic quantity. If a number or
        a `~astropy.units.Quantity` with a logarithmic unit, it will be
        converted to ``unit`` and the physical unit will be inferred from
        ``unit``.  If a `~astropy.units.Quantity` with just a physical unit,
        it will converted to the logarithmic unit, after, if necessary,
        converting it to the physical unit inferred from ``unit``.

    unit : str, `~astropy.units.UnitBase`, or `~astropy.units.FunctionUnitBase`, optional
        For an `~astropy.units.FunctionUnitBase` instance, the
        physical unit will be taken from it; for other input, it will be
        inferred from ``value``. By default, ``unit`` is set by the subclass.

    dtype : `~numpy.dtype`, optional
        The ``dtype`` of the resulting Numpy array or scalar that will
        hold the value.  If not provided, is is determined automatically
        from the input value.

    copy : bool, optional
        If `True` (default), then the value is copied.  Otherwise, a copy will
        only be made if ``__array__`` returns a copy, if value is a nested
        sequence, or if a copy is needed to satisfy an explicitly given
        ``dtype``.  (The `False` option is intended mostly for internal use,
        to speed up initialization where a copy is known to have been made.
        Use with care.)

    Examples
    --------
    Typically, use is made of an `~astropy.units.FunctionQuantity`
    subclass, as in::

        >>> import astropy.units as u
        >>> u.Magnitude(-2.5)
        <Magnitude -2.5 mag>
        >>> u.Magnitude(10.*u.count/u.second)
        <Magnitude -2.5 mag(ct / s)>
        >>> u.Decibel(1.*u.W, u.DecibelUnit(u.mW))  # doctest: +FLOAT_CMP
        <Decibel 30. dB(mW)>

    c                     | j         t          |dt                    z   }| j        t          |d|          z   }|                     ||          S Nunit_function_viewro   r6   r   rp   	_new_viewr!   r<   new_unitresults       r"   rH   zLogQuantity.__add__  sK     9wuf6LMMM$wu6F'N'NN~~fh///r%   c                 ,    |                      |          S r   )rH   rG   s     r"   rK   zLogQuantity.__radd__      ||E"""r%   c                     | j         t          |dt                    z   }| j        }|t          |d|          z  }|                     |           | S rn   ro   r6   r   rp   	_set_unitr!   r<   rt   function_views       r"   __iadd__zLogQuantity.__iadd__  Q    9wuf6LMMM+(8%@@@x   r%   c                     | j         t          |dt                    z
  }| j        t          |d|          z
  }|                     ||          S rn   rq   rs   s       r"   rN   zLogQuantity.__sub__  sI    9wuf6LMMM$wu6F'N'NN~~fh///r%   c                    | j                             t          |dt                              }| j                            t          |d|                    }|                    |j                  }|                     ||          S rn   )ro   rP   r6   r   rp   r)   r4   rr   rs   s       r"   rP   zLogQuantity.__rsub__  sq    9%%geV=S&T&TUU$--ge=Mu.U.UVV 8122~~fh///r%   c                     | j         t          |dt                    z
  }| j        }|t          |d|          z  }|                     |           | S rn   ry   r{   s       r"   __isub__zLogQuantity.__isub__&  r~   r%   c                 8   t          |t          j                  r_| j        j        |z  }|                     t          j                  |z  }|                     || j        	                    |                    S t                                          |          S r   )
isinstancenumbersNumberro   r5   viewr+   ndarrayrr   r;   re   __mul__r!   r<   new_physical_unitru   rf   s       r"   r   zLogQuantity.__mul__.  sz    eW^,, 	* !%	 7 >YYrz**U2F>>&$)//:K*L*LMMM77??5)))r%   c                 ,    |                      |          S r   )r   rG   s     r"   __rmul__zLogQuantity.__rmul__9  rw   r%   c                    t          |t          j                  rJ| j        j        |z  }| j        }||z  }|                     | j                            |                     | S t                      	                    |          S r   )
r   r   r   ro   r5   rp   rz   r;   re   __imul__r!   r<   r   r|   rf   s       r"   r   zLogQuantity.__imul__<  sw    eW^,, 	+ $	 7 > /MU"MNN49??+<==>>>K77##E***r%   c                 >   t          |t          j                  rb| j        j        d|z  z  }|                     t          j                  |z  }|                     || j        	                    |                    S t                                          |          S rE   )r   r   r   ro   r5   r   r+   r   rr   r;   re   __truediv__r   s       r"   r   zLogQuantity.__truediv__F  s    eW^,, 	. !%	 7AI FYYrz**U2F>>&$)//:K*L*LMMM77&&u---r%   c                    t          |t          j                  rM| j        j        d|z  z  }| j        }||z  }|                     | j                            |                     | S t                      	                    |          S rE   )
r   r   r   ro   r5   rp   rz   r;   re   __itruediv__r   s       r"   r   zLogQuantity.__itruediv__Q  s{    eW^,, 	/ $	 7AI F /MU"MNN49??+<==>>>K77''...r%   c                     	 t          |          }n# t          $ r
 t          cY S w xY w| j        |z  }|                     t
          j                  |z  }|                     ||          S r   )float	TypeErrorr9   ro   r   r+   r   rr   )r!   r<   rt   	new_values       r"   __pow__zLogQuantity.__pow__[  ss    	"%LLEE 	" 	" 	"!!!!	"9e#IIbj))U2	~~i222s    &&c                 R   	 t          |          }n# t          $ r
 t          cY S w xY wt          || j                  st          S 	 | j        j                            |j                  }|                     t          j
                  dxx         | j                            |          z  cc<   nb# t          $ rU 	 |                     |          }n# t          $ r t          cY cY S w xY w||                     t          j
                  d<   Y nw xY w|                     |           | S )N.)r   r   r9   r   _unit_classro   r5   r7   r   r+   r   r/   r   	_to_valuerz   )r!   r<   factorvalues       r"   __ilshift__zLogQuantity.__ilshift__e  sS   	"KKEE 	" 	" 	"!!!!	" %!122 	"!!	JY,001DEEF IIbj!!#&&&$)*A*A&*I*II&&&& # 	/ 	/ 	/&u--& & & &%%%%%%& */DIIbj!!#&&&	/ 	usB    &&$B0 0
D;CDC'"D&C''%DDNr   c                 j    | j         j        dz  }|                     t          j        |||||          S )N   outddofro   )ro   r4   _wrap_functionr+   varr!   axisdtyper   r   ro   s         r"   r   zLogQuantity.var  s5    y&)""264CdQU"VVVr%   c                     | j                             t                    }|                     t          j        |||||          S )Nr   )ro   r;   r   r   r+   stdr   s         r"   r   zLogQuantity.std  s:    y566""264CdQU"VVVr%   c                     | j                             t                    }|                     t          j        |||          S )N)r   ro   )ro   r;   r   r   r+   ptp)r!   r   r   ro   s       r"   r   zLogQuantity.ptp  s5    y566""264St"DDDr%   r
   rB   c                     | j                             t                    }|                     t          j        |||          S N)ro   )ro   r;   r   r   r+   diff)r!   nr   ro   s       r"   r   zLogQuantity.diff  s5    y566""27At$"???r%   c                     | j                             t                    }|                     t          j        |||          S r   )ro   r;   r   r   r+   ediff1d)r!   to_endto_beginro   s       r"   r   zLogQuantity.ediff1d  s5    y566""2:vxd"KKKr%   c                 8    h | ]}t          t          |          S rV   )r6   r+   ).0functions     r"   	<setcomp>zLogQuantity.<setcomp>  s5     D D D"*HD D Dr%   )r   r   r   r   r   )NNNr   )NN)r
   rB   )rQ   rR   rS   rT   r   r   rH   rK   r}   rN   rP   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _supported_functionsrg   rh   s   @r"   r   r      s       + +\ K0 0 0# # #  0 0 00 0 0  	* 	* 	* 	* 	*# # #+ + + + +	. 	. 	. 	. 	./ / / / /3 3 3  8W W W WW W W WE E E E@ @ @ @L L L L ,@ D D.VD D D r%   r   c                       e Zd ZeZdS )r   N)rQ   rR   rS   r   r   rV   r%   r"   r   r             KKKr%   r   c                       e Zd ZeZdS )r   N)rQ   rR   rS   r   r   rV   r%   r"   r   r     s        KKKr%   r   c                       e Zd ZeZdS )r   N)rQ   rR   rS   r   r   rV   r%   r"   r   r     r   r%   r   z6ST magnitude: STmag=-21.1 corresponds to 1 erg/s/cm2/Az7AB magnitude: ABmag=-48.6 corresponds to 1 erg/s/cm2/Hzz=Absolute bolometric magnitude: M_bol=0 corresponds to L_bol0=z=Apparent bolometric magnitude: m_bol=0 corresponds to f_bol0=)&r   numpyr+   astropy.unitsr   r   r   r   r   r   r	   corer   r   unitsr   r   r   __all__r   r   r   r   r   r   r   r   _function_unit_classSTfluxr   rT   ABfluxr   Bolr   sibolr   rV   r%   r"   <module>r      s                         5 4 4 4 4 4 4 4             ]A ]A ]A ]A ]A ]A ]A ]A@    g   .' ' ' ' 'g ' ' '@    '   .F F F F F" F F FR    +       k           # % "  	"##H"##I  XKODVXX  	  XKODVXX r%   