B
    q\/                 @   sJ  d dl Zd dl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
UnitsErrordimensionless_unscaledphotometric   )FunctionUnitBaseFunctionQuantity)dexdB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 `MagUnit`, `DecibelUnit`, and `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   Alib/python3.7/site-packages/astropy/units/function/logarithmic.py_default_function_unit    s    zLogUnit._default_function_unitc             C   s   t S )N)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npZ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   r   to_physical-   s    zLogUnit.to_physicalc             C   st   yt |d|| j W n. tk
r,   tS  tk
rF   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 ofof compatible type.physical_unitr   )
getattrZ_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_unit5   s    

z%LogUnit._add_and_adjust_physical_unitc             C   s   |  | jd S )N)r)   r%   )r   r   r   r   __neg__V   s    zLogUnit.__neg__c             C   s   |  |ddS )Nr   )r+   )r   r*   r   r   r   __add__Y   s    zLogUnit.__add__c             C   s   |  |ddS )Nr   )r+   )r   r*   r   r   r   __radd__^   s    zLogUnit.__radd__c             C   s   |  |ddS )Nr   r,   )r+   )r   r*   r   r   r   __sub__a   s    zLogUnit.__sub__c             C   s   |  |ddS )Nr,   r   )r+   )r   r*   r   r   r   __rsub__d   s    zLogUnit.__rsub__N)__name__
__module____qualname____doc__propertyr   r   r!   r#   r+   r-   r.   r/   r0   r1   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 )N)r   )r   r   r   r   r   w   s    zMagUnit._default_function_unitc             C   s   t S )N)r   )r   r   r   r   r   {   s    zMagUnit._quantity_classN)r2   r3   r4   r5   r6   r   r   r   r   r   r   r   j   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 ``dex`, but this allows one to use an equivalent
        unit such as ``0.5 dex``.
    c             C   s   t S )N)r	   )r   r   r   r   r      s    zDexUnit._default_function_unitc             C   s   t S )N)r   )r   r   r   r   r      s    zDexUnit._quantity_classN)r2   r3   r4   r5   r6   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 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 )N)r
   )r   r   r   r   r      s    z"DecibelUnit._default_function_unitc             C   s   t S )N)r   )r   r   r   r   r      s    zDecibelUnit._quantity_classN)r2   r3   r4   r5   r6   r   r   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dddZd ddZd!ddZd"ddZd#ddZejedd dD B ZdS )$r   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 convertible items.
        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 : string, `~astropy.units.UnitBase` or `~astropy.units.function.FunctionUnitBase` instance, optional
        For an `~astropy.units.function.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.function.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)r7   r&   r   r8   	_new_view)r   r*   new_unitresultr   r   r   r.      s    zLogQuantity.__add__c             C   s
   |  |S )N)r.   )r   r*   r   r   r   r/      s    zLogQuantity.__radd__c             C   s6   | j t|dt }| j}|t|d|7 }| | | S )Nr7   r8   )r7   r&   r   r8   	_set_unit)r   r*   r:   function_viewr   r   r   __iadd__   s
    
zLogQuantity.__iadd__c             C   s0   | j t|dt }| jt|d| }| ||S )Nr7   r8   )r7   r&   r   r8   r9   )r   r*   r:   r;   r   r   r   r0      s    zLogQuantity.__sub__c             C   s@   | j t|dt}| jt|d|}||j}| ||S )Nr7   r8   )r7   r1   r&   r   r8   r   r$   r9   )r   r*   r:   r;   r   r   r   r1      s    zLogQuantity.__rsub__c             C   s6   | j t|dt }| j}|t|d|8 }| | | S )Nr7   r8   )r7   r&   r   r8   r<   )r   r*   r:   r=   r   r   r   __isub__  s
    
zLogQuantity.__isub__Nr   c             C   s    | j tj||||| jjd dS )N   )outddofr7   )_wrap_functionr   varr7   r$   )r   axisdtyperA   rB   r   r   r   rD     s    zLogQuantity.varc          	   C   s    | j tj||||| jtdS )N)rA   rB   r7   )rC   r   stdr7   r)   r   )r   rE   rF   rA   rB   r   r   r   rG     s    zLogQuantity.stdc             C   s   | j tj||| jtdS )N)rA   r7   )rC   r   ptpr7   r)   r   )r   rE   rA   r   r   r   rH     s    zLogQuantity.ptpr   r,   c             C   s   | j tj||| jtdS )N)r7   )rC   r   diffr7   r)   r   )r   nrE   r   r   r   rI     s    zLogQuantity.diffc             C   s   | j tj||| jtdS )N)r7   )rC   r   ediff1dr7   r)   r   )r   Zto_endZto_beginr   r   r   rK   "  s    zLogQuantity.ediff1dc             c   s   | ]}t t|V  qd S )N)r&   r   ).0Zfunctionr   r   r   	<genexpr>'  s    zLogQuantity.<genexpr>)rD   rG   rH   rI   rK   )NNNr   )NNNr   )NN)r   r,   )NN)r2   r3   r4   r5   r   _unit_classr.   r/   r>   r0   r1   r?   rD   rG   rH   rI   rK   r   Z_supported_functionssetr   r   r   r   r      s    ,	





c               @   s   e Zd ZeZdS )r   N)r2   r3   r4   r   rN   r   r   r   r   r   +  s   c               @   s   e Zd ZeZdS )r   N)r2   r3   r4   r   rN   r   r   r   r   r   /  s   c               @   s   e Zd ZeZdS )r   N)r2   r3   r4   r   rN   r   r   r   r   r   3  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={0}z@Apparent bolometric magnitude: m_bol=0 corresponds to f_bol0={0})#Znumpyr   Zastropy.unitsr   r   r   r   Zcorer   r   Zunitsr	   r
   r   __all__r   r   r   r   r   r   r   r   Z_function_unit_classZSTfluxr   r5   ZABfluxr   ZBolr   formatZsiZbolr   r   r   r   r   <module>   s6   [}



