ó
›ßÈ[c           @  s÷  d  Z  d d l m Z m Z d d l Z d d l m Z d d l m	 Z	 d d l
 m Z d	 d
 d d d d d d d d d g Z d d „ Z e d d „ Z e j e	 ƒ d	 e f d „  ƒ  Yƒ Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d  „  ƒ  YZ d e f d! „  ƒ  YZ d e f d" „  ƒ  YZ d e f d# „  ƒ  YZ d$ e f d% „  ƒ  YZ d e f d& „  ƒ  YZ d' e f d( „  ƒ  YZ  d S()   s€   
Classes that deal with stretching, i.e. mapping a range of [0:1] values onto
another set of [0:1] values with a transformation
iÿÿÿÿ(   t   divisiont   print_functionNi   (   t   six(   t   InheritDocstringsi   (   t   BaseTransformt   BaseStretcht   LinearStretcht   SqrtStretcht   PowerStretcht   PowerDistStretcht   SquaredStretcht
   LogStretcht   AsinhStretcht   SinhStretcht   HistEqStretcht   ContrastBiasStretchc         C  s`   | d k r& t j | ƒ t j |  ƒ St j | d | ƒt j | t j |  ƒ d | ƒ| Sd S(   s   Calculate the log base n of x.t   outN(   t   Nonet   npt   logt   true_divide(   t   nt   xR   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyt   _logn   s
    c         C  sV   | r t  j |  d d d | ƒS| d k r> t  j |  d t ƒSt  j |  ƒ | (| Sd S(   s“   
    Prepare the data by optionally clipping and copying, and return the
    array that should be subsequently used for in-place calculations.
    g        g      ð?R   t   copyN(   R   t   clipR   t   arrayt   Truet   asarray(   t   valuesR   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyt   _prepare!   s    c           B  s,   e  Z d  Z e d d „ Z e d „  ƒ Z RS(   s´   
    Base class for the stretch classes, which, when called with an array
    of values in the range [0:1], return an transformed array of values,
    also in the range [0:1].
    c         C  s   d S(   su  
        Transform values using this stretch.

        Parameters
        ----------
        values : array-like
            The input values, which should already be normalized to the
            [0:1] range.
        clip : bool, optional
            If `True` (default), values outside the [0:1] range are
            clipped to the [0:1] range.
        out : `~numpy.ndarray`, optional
            If specified, the output values will be placed in this array
            (typically used for in-place calculations).

        Returns
        -------
        result : `~numpy.ndarray`
            The transformed values.
        N(    (   t   selfR   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyt   __call__9   s    c         C  s   d S(   s5   A stretch object that performs the inverse operation.N(    (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyt   inverseO   s    N(   t   __name__t
   __module__t   __doc__R   R   R    t   propertyR!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR   1   s   c           B  s,   e  Z d  Z e d d „ Z e d „  ƒ Z RS(   sV   
    A linear stretch.

    The stretch is given by:

    .. math::
        y = x
    c         C  s   t  | d | d | ƒS(   NR   R   (   R   (   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR    ^   s    c         C  s   t  ƒ  S(   s5   A stretch object that performs the inverse operation.(   R   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   a   s    N(   R"   R#   R$   R   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR   T   s   c           B  s,   e  Z d  Z e d d „ Z e d „  ƒ Z RS(   sb   
    A square root stretch.

    The stretch is given by:

    .. math::
        y = \sqrt{x}
    c         C  s/   t  | d | d | ƒ} t j | d | ƒ| S(   NR   R   (   R   R   t   sqrt(   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR    q   s    c         C  s
   t  d ƒ S(   s5   A stretch object that performs the inverse operation.i   (   R   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   v   s    N(   R"   R#   R$   R   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR   g   s   c           B  s5   e  Z d  Z d „  Z e d d „ Z e d „  ƒ Z RS(   sµ   
    A power stretch.

    The stretch is given by:

    .. math::
        y = x^a

    Parameters
    ----------
    a : float
        The power index (see the above formula).
    c         C  s    t  t |  ƒ j ƒ  | |  _ d  S(   N(   t   superR   t   __init__t   power(   R   t   a(    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(   ‹   s    c         C  s5   t  | d | d | ƒ} t j | |  j d | ƒ| S(   NR   R   (   R   R   R)   (   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR       s    c         C  s   t  d |  j ƒ S(   s5   A stretch object that performs the inverse operation.g      ð?(   R   R)   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   ”   s    N(	   R"   R#   R$   R(   R   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR   |   s   	c           B  s8   e  Z d  Z d d „ Z e d d „ Z e d „  ƒ Z RS(   s  
    An alternative power stretch.

    The stretch is given by:

    .. math::
        y = \frac{a^x - 1}{a - 1}

    Parameters
    ----------
    a : float, optional
        The ``a`` parameter used in the above formula.  Default is 1000.
        ``a`` cannot be set to 1.
    g     @@c         C  s;   | d k r t  d ƒ ‚ n  t t |  ƒ j ƒ  | |  _ d  S(   Ni   s   a cannot be set to 1(   t
   ValueErrorR'   R	   R(   t   exp(   R   R*   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(   ª   s    c         C  sh   t  | d | d | ƒ} t j |  j | d | ƒt j | d d | ƒt j | |  j d d | ƒ| S(   NR   R   i   g      ð?(   R   R   R)   R,   t   subtractR   (   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR    °   s
    c         C  s   t  d |  j ƒ S(   s5   A stretch object that performs the inverse operation.R*   (   t   InvertedPowerDistStretchR,   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   ·   s    N(	   R"   R#   R$   R(   R   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR	   š   s   R.   c           B  s8   e  Z d  Z d d „ Z e d d „ Z e d „  ƒ Z RS(   sO  
    Inverse transformation for
    `~astropy.image.scaling.PowerDistStretch`.

    The stretch is given by:

    .. math::
        y = \frac{\log(y (a-1) + 1)}{\log a}

    Parameters
    ----------
    a : float, optional
        The ``a`` parameter used in the above formula.  Default is 1000.
        ``a`` cannot be set to 1.
    g     @@c         C  s;   | d k r t  d ƒ ‚ n  t t |  ƒ j ƒ  | |  _ d  S(   Ni   s   a cannot be set to 1(   R+   R'   R.   R(   R,   (   R   R*   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(   Î   s    c         C  se   t  | d | d | ƒ} t j | |  j d d | ƒt j | d d | ƒt |  j | d | ƒ| S(   NR   R   g      ð?i   (   R   R   t   multiplyR,   t   addR   (   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR    Ô   s
    c         C  s   t  d |  j ƒ S(   s5   A stretch object that performs the inverse operation.R*   (   R	   R,   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   Û   s    N(	   R"   R#   R$   R(   R   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR.   ½   s   c           B  s&   e  Z d  Z d „  Z e d „  ƒ Z RS(   st   
    A convenience class for a power stretch of 2.

    The stretch is given by:

    .. math::
        y = x^2
    c         C  s   t  t |  ƒ j d ƒ d  S(   Ni   (   R'   R
   R(   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(   ë   s    c         C  s   t  ƒ  S(   s5   A stretch object that performs the inverse operation.(   R   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   î   s    (   R"   R#   R$   R(   R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR
   á   s   	c           B  s8   e  Z d  Z d d „ Z e d d „ Z e d „  ƒ Z RS(   sî   
    A log stretch.

    The stretch is given by:

    .. math::
        y = \frac{\log{(a x + 1)}}{\log{(a + 1)}}.

    Parameters
    ----------
    a : float
        The ``a`` parameter used in the above formula.  Default is 1000.
    g     @@c         C  s    t  t |  ƒ j ƒ  | |  _ d  S(   N(   R'   R   R(   R,   (   R   R*   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(     s    c         C  s„   t  | d | d | ƒ} t j | |  j d | ƒt j | d d | ƒt j | d | ƒt j | t j |  j d ƒ d | ƒ| S(   NR   R   g      ð?(   R   R   R/   R,   R0   R   R   (   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR      s    &c         C  s   t  |  j ƒ S(   s5   A stretch object that performs the inverse operation.(   t   InvertedLogStretchR,   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!     s    N(	   R"   R#   R$   R(   R   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR   ô   s   R1   c           B  s5   e  Z d  Z d „  Z e d d „ Z e d „  ƒ Z RS(   s  
    Inverse transformation for `~astropy.image.scaling.LogStretch`.

    The stretch is given by:

    .. math::
        y = \frac{e^{y} (a + 1) -1}{a}

    Parameters
    ----------
    a : float, optional
        The ``a`` parameter used in the above formula.  Default is 1000.
    c         C  s    t  t |  ƒ j ƒ  | |  _ d  S(   N(   R'   R1   R(   R,   (   R   R*   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(   $  s    c         C  s„   t  | d | d | ƒ} t j | t j |  j d ƒ d | ƒt j | d | ƒt j | d d | ƒt j | |  j d | ƒ| S(   NR   R   g      ð?(   R   R   R/   R   R,   R-   R   (   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR    (  s    &c         C  s   t  |  j ƒ S(   s5   A stretch object that performs the inverse operation.(   R   R,   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   0  s    N(	   R"   R#   R$   R(   R   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR1     s   	c           B  s8   e  Z d  Z d d „ Z e d d „ Z e d „  ƒ Z RS(   sß  
    An asinh stretch.

    The stretch is given by:

    .. math::
        y = \frac{{\rm asinh}(x / a)}{{\rm asinh}(1 / a)}.

    Parameters
    ----------
    a : float, optional
        The ``a`` parameter used in the above formula.  The value of
        this parameter is where the asinh curve transitions from linear
        to logarithmic behavior, expressed as a fraction of the
        normalized image.  Must be in the range between 0 and 1.
        Default is 0.1
    gš™™™™™¹?c         C  s    t  t |  ƒ j ƒ  | |  _ d  S(   N(   R'   R   R(   R*   (   R   R*   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(   I  s    c         C  sn   t  | d | d | ƒ} t j | |  j d | ƒt j | d | ƒt j | t j d |  j ƒ d | ƒ| S(   NR   R   g      ð?(   R   R   R   R*   t   arcsinh(   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR    M  s
    &c         C  s!   t  d d t j d |  j ƒ ƒ S(   s5   A stretch object that performs the inverse operation.R*   g      ð?(   R   R   R2   R*   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   T  s    N(	   R"   R#   R$   R(   R   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR   6  s   c           B  s8   e  Z d  Z d d „ Z e d d „ Z e d „  ƒ Z RS(   sý   
    A sinh stretch.

    The stretch is given by:

    .. math::
        y = \frac{{\rm sinh}(x / a)}{{\rm sinh}(1 / a)}

    Parameters
    ----------
    a : float, optional
        The ``a`` parameter used in the above formula.  Default is 1/3.
    g      ð?g      @c         C  s    t  t |  ƒ j ƒ  | |  _ d  S(   N(   R'   R   R(   R*   (   R   R*   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(   i  s    c         C  sn   t  | d | d | ƒ} t j | |  j d | ƒt j | d | ƒt j | t j d |  j ƒ d | ƒ| S(   NR   R   g      ð?(   R   R   R   R*   t   sinh(   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR    m  s
    &c         C  s!   t  d d t j d |  j ƒ ƒ S(   s5   A stretch object that performs the inverse operation.R*   g      ð?(   R   R   R3   R*   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   t  s    gUUUUUUÕ?N(	   R"   R#   R$   R(   R   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR   Z  s   c           B  s8   e  Z d  Z d d „ Z e d d „ Z e d „  ƒ Z RS(   s  
    A histogram equalization stretch.

    Parameters
    ----------
    data : array-like
        The data defining the equalization.
    values : array-like, optional
        The input image values, which should already be normalized to
        the [0:1] range.
    c         C  s‹   t  j | j ƒ  ƒ |  _ |  j j ƒ  } |  j j ƒ  } |  j | | | |  _ | d  k r~ t  j d d t |  j ƒ ƒ |  _	 n	 | |  _	 d  S(   Ng        g      ð?(
   R   t   sortt   ravelt   datat   mint   maxR   t   linspacet   lenR   (   R   R6   R   t   vmint   vmax(    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(   ‡  s    $c         C  s8   t  | d | d | ƒ} t j | |  j |  j ƒ | (| S(   NR   R   (   R   R   t   interpR6   R   (   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR    •  s    c         C  s   t  |  j d |  j ƒS(   s5   A stretch object that performs the inverse operation.R   (   t   InvertedHistEqStretchR6   R   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   š  s    N(	   R"   R#   R$   R   R(   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR   z  s   R>   c           B  s8   e  Z d  Z d d „ Z e d d „ Z e d „  ƒ Z RS(   s.  
    Inverse transformation for `~astropy.image.scaling.HistEqStretch`.

    Parameters
    ----------
    data : array-like
        The data defining the equalization.
    values : array-like, optional
        The input image values, which should already be normalized to
        the [0:1] range.
    c         C  sF   | |  _  | d  k r9 t j d d t |  j  ƒ ƒ |  _ n	 | |  _ d  S(   Ng        g      ð?(   R6   R   R   R9   R:   R   (   R   R6   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(   ­  s    	$c         C  s8   t  | d | d | ƒ} t j | |  j |  j ƒ | (| S(   NR   R   (   R   R   R=   R   R6   (   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR    ´  s    c         C  s   t  |  j d |  j ƒS(   s5   A stretch object that performs the inverse operation.R   (   R   R6   R   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   ¹  s    N(	   R"   R#   R$   R   R(   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR>      s   c           B  s5   e  Z d  Z d „  Z e d d „ Z e d „  ƒ Z RS(   sŒ  
    A stretch that takes into account contrast and bias.

    The stretch is given by:

    .. math::
        y = (x - {\rm bias}) * {\rm contrast} + 0.5

    and the output values are clipped to the [0:1] range.

    Parameters
    ----------
    contrast : float
        The contrast parameter (see the above formula).

    bias : float
        The bias parameter (see the above formula).
    c         C  s)   t  t |  ƒ j ƒ  | |  _ | |  _ d  S(   N(   R'   R   R(   t   contrastt   bias(   R   R?   R@   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(   Ó  s    	c         C  s†   t  | d t d | ƒ} t j | |  j d | ƒt j | |  j d | ƒt j | d d | ƒ| r‚ t j | d d d | ƒn  | S(   NR   R   g      à?i    i   (	   R   t   FalseR   R-   R@   R/   R?   R0   R   (   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR    Ø  s    c         C  s   t  |  j |  j ƒ S(   s5   A stretch object that performs the inverse operation.(   t   InvertedContrastBiasStretchR?   R@   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!   æ  s    N(	   R"   R#   R$   R(   R   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR   ¿  s   	RB   c           B  s5   e  Z d  Z d „  Z e d d „ Z e d „  ƒ Z RS(   s1  
    Inverse transformation for ContrastBiasStretch.

    Parameters
    ----------
    contrast : float
        The contrast parameter (see
        `~astropy.visualization.ConstrastBiasStretch).

    bias : float
        The bias parameter (see
        `~astropy.visualization.ConstrastBiasStretch).
    c         C  s)   t  t |  ƒ j ƒ  | |  _ | |  _ d  S(   N(   R'   RB   R(   R?   R@   (   R   R?   R@   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR(   û  s    	c         C  s†   t  | d t d | ƒ} t j | d d | ƒt j | |  j d | ƒt j | |  j d | ƒ| r‚ t j | d d d | ƒn  | S(   NR   R   g      à?i    i   (	   R   RA   R   R-   R   R?   R0   R@   R   (   R   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR       s    c         C  s   t  |  j |  j ƒ S(   s5   A stretch object that performs the inverse operation.(   R   R?   R@   (   R   (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyR!     s    N(	   R"   R#   R$   R(   R   R   R    R%   R!   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyRB   ì  s   	(!   R$   t
   __future__R    R   t   numpyR   t   externR   t
   utils.miscR   t	   transformR   t   __all__R   R   R   R   t   add_metaclassR   R   R   R   R	   R.   R
   R   R1   R   R   R   R>   R   RB   (    (    (    s<   lib/python2.7/site-packages/astropy/visualization/stretch.pyt   <module>   s4   "#$!!$ &-