U
    e»{jŠ;  ã                   @   s^  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 dddd	d
dddddddgZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd	„ d	eƒZG dd
„ d
eƒZG dd„ deƒZG dd„ deƒZG d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                   @   sh   e Zd ZdZedd„ ƒZedd„ ƒZdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zd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                 C   s   t S ©N©r   ©Úself© r   úa/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/units/function/logarithmic.pyÚ_default_function_unit6   s    zLogUnit._default_function_unitc                 C   s   t S r   )r   r   r   r   r    Ú_quantity_class:   s    zLogUnit._quantity_classc                 C   s   t  | jt |¡¡S )zaTransformation from value in physical to value in logarithmic units.
        Used in equivalency.)r   ÚtoÚ_function_unitÚnpÚlog10©r   Úxr   r   r    Úfrom_physical>   s    zLogUnit.from_physicalc                 C   s   d| j  t|¡ S )zaTransformation from value in logarithmic to value in physical units.
        Used in equivalency.é
   )r$   r#   r   r'   r   r   r    Úto_physicalC   s    zLogUnit.to_physicalc                 C   sx   zt |d|ƒ | j¡ W n2 tk
r0   t Y S  tk
rJ   tdƒ‚Y nX 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   Z_physical_unitÚ_copy)r   ÚotherZ	sign_selfZ
sign_otherZother_physical_unitr-   r   r   r    Ú_add_and_adjust_physical_unitL   s    ÿ
  ÿz%LogUnit._add_and_adjust_physical_unitc                 C   s   |   | jd ¡S )Néÿÿÿÿ)r2   r-   r   r   r   r    Ú__neg__m   s    zLogUnit.__neg__c                 C   s   |   |dd¡S ©Nr	   ©r4   ©r   r3   r   r   r    Ú__add__p   s    zLogUnit.__add__c                 C   s   |   |dd¡S r7   r8   r9   r   r   r    Ú__radd__u   s    zLogUnit.__radd__c                 C   s   |   |dd¡S )Nr	   r5   r8   r9   r   r   r    Ú__sub__x   s    zLogUnit.__sub__c                 C   s   |   |dd¡S )Nr5   r	   r8   r9   r   r   r    Ú__rsub__{   s    zLogUnit.__rsub__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr!   r"   r)   r+   r4   r6   r:   r;   r<   r=   r   r   r   r    r   #   s   

	!c                   @   s(   e Zd ZdZedd„ ƒZed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                 C   s   t S r   )r   r   r   r   r    r!   �   s    zMagUnit._default_function_unitc                 C   s   t S r   )r   r   r   r   r    r"   “   s    zMagUnit._quantity_classN©r>   r?   r@   rA   rB   r!   r"   r   r   r   r    r   �   s
   
c                       s:   e Zd ZdZedd„ ƒZedd„ ƒZd	‡ fdd„	Z‡  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                 C   s   t S r   r   r   r   r   r    r!   ¦   s    zDexUnit._default_function_unitc                 C   s   t S r   )r   r   r   r   r    r"   ª   s    zDexUnit._quantity_classÚgenericc                    s<   |dkr.| j tkrdS d| j j|d�› d�S n
tƒ  ¡ S d S )NZcdsz[-]ú[)Úformatú])r-   r   Ú	to_stringÚsuper)r   rF   ©Ú	__class__r   r    rH   ®   s
    
zDexUnit.to_string)rD   )	r>   r?   r@   rA   rB   r!   r"   rH   Ú__classcell__r   r   rJ   r    r   ˜   s   

c                   @   s(   e Zd ZdZedd„ ƒZed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                 C   s   t S r   )r   r   r   r   r    r!   Æ   s    z"DecibelUnit._default_function_unitc                 C   s   t S r   )r   r   r   r   r    r"   Ê   s    zDecibelUnit._quantity_classNrC   r   r   r   r    r   ¸   s
   
c                       sÖ   e Zd ZdZeZdd„ Zdd„ Zdd„ Zdd	„ Z	d
d„ Z
dd„ Z‡ fdd„Zdd„ Z‡ fdd„Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Zd-dd„Zd.d d!„Zd/d"d#„Zd0d&d'„Zd1d(d)„Zejd*d+„ d,D ƒB Z‡  ZS )2r   aÚ  A representation of a (scaled) logarithm of a number with a unit

    Parameters
    ----------
    value : number, `~astropy.units.Quantity`, `~astropy.units.function.logarithmic.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                 C   s0   | j t|dtƒ }| jt|d|ƒ }|  ||¡S ©NÚunitÚ_function_view©rN   r.   r   rO   Ú	_new_view©r   r3   Únew_unitÚresultr   r   r    r:     s    zLogQuantity.__add__c                 C   s
   |   |¡S r   )r:   r9   r   r   r    r;   
  s    zLogQuantity.__radd__c                 C   s6   | j t|dtƒ }| j}|t|d|ƒ7 }|  |¡ | S rM   ©rN   r.   r   rO   Ú	_set_unit©r   r3   rS   Úfunction_viewr   r   r    Ú__iadd__  s
    
zLogQuantity.__iadd__c                 C   s0   | j t|dtƒ }| jt|d|ƒ }|  ||¡S rM   rP   rR   r   r   r    r<     s    zLogQuantity.__sub__c                 C   s@   | j  t|dtƒ¡}| j t|d|ƒ¡}| |j¡}|  ||¡S rM   )rN   r=   r.   r   rO   r#   r,   rQ   rR   r   r   r    r=     s    zLogQuantity.__rsub__c                 C   s6   | j t|dtƒ }| j}|t|d|ƒ8 }|  |¡ | S rM   rU   rW   r   r   r    Ú__isub__$  s
    
zLogQuantity.__isub__c                    sL   t |tjƒr<| jj| }|  tj¡| }|  || j 	|¡¡S t
ƒ  |¡S d S r   )Ú
isinstanceÚnumbersÚNumberrN   r-   Úviewr%   ÚndarrayrQ   r2   rI   Ú__mul__©r   r3   Únew_physical_unitrT   rJ   r   r    r`   ,  s
    zLogQuantity.__mul__c                 C   s
   |   |¡S r   )r`   r9   r   r   r    Ú__rmul__7  s    zLogQuantity.__rmul__c                    sL   t |tjƒr<| jj| }| j}||9 }|  | j |¡¡ | S tƒ  	|¡S d S r   )
r[   r\   r]   rN   r-   rO   rV   r2   rI   Ú__imul__©r   r3   rb   rX   rJ   r   r    rd   :  s    zLogQuantity.__imul__c                    sP   t |tjƒr@| jjd|  }|  tj¡| }|  || j 	|¡¡S t
ƒ  |¡S d S r7   )r[   r\   r]   rN   r-   r^   r%   r_   rQ   r2   rI   Ú__truediv__ra   rJ   r   r    rf   D  s
    zLogQuantity.__truediv__c                    sP   t |tjƒr@| jjd|  }| j}|| }|  | j |¡¡ | S tƒ  	|¡S d S r7   )
r[   r\   r]   rN   r-   rO   rV   r2   rI   Ú__itruediv__re   rJ   r   r    rg   O  s    zLogQuantity.__itruediv__c                 C   sL   zt |ƒ}W n tk
r$   t Y S X | j| }|  tj¡| }|  ||¡S r   )ÚfloatÚ	TypeErrorr1   rN   r^   r%   r_   rQ   )r   r3   rS   Ú	new_valuer   r   r    Ú__pow__Y  s    

zLogQuantity.__pow__c                 C   sÊ   zt |ƒ}W n tk
r$   t Y S X t|| jƒs6tS z| jj |j¡}W nP tk
rš   z|  	|¡}W n tk
r„   t Y  Y S X ||  
tj¡d< Y n"X |  
tj¡d  | j |¡7  < |  |¡ | S )N.)r   r   r1   r[   Ú_unit_classrN   r-   r/   r   Z	_to_valuer^   r%   r_   r)   rV   )r   r3   ÚfactorÚvaluer   r   r    Ú__ilshift__c  s"    
 
zLogQuantity.__ilshift__Nr   c                 C   s$   | j jd }| jtj|||||d�S )Né   ©ÚoutÚddofrN   )rN   r,   Ú_wrap_functionr%   Úvar©r   ÚaxisZdtyperr   rs   rN   r   r   r    ru     s    zLogQuantity.varc                 C   s$   | j  t¡}| jtj|||||d�S )Nrq   )rN   r2   r   rt   r%   Ústdrv   r   r   r    rx   ƒ  s    zLogQuantity.stdc                 C   s    | j  t¡}| jtj|||d�S )N)rr   rN   )rN   r2   r   rt   r%   Úptp)r   rw   rr   rN   r   r   r    ry   ‡  s    zLogQuantity.ptpr	   r5   c                 C   s    | j  t¡}| jtj|||d�S ©N)rN   )rN   r2   r   rt   r%   Údiff)r   Únrw   rN   r   r   r    r{   ‹  s    zLogQuantity.diffc                 C   s    | j  t¡}| jtj|||d�S rz   )rN   r2   r   rt   r%   Úediff1d)r   Zto_endZto_beginrN   r   r   r    r}   �  s    zLogQuantity.ediff1dc                 C   s   h | ]}t t|ƒ’qS r   )r.   r%   )Ú.0Úfunctionr   r   r    Ú	<setcomp>“  s    zLogQuantity.<setcomp>)ru   rx   ry   r{   r}   )NNNr   )NNNr   )NN)r	   r5   )NN)r>   r?   r@   rA   r   rl   r:   r;   rY   r<   r=   rZ   r`   rc   rd   rf   rg   rk   ro   ru   rx   ry   r{   r}   r
   Z_supported_functionsrL   r   r   rJ   r    r   Ï   s.   .	








ÿc                   @   s   e Zd ZeZdS )r   N)r>   r?   r@   r   rl   r   r   r   r    r   ˜  s   c                   @   s   e Zd ZeZdS )r   N)r>   r?   r@   r   rl   r   r   r   r    r   œ  s   c                   @   s   e Zd ZeZdS )r   N)r>   r?   r@   r   rl   r   r   r   r    r      s   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%   Zastropy.unitsr   r   r   r   r   r   r   Úcorer
   r   Zunitsr   r   r   Ú__all__r   r   r   r   r   r   r   r   Z_function_unit_classZSTfluxr   rA   ZABfluxr   ZBolr   ÚsiZbolr   r   r   r   r    Ú<module>   sN   $
ô^  J


ÿ
ÿ