ó
›ßÈ[c           @` s¨   d  d l  m Z m Z 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 l m Z d  d d	 d
 d d d d d d d d „ Z d d „ Z d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   LooseVersioni   (   t   simple_normi   (   t   log(   t   getdatau   linearg      ð?gš™™™™™¹?u   Greys_rc         C` s  d d l  } d d l j } d d l j } y t | ƒ } Wn t k
 rM n Xy t |  | ƒ } Wn! t k
 r„ } t	 j
 | ƒ d SX| j d k r­ t	 j
 d j | ƒ ƒ n  | d k rt j j |  ƒ d } | j d ƒ r÷ t j j | ƒ d } n  | d 7} n  t j j | ƒ d d } | j ƒ  d k rat | j ƒ t d	 ƒ k ra| d d d
 … } n  | | j k rŠt	 j
 d j | ƒ ƒ d St | d | d | d | d | d | d | d |	 d |
 ƒ} | j | | | ƒ d | d d d | ƒt	 j d j | ƒ ƒ d S(   uù	  
    Create a bitmap file from a FITS image, applying a stretching
    transform between minimum and maximum cut levels and a matplotlib
    colormap.

    Parameters
    ----------
    filename : str
        The filename of the FITS file.
    ext : int
        FITS extension name or number of the image to convert.  The
        default is 0.
    out_fn : str
        The filename of the output bitmap image.  The type of bitmap
        is determined by the filename extension (e.g. '.jpg', '.png').
        The default is a PNG file with the same name as the FITS file.
    stretch : {{'linear', 'sqrt', 'power', log', 'asinh'}}
        The stretching 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.
    cmap : str
        The matplotlib color map name.  The default is 'Greys_r'.
    i    Ni   i   u,   data in FITS extension {0} is not a 2D arrayu   .fitsu   .pngu   pngu   2.0.0iÿÿÿÿu,   {0} is not a valid matplotlib colormap name.t   stretcht   powert   asinh_at   min_cutt   max_cutt   min_percentt   max_percentt   percentt   cmapt   originu   lowert   formatu   Saved file to {0}.(   t
   matplotlibt   matplotlib.cmt   cmt   matplotlib.imaget   imaget   intt
   ValueErrorR   t	   ExceptionR   t   criticalt   ndimR   t   Nonet   ost   patht   splitextt   endswitht   lowerR   t   __version__t   datadR   t   imsavet   info(   t   filenamet   extt   out_fnR   R	   R
   R   R   R   R   R   R   R   R   t   mimgR   t   et
   out_formatt   norm(    (    sH   lib/python2.7/site-packages/astropy/visualization/scripts/fits2bitmap.pyt   fits2bitmap   sF    ;
	!c         C` s/  d d  l  } | j d d ƒ } | j d d d d d d d	 d
 ƒ| j d d d d t d d  d	 d ƒ| j d d t d d d	 d ƒ| j d d t d d d	 d ƒ| j d d t d d d	 d ƒ| j d d t d d  d	 d ƒ| j d d t d d  d	 d ƒ| j d d t d d  d	 d ƒ| j d d t d d  d	 d ƒ| j d  d t d d  d	 d! ƒ| j d" d d# d t d d$ d	 d% ƒ| j d d& d' d	 d( ƒ| j |  ƒ }  x~ |  j D]s } t | d) |  j	 d* |  j
 d+ |  j d, |  j d- |  j d. |  j d/ |  j d0 |  j d1 |  j d2 |  j d3 |  j ƒq´Wd  S(4   Ni    t   descriptionu'   Create a bitmap file from a FITS image.u   -eu   --extt   metavaru   hdut   defaultt   helpu8   Specify the HDU extension number or name (Default is 0).u   -ou   filenamet   typeuZ   Filename for the output image (Default is a PNG file with the same name as the FITS file).u	   --stretchu   linearu^   Type of image stretching ("linear", "sqrt", "power", "log", or "asinh") (Default is "linear").u   --powerg      ð?u4   Power index for "power" stretching (Default is 1.0).u	   --asinh_agš™™™™™¹?u•   The value in normalized image where the asinh curve transitions from linear to logarithmic behavior (used only for "asinh" stretch) (Default is 0.1).u	   --min_cutuH   The pixel value of the minimum cut level (Default is the image minimum).u	   --max_cutuH   The pixel value of the maximum cut level (Default is the image maximum).u   --min_percentuL   The percentile value used to determine the minimum cut level (Default is 0).u   --max_percentuN   The percentile value used to determine the maximum cut level (Default is 100).u	   --percentu}   The percentage of the image values used to determine the pixel values of the minimum and maximum cut levels (Default is 100).u   --cmapu   colormap_nameu   Greys_ru1   matplotlib color map name (Default is "Greys_r").t   nargsu   +u)   Path to one or more FITS files to convertR(   R)   R   R   R   R   R   R   R	   R
   R   (   t   argparset   ArgumentParsert   add_argumentt   strR   t   floatt
   parse_argsR'   R.   R(   t   oR   R   R   R   R   R   R	   R
   R   (   t   argsR5   t   parserR'   (    (    sH   lib/python2.7/site-packages/astropy/visualization/scripts/fits2bitmap.pyt   main{   sD    		(   t
   __future__R    R   R   R   R   t   distutils.versionR   t   mpl_normalizeR   t    R   t   io.fitsR   R   R.   R>   (    (    (    sH   lib/python2.7/site-packages/astropy/visualization/scripts/fits2bitmap.pyt   <module>   s   "		k