B
    Afxa                 @   sZ   d Z ddlmZmZmZ G dd dZG dd deZG dd deZG d	d
 d
eZdS )z
    pint.converters
    ~~~~~~~~~~~~~~~

    Functions and classes related to unit conversions.

    :copyright: 2016 by Pint Authors, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
   )	HAS_NUMPYexplogc               @   s<   e Zd ZdZedd Zedd ZdddZdd	d
ZdS )	Converterz Base class for value converters.c             C   s   dS )NT )selfr   r   .lib/python3.7/site-packages/pint/converters.pyis_multiplicative   s    zConverter.is_multiplicativec             C   s   dS )NFr   )r   r   r   r   is_logarithmic   s    zConverter.is_logarithmicFc             C   s   |S )Nr   )r   valueinplacer   r   r   to_reference   s    zConverter.to_referencec             C   s   |S )Nr   )r   r   r   r   r   r   from_reference   s    zConverter.from_referenceN)F)F)	__name__
__module____qualname____doc__propertyr	   r
   r   r   r   r   r   r   r      s
   
r   c               @   s,   e Zd ZdZdd Zd
ddZdddZd	S )ScaleConverterzA linear transformation.c             C   s
   || _ d S )N)scale)r   r   r   r   r   __init__$   s    zScaleConverter.__init__Fc             C   s   |r|| j 9 }n
|| j  }|S )N)r   )r   r   r   r   r   r   r   '   s    
zScaleConverter.to_referencec             C   s   |r|| j  }n
|| j  }|S )N)r   )r   r   r   r   r   r   r   /   s    
zScaleConverter.from_referenceN)F)F)r   r   r   r   r   r   r   r   r   r   r   r   !   s   
r   c               @   s8   e Zd ZdZdd Zedd ZdddZdd	d
ZdS )OffsetConverterzAn affine transformation.c             C   s   || _ || _d S )N)r   offset)r   r   r   r   r   r   r   ;   s    zOffsetConverter.__init__c             C   s
   | j dkS )N    )r   )r   r   r   r   r	   ?   s    z!OffsetConverter.is_multiplicativeFc             C   s.   |r|| j 9 }|| j7 }n|| j  | j }|S )N)r   r   )r   r   r   r   r   r   r   C   s
    
zOffsetConverter.to_referencec             C   s.   |r|| j 8 }|| j }n|| j  | j }|S )N)r   r   )r   r   r   r   r   r   r   L   s
    
zOffsetConverter.from_referenceN)F)F)	r   r   r   r   r   r   r	   r   r   r   r   r   r   r   8   s
   
	r   c               @   sD   e Zd ZdZdd Zedd Zedd Zdd	d
ZdddZ	dS )LogarithmicConvertera  Converts between linear units and logarithmic units, such as dB, octave, neper or pH.
    Q_log = logfactor * log( Q_lin / scale ) / log(log_base)

    Parameters
    ----------
    scale : float
        unit of reference at denominator for logarithmic unit conversion
    logbase : float
        base of logarithm used in the logarithmic unit conversion
    logfactor : float
        factor multiplied to logarithm for unit conversion
    inplace : bool
        controls if computation is done in place
    c             C   s   || _ || _|| _dS )a<  
        Parameters
        ----------
        scale : float
            unit of reference at denominator inside logarithm for unit conversion
        logbase: float
            base of logarithm used in unit conversion
        logfactor: float
            factor multiplied to logarithm for unit conversion
        N)r   logbase	logfactor)r   r   r   r   r   r   r   r   f   s    zLogarithmicConverter.__init__c             C   s   dS )NFr   )r   r   r   r   r	   v   s    z&LogarithmicConverter.is_multiplicativec             C   s   dS )NTr   )r   r   r   r   r
   z   s    z#LogarithmicConverter.is_logarithmicFc             C   s^   |r<|| j  }trt|| nt|}|| jt| j 9 }n| jt|| j   t| j }|S )zConverts value from the reference unit to the logarithmic unit

        dBm   <------   mW
        y dBm = 10 log10( x / 1mW )
        )r   r   r   r   r   )r   r   r   r   r   r   r   ~   s    
z#LogarithmicConverter.from_referencec             C   sb   |r@|| j  }|t| j9 }tr,t|| nt|}|| j9 }n| jtt| j|| j    }|S )zConverts value to the reference unit from the logarithmic unit

        dBm   ------>   mW
        y dBm = 10 log10( x / 1mW )
        )r   r   r   r   r   r   )r   r   r   r   r   r   r      s    
z!LogarithmicConverter.to_referenceN)F)F)
r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   V   s   
r   N)	r   compatr   r   r   r   r   r   r   r   r   r   r   <module>	   s
   