
[c           @` s/  d  Z  d d l m Z m Z m Z m Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z d d l m Z d d l m Z m Z d d l m Z y d d l Z e Z Wn e k
 r e Z n Xe Z d d	  Z d
   Z d d  Z d   Z d   Z d   Z d   Z  d e! f d     YZ" d S(   u   
Tests for RGB Images
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   assert_equali   (   t   convolvet   Gaussian2DKerneli   (   t
   lupton_rgbc         C` sL   d d l  j } | j |  d d d d | r> | j |  n  | j   | S(   u<   Display an rgb image using matplotlib (useful for debugging)i    Nt   interpolationu   nearestt   originu   lower(   t   matplotlib.pyplott   pyplott   imshowt   titlet   show(   t   rgbR   t   plt(    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   display_rgb   s    
c         C` s)   |  j    } |  | k } t j | | <| S(   u   
    Return image with all points above satValue set to NaN.

    Simulates saturation on an image, so we can test 'replace_saturated_pixels'
    (   t   copyt   npt   nan(   t   imaget   satValuet   resultt	   saturated(    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   saturate(   s    id   c         C` s#   t  j t  j j d  d d |  S(   Ni
   id   t   dtype(   R   t   arrayt   random(   R   t   N(    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   random_array4   s    c          C` sG   t  t j  }  t j |   } |  j | j k s6 t  t |  |  d  S(   N(   R   R   t   float64R   t   compute_intensityR   t   AssertionErrorR   (   t   image_rt	   intensity(    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_compute_intensity_1_float8   s    c          C` sG   t  t j  }  t j |   } |  j | j k s6 t  t |  |  d  S(   N(   R   R   t   uint8R   R    R   R!   R   (   R"   R#   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_compute_intensity_1_uint?   s    c          C` sw   t  t j  }  t  t j  } t  t j  } t j |  | |  } |  j | j k sZ t  t | |  | | d  d  S(   Ng      @(   R   R   R   R   R    R   R!   R   (   R"   t   image_gt   image_bR#   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_compute_intensity_3_floatF   s    c          C` sw   t  t j  }  t  t j  } t  t j  } t j |  | |  } |  j | j k sZ t  t | |  | | d  d  S(   Ni   (   R   R   R%   R   R    R   R!   R   (   R"   R'   R(   R#   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_compute_intensity_3_uintO   s    t   TestLuptonRgbc           B` s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z e	 j
 j d  d    Z d	   Z d
   Z d   Z d   Z d   Z RS(   u   A test case for Rgbc         C` s  t  j j d  d \ |  _ |  _ |  _ d \ } } | |  _ | |  _ | | f } t  j |  } t  j |  } t  j |  } d d g d d	 g d
 d
 g d	 d g g } d d d d g }	 d d d d g }
 d d d d g } x t	 | |	 |
 |  D]| \ } } } } | t
 d d |  | | d | d f <| t
 d d |  | | d | d f <| | | d | d f <q Wd   } t d  } | | |  |  _ | | |  |  _ | | |  |  _ d  S(   Ni  i    i   i   iU   iK   i   i2   i-   i   i|  iX  i N  g      ?g      g       @g      g      @i
   g?i   c         S` s>   t  |  | d d d t } t j j d d |  j  } | | S(   Nt   boundaryu   extendt   normalize_kerneli    i   (   R   t   TrueR   R   t   normalt   shape(   R   t   psft   convolvedImaget   randomImage(    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   convolve_with_noisev   s    (   i    i   i   (   iU   iK   (   R   R   t   seedt   min_t   stretch_t   Qt   widtht   heightt   zerost   zipt   powR   R"   R'   R(   (   t   selft   methodR9   R:   R0   R"   R'   R(   t   pointst   valuest   g_rt   r_it   pt   vt   grt   riR4   R1   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   setup_method[   s,    		*())	c         C` se   t  j |  j |  j |  j  } | j |  j |  j |  j  } t	 ra t
 | d t j   j j n  d S(   u1   Test creating an RGB image using an asinh stretchR   N(   R   t   AsinhMappingR6   R7   R8   t   make_rgb_imageR"   R'   R(   t   displayR   t   syst	   _getframet   f_codet   co_name(   R>   t   asinhMapt   rgbImage(    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt
   test_Asinh   s    c         C` se   t  j |  j |  j |  j  } | j |  j |  j |  j  } t ra t | d t j	   j
 j n  d S(   uH   Test creating an RGB image using an asinh stretch estimated using zscaleR   N(   R   t   AsinhZScaleMappingR"   R'   R(   RJ   RK   R   RL   RM   RN   RO   (   R>   t   mapRQ   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_AsinhZscale   s    c         C` se   t  j |  j |  j |  j  } | j |  j |  j |  j  } t ra t | d t j	   j
 j n  d S(   uY   Test creating an RGB image using an asinh stretch estimated using zscale on the intensityR   N(   R   RS   R"   R'   R(   RJ   RK   R   RL   RM   RN   RO   (   R>   RT   RQ   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_AsinhZscaleIntensity   s    c         C` s   d d d g } |  j  | d 7_  |  j | d 7_ |  j | d 7_ t j |  j  |  j |  j d | } | j |  j  |  j |  j  } t r t | d t j	   j
 j n  d	 S(
   u   Test creating an RGB image using an asinh stretch estimated using zscale on the intensity
        where the images each have a pedestal addedid   i  ipi    i   i   t   pedestalR   N(   R"   R'   R(   R   RS   RJ   RK   R   RL   RM   RN   RO   (   R>   RW   RT   RQ   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt!   test_AsinhZscaleIntensityPedestal   s    $c         C` sY   t  j |  j  } | j |  j |  j |  j  } t rU t | d t j   j j	 n  d S(   ul   Test creating a black-and-white image using an asinh stretch estimated
        using zscale on the intensityR   N(
   R   RS   R"   RJ   RK   R   RL   RM   RN   RO   (   R>   RT   RQ   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_AsinhZscaleIntensityBW   s    u   not HAS_MATPLOTLIBc         C` s   d } t  j d d   } t |  j |  } t |  j |  } t |  j |  } t j | | | |  j |  j	 |  j
 d | t j j | j  s t  Wd QXd S(   u"   Test the function that does it allg     @@t   suffixu   .pngt   filenameN(   t   tempfilet   NamedTemporaryFileR   R"   R'   R(   R   t   make_lupton_rgbR6   R7   R8   t   ost   patht   existst   nameR!   (   R>   R   t   tempt   redt   greent   blue(    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_make_rgb   s    +c         C` s   t  j d  d } t j d d  t } t |  j |  } t |  j |  } t |  j |  } t j	 | | | |  j
 |  j |  j d d d d d	 | Wd  QXd  S(
   Nu(   saturation correction is not implementedg     @@RZ   u   .pngt   saturated_border_widthi   t   saturated_pixel_valuei  R[   (   t   pytestt   skipR\   R]   R   R"   R'   R(   R   R^   R6   R7   R8   (   R>   R   Rc   Rd   Re   Rf   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_make_rgb_saturated_fix   s    $c         C` sY   t  j d d  } | j |  j |  j |  j  } t rU t | d t j	   j
 j n  d S(   u%   Test using a specified linear stretchgfffff gzG*@R   N(   R   t   LinearMappingRJ   R"   R'   R(   RK   R   RL   RM   RN   RO   (   R>   RT   RQ   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_linear   s    c         C` s\   t  j d |  j  } | j |  j |  j |  j  } t rX t | d t j	   j
 j n  d S(   u=   Test using a min/max linear stretch determined from one imageR   R   N(   R   Rm   R(   RJ   R"   R'   RK   R   RL   RM   RN   RO   (   R>   RT   RQ   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_linear_min_max   s    c         C` s  t  j d  d } t |  j |  |  _ t |  j |  |  _ t |  j |  |  _ t j |  j |  j |  j d d  t j	 |  j j
   j    j   s t  t j	 |  j j
   j    j   s t  t j	 |  j j
   j    j   s t  |  j j
   |  _ |  j j
   |  _ |  j j
   |  _ t j |  j |  j |  j  } | j |  j |  j |  j  } t rt | d t j   j j n  d S(   u*   Test interpolationolating saturated pixelsu8   replaceSaturatedPixels is not implemented in astropy yetg     @@i   i  R   N(   Rj   Rk   R   R"   R'   R(   R   t   replaceSaturatedPixelsR   t   isfinitet   getImaget   getArrayt   allR!   t   imagesRt   imagesGt   imagesBRI   R6   R7   R8   RJ   RK   R   RL   RM   RN   RO   (   R>   R   RP   RQ   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_saturated   s     "***c         C` sk   t  j t  ; } |  j j |  j |  j  } t j | |  j	 |  j
  Wd  QXd t | j  k sg t  d  S(   Nu   shapes must match(   Rj   t   raisest
   ValueErrorR"   t   reshapeR:   R9   R   R^   R'   R(   t   strt   valueR!   (   R>   t   excinfoR"   (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   test_different_shapes_asserts   s    (   t   __name__t
   __module__t   __doc__RH   RR   RU   RV   RX   RY   Rj   t   markt   skipifRg   Rl   Rn   Ro   Rx   R   (    (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyR+   X   s   	%										(#   R   t
   __future__R    R   R   R   RL   R_   R\   Rj   t   numpyR   t   numpy.testingR   t   convolutionR   R   t    R   t
   matplotlibR.   t   HAS_MATPLOTLIBt   ImportErrort   FalseRK   t   NoneR   R   R   R$   R&   R)   R*   t   objectR+   (    (    (    sJ   lib/python2.7/site-packages/astropy/visualization/tests/test_lupton_rgb.pyt   <module>   s.   "


							