ó
›ßÈ[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 m	 Z	 m
 Z
 m Z m Z d d l m Z m Z m Z m Z m Z m Z yK d d l Z d d l m Z e e e ƒ sØ d	 e e f d
 „  ƒ  YZ n  Wn' e k
 rd	 e f d „  ƒ  YZ n Xd d g Z i d g d 6Z d e f d „  ƒ  YZ d d d d d d d d e d „	 Z  d S(   sK   
Normalization class for Matplotlib that can be used to produce
colorbars.
iÿÿÿÿ(   t   divisiont   print_functionN(   t   mai   (   t   PercentileIntervalt   AsymmetricPercentileIntervalt   ManualIntervalt   MinMaxIntervalt   BaseInterval(   t   LinearStretcht   SqrtStretcht   PowerStretcht
   LogStretcht   AsinhStretcht   BaseStretch(   t	   NormalizeR   c           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sB   lib/python2.7/site-packages/astropy/visualization/mpl_normalize.pyR      s   c           B  s   e  Z d  „  Z RS(   c         O  s   t  d ƒ ‚ d  S(   Ns2   matplotlib is required in order to use this class.(   t   ImportError(   t   selft   argst   kwargs(    (    sB   lib/python2.7/site-packages/astropy/visualization/mpl_normalize.pyt   __init__   s    (   R   R   R   (    (    (    sB   lib/python2.7/site-packages/astropy/visualization/mpl_normalize.pyR      s   t   ImageNormalizet   simple_normt
   matplotlibt   *c           B  sA   e  Z d  Z d d d d e ƒ  e d „ Z d d „ Z d „  Z RS(   s÷  
    Normalization class to be used with Matplotlib.

    Parameters
    ----------
    data : `~numpy.ndarray`, optional
        The image array.  This input is used only if ``interval`` is
        also input.  ``data`` and ``interval`` are used to compute the
        vmin and/or vmax values only if ``vmin`` or ``vmax`` are not
        input.
    interval : `~astropy.visualization.BaseInterval` subclass instance, optional
        The interval object to apply to the input ``data`` to determine
        the ``vmin`` and ``vmax`` values.  This input is used only if
        ``data`` is also input.  ``data`` and ``interval`` are used to
        compute the vmin and/or vmax values only if ``vmin`` or ``vmax``
        are not input.
    vmin, vmax : float
        The minimum and maximum levels to show for the data.  The
        ``vmin`` and ``vmax`` inputs override any calculated values from
        the ``interval`` and ``data`` inputs.
    stretch : `~astropy.visualization.BaseStretch` subclass instance, optional
        The stretch object to apply to the data.  The default is
        `~astropy.visualization.LinearStretch`.
    clip : bool, optional
        If `True` (default), data values outside the [0:1] range are
        clipped to the [0:1] range.
    c   	      C  s  t  t |  ƒ j d | d | d | ƒ | |  _ | |  _ | d  k	 r | d  k	 r | j | ƒ \ } } |  j d  k r | |  _ n  |  j d  k r | |  _ q n  | d  k	 rÈ t | t ƒ rÈ t	 d ƒ ‚ n  | |  _
 | d  k	 rü t | t ƒ rü t	 d ƒ ‚ n  | |  _ | j |  _ | |  _ d  S(   Nt   vmint   vmaxt   clips5   stretch must be an instance of a BaseStretch subclasss7   interval must be an instance of a BaseInterval subclass(   t   superR   R   R   R   t   Nonet
   get_limitst
   isinstanceR   t	   TypeErrort   stretchR   t   intervalt   inverset   inverse_stretchR   (	   R   t   dataR#   R   R   R"   R   t   _vmint   _vmax(    (    sB   lib/python2.7/site-packages/astropy/visualization/mpl_normalize.pyR   A   s"    %				c         C  s=  | d  k r |  j } n  t | t j ƒ rW | r9 t } n	 | j } | j |  j ƒ } n t } t	 j
 | ƒ r‡ t	 j | g d t ƒ} n t	 j | d t d t ƒ} |  j | ƒ t	 j | |  j d | ƒt	 j | |  j |  j d | ƒ|  j rt	 j | d d d | ƒ} n  |  j | d | d t ƒ} t j | d | ƒS(   Nt   dtypet   copyt   outg        g      ð?R   t   mask(   R   R   R    R   t   MaskedArrayt   FalseR,   t   filledR   t   npt   isscalart   arrayt   floatt   Truet   autoscale_Nonet   subtractR   t   true_divideR"   (   R   t   valuesR   R,   (    (    sB   lib/python2.7/site-packages/astropy/visualization/mpl_normalize.pyt   __call__\   s$    		 	c         C  s.   |  j  | d t ƒ} | |  j |  j |  j S(   NR   (   R%   R.   R   R   (   R   R8   t   values_norm(    (    sB   lib/python2.7/site-packages/astropy/visualization/mpl_normalize.pyR$      s    N(	   R   R   t   __doc__R   R   R.   R   R9   R$   (    (    (    sB   lib/python2.7/site-packages/astropy/visualization/mpl_normalize.pyR   $   s
   %t   linearg      ð?gš™™™™™¹?c
      	   C  sK  | d k	 r t | ƒ }
 ni | d k	 s3 | d k	 rQ t | p? d | pH d ƒ }
 n3 | d k	 si | d k	 r{ t | | ƒ }
 n	 t ƒ  }
 | d k rœ t ƒ  } n{ | d k r´ t ƒ  } nc | d k rÏ t | ƒ } nH | d k rç t ƒ  } n0 | d k rt	 | ƒ } n t
 d j | ƒ ƒ ‚ |
 j |  ƒ \ } } t d	 | d
 | d | d |	 ƒ S(   s?
  
    Return a Normalization class that can be used for displaying images
    with Matplotlib.

    This function enables only a subset of image stretching functions
    available in `~astropy.visualization.mpl_normalize.ImageNormalize`.

    This function is used by the
    ``astropy.visualization.scripts.fits2bitmap`` script.

    Parameters
    ----------
    data : `~numpy.ndarray`
        The image array.

    stretch : {'linear', 'sqrt', 'power', log', 'asinh'}, optional
        The stretch function to apply to the image.  The default is
        'linear'.

    power : float, optional
        The power index for ``stretch='power'``.  The default is 1.0.

    asinh_a : float, optional
        For ``stretch='asinh'``, the value 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.  The default is 0.1.

    min_cut : float, optional
        The pixel value of the minimum cut level.  Data values less than
        ``min_cut`` will set to ``min_cut`` before stretching the image.
        The default is the image minimum.  ``min_cut`` overrides
        ``min_percent``.

    max_cut : float, optional
        The pixel value of the maximum cut level.  Data values greater
        than ``min_cut`` will set to ``min_cut`` before stretching the
        image.  The default is the image maximum.  ``max_cut`` overrides
        ``max_percent``.

    min_percent : float, optional
        The percentile value used to determine the pixel value of
        minimum cut level.  The default is 0.0.  ``min_percent``
        overrides ``percent``.

    max_percent : float, optional
        The percentile value used to determine the pixel value of
        maximum cut level.  The default is 100.0.  ``max_percent``
        overrides ``percent``.

    percent : float, optional
        The percentage of the image values used to determine the pixel
        values of the minimum and maximum cut levels.  The lower cut
        level will set at the ``(100 - percent) / 2`` percentile, while
        the upper cut level will be set at the ``(100 + percent) / 2``
        percentile.  The default is 100.0.  ``percent`` is ignored if
        either ``min_percent`` or ``max_percent`` is input.

    clip : bool, optional
        If `True` (default), data values outside the [0:1] range are
        clipped to the [0:1] range.

    Returns
    -------
    result : `ImageNormalize` instance
        An `ImageNormalize` instance that can be used for displaying
        images with Matplotlib.
    g        g      Y@R<   t   sqrtt   powert   logt   asinhs   Unknown stretch: {0}.R   R   R"   R   N(   R   R   R   R   R   R   R	   R
   R   R   t
   ValueErrort   formatR   R   (   R&   R"   R>   t   asinh_at   min_cutt   max_cutt   min_percentt   max_percentt   percentR   R#   R   R   (    (    sB   lib/python2.7/site-packages/astropy/visualization/mpl_normalize.pyR   ‰   s*    H	(!   R;   t
   __future__R    R   t   numpyR0   R   R#   R   R   R   R   R   R"   R   R	   R
   R   R   R   R   t   matplotlib.colorsR   R    t   typet   objectR   t   __all__t   __doctest_requires__R   R   R4   R   (    (    (    sB   lib/python2.7/site-packages/astropy/visualization/mpl_normalize.pyt   <module>   s$   (. e	