
    IR-e$                         d 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 ddlmZ dZddZd	 ZddZd Zd Zd Zd Z G d d          ZdS )z
Tests for RGB Images
    N)assert_equal)Gaussian2DKernelconvolve)HAS_MATPLOTLIB)
lupton_rgbFc                     ddl m} |                    | dd           |r|                    |           |                                 |S )z<Display an rgb image using matplotlib (useful for debugging)r   Nnearestlower)interpolationorigin)matplotlib.pyplotpyplotimshowtitleshow)rgbr   plts      Klib/python3.11/site-packages/astropy/visualization/tests/test_lupton_rgb.pydisplay_rgbr      sX    ######JJs)GJ<<< 		%HHJJJJ    c                 X    |                                  }| |k    }t          j        ||<   |S )z
    Return image with all points above satValue set to NaN.

    Simulates saturation on an image, so we can test 'replace_saturated_pixels'
    )copynpnan)imagesatValueresult	saturateds       r   saturater   #   s,     ZZ\\F IF9Mr   d   c                 n    t          j        t           j                            d          dz  |           S )N
   r    )dtype)r   arrayrandom)r#   Ns     r   random_arrayr'   /   s,    8BI$$R((3.e<<<<r   c                      t          t          j                  } t          j        |           }| j        |j        k    sJ t          | |           d S Nr'   r   float64r   compute_intensityr#   r   image_r	intensitys     r   test_compute_intensity_1_floatr0   3   sL    2:&&G,W55I=IO++++)$$$$$r   c                      t          t          j                  } t          j        |           }| j        |j        k    sJ t          | |           d S r)   r'   r   uint8r   r,   r#   r   r-   s     r   test_compute_intensity_1_uintr4   :   sL    28$$G,W55I=IO++++)$$$$$r   c                     t          t          j                  } t          t          j                  }t          t          j                  }t          j        | ||          }| j        |j        k    sJ t          || |z   |z   dz             d S )Ng      @r*   r.   image_gimage_br/   s       r   test_compute_intensity_3_floatr9   A   s}    2:&&G2:&&G2:&&G,WgwGGI=IO++++Ww.8C?@@@@@r   c                     t          t          j                  } t          t          j                  }t          t          j                  }t          j        | ||          }| j        |j        k    sJ t          || |z   |z   dz             d S )N   r2   r6   s       r   test_compute_intensity_3_uintr<   J   s}    28$$G28$$G28$$G,WgwGGI=IO++++Ww.8Q>?????r   c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	e
j                            e d	          d
             Zd Zd Zd Zd Zd ZdS )TestLuptonRgbzA test case for Rgbc                    t           j                            d           d\  | _        | _        | _        d\  }}|| _        || _        ||f}t          j        |          }t          j        |          }t          j        |          }ddgddgddgddgg}g d}	g d	}
g d
}t          ||	|
|          D ]h\  }}}}|t          dd|z            z  ||d         |d         f<   |t          dd|z            z  ||d         |d         f<   |||d         |d         f<   id }t          d          } |||          | _         |||          | _         |||          | _        d S )N  )r         )U   K      2   -      )r@   i|  iX  i N  )      ?g      rI   rI   )g       @g            @rI   r"   g?r      c                 ~    t          | |dd          }t          j                            dd| j                  }||z   S )NextendT)boundarynormalize_kernelr      )r   r   r%   normalshape)r   psfconvolvedImagerandomImages       r   convolve_with_noisez7TestLuptonRgb.setup_method.<locals>.convolve_with_noiseq   sG    %sX  N )**1a==K//r   rJ   )r   r%   seedmin_stretch_Qwidthheightzeroszippowr   r.   r7   r8   )selfmethodr[   r\   rR   r.   r7   r8   pointsvaluesg_rr_ipvgrrirV   rS   s                     r   setup_methodzTestLuptonRgb.setup_methodV   s   
	t+3(	4=$&v
(5//(5//(5// r(RHr2hR9)))######  S99 	$ 	$LAq"b"#c"cBh&7&7"7GAaD!A$J"#c"cBh&7&7"7GAaD!A$J"#GAaD!A$J	0 	0 	0 s##**7C88**7C88**7C88r   c                    t          j        | j        | j        | j                  }|                    | j        | j        | j                  }t          r.t          |t          j                    j        j                   dS dS )z1Test creating an RGB image using an asinh stretchr   N)r   AsinhMappingrX   rY   rZ   make_rgb_imager.   r7   r8   displayr   sys	_getframef_codeco_name)r`   asinhMaprgbImages      r   
test_AsinhzTestLuptonRgb.test_Asinh}   ss    *49dmTVLL**4<t|TT 	H(>(FGGGGGG	H 	Hr   c                    t          j        | j        | j        | j                  }|                    | j        | j        | j                  }t          r.t          |t          j	                    j
        j                   dS dS )zHTest creating an RGB image using an asinh stretch estimated using zscalerl   Nr   AsinhZScaleMappingr.   r7   r8   rn   ro   r   rp   rq   rr   rs   r`   mapru   s      r   test_AsinhZscalezTestLuptonRgb.test_AsinhZscale   su     +DL$,UU%%dlDL$,OO 	H(>(FGGGGGG	H 	Hr   c                    t          j        | j        | j        | j                  }|                    | j        | j        | j                  }t          r.t          |t          j	                    j
        j                   dS dS )zk
        Test creating an RGB image using an asinh stretch estimated using zscale on the intensity
        rl   Nrx   rz   s      r   test_AsinhZscaleIntensityz'TestLuptonRgb.test_AsinhZscaleIntensity   su    
 +DL$,UU%%dlDL$,OO 	H(>(FGGGGGG	H 	Hr   c                    g d}| xj         |d         z  c_         | xj        |d         z  c_        | xj        |d         z  c_        t          j        | j         | j        | j        |          }|                    | j         | j        | j                  }t          r.t          |t          j	                    j
        j                   dS dS )zTest creating an RGB image using an asinh stretch estimated using zscale on the intensity
        where the images each have a pedestal added)r    i  ipr   rK   rP   )pedestalrl   N)r.   r7   r8   r   ry   rn   ro   r   rp   rq   rr   rs   )r`   r   r{   ru   s       r   !test_AsinhZscaleIntensityPedestalz/TestLuptonRgb.test_AsinhZscaleIntensityPedestal   s     $#####+L$,x
 
 
 %%dlDL$,OO 	H(>(FGGGGGG	H 	Hr   c                     t          j        | j                  }|                    | j        | j        | j                  }t          r.t          |t          j                    j        j	                   dS dS )zlTest creating a black-and-white image using an asinh stretch estimated
        using zscale on the intensityrl   N)
r   ry   r.   rn   ro   r   rp   rq   rr   rs   rz   s      r   test_AsinhZscaleIntensityBWz)TestLuptonRgb.test_AsinhZscaleIntensityBW   sm     +DL99%%dlDL$,OO 	H(>(FGGGGGG	H 	Hr   zrequires matplotlib)reasonc           
         d}t          j        d          5 }t          | j        |          }t          | j        |          }t          | j        |          }t          j        |||| j        | j	        | j
        |           t          j                            |j                  sJ 	 ddd           dS # 1 swxY w Y   dS )z"Test the function that does it all     @@.pngsuffix)filenameN)tempfileNamedTemporaryFiler   r.   r7   r8   r   make_lupton_rgbrX   rY   rZ   ospathexistsnamer`   r   tempredgreenblues         r   test_make_rgbzTestLuptonRgb.test_make_rgb   s    (777 	-44<22CT\844EDL(33D&UD$)T]DFT    7>>$),,,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   BB66B:=B:c                 d   t          j        d           d}t          j        d          5 }t	          | j        |          }t	          | j        |          }t	          | j        |          }t          j	        |||| j
        | j        | j        dd|	  	         d d d            d S # 1 swxY w Y   d S )Nz(saturation correction is not implementedr   r   r   rK     )saturated_border_widthsaturated_pixel_valuer   )pytestskipr   r   r   r.   r7   r8   r   r   rX   rY   rZ   r   s         r   test_make_rgb_saturated_fixz)TestLuptonRgb.test_make_rgb_saturated_fix   s    >???(777 	44<22CT\844EDL(33D&	'(&*
 
 
 
		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A,B%%B),B)c                     t          j        dd          }|                    | j        | j        | j                  }t          r.t          |t          j	                    j
        j                   dS dS )z%Test using a specified linear stretchgfffff gzG*@rl   N)r   LinearMappingrn   r.   r7   r8   ro   r   rp   rq   rr   rs   rz   s      r   test_linearzTestLuptonRgb.test_linear   sm     &ue44%%dlDL$,OO 	H(>(FGGGGGG	H 	Hr   c                     t          j        | j                  }|                    | j        | j        | j                  }t          r.t          |t          j	                    j
        j                   dS dS )z=Test using a min/max linear stretch determined from one image)r   rl   N)r   r   r8   rn   r.   r7   ro   r   rp   rq   rr   rs   rz   s      r   test_linear_min_maxz!TestLuptonRgb.test_linear_min_max   sp     &T\:::%%dlDL$,OO 	H(>(FGGGGGG	H 	Hr   c                    t          j        d           d}t          | j        |          | _        t          | j        |          | _        t          | j        |          | _        t          j        | j        | j        | j        dd           t          j	        | j        
                                                                                                          sJ t          j	        | j        
                                                                                                          sJ t          j	        | j        
                                                                                                          sJ | j        
                                | _        | j        
                                | _        | j        
                                | _        t          j        | j        | j        | j                  }|                    | j        | j        | j                  }t*          r.t-          |t/          j                    j        j                   dS dS )z*Test interpolationolating saturated pixelsz8replaceSaturatedPixels is not implemented in astropy yetr   rK   r   rl   N)r   r   r   r.   r7   r8   r   replaceSaturatedPixelsr   isfinitegetImagegetArrayallimagesRimagesGimagesBrm   rX   rY   rZ   rn   ro   r   rp   rq   rr   rs   )r`   r   rt   ru   s       r   test_saturatedzTestLuptonRgb.test_saturated   s   NOOOh77h77h77)L$,a	
 	
 	
 {4<0022;;==>>BBDDDDD{4<0022;;==>>BBDDDDD{4<0022;;==>>BBDDDDD |,,..|,,..|,,..*49dmTVLL**4<t|TT 	H(>(FGGGGGG	H 	Hr   c                     t          j        t          d          5  | j                            | j        | j                  }t          j        || j	        | j
                   d d d            d S # 1 swxY w Y   d S )Nzshapes must match)match)r   raises
ValueErrorr.   reshaper\   r[   r   r   r7   r8   )r`   r.   s     r   test_different_shapes_assertsz+TestLuptonRgb.test_different_shapes_asserts   s    ]:-ABBB 	L 	Ll**4;
CCG&wdlKKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	Ls   AA//A36A3N)__name__
__module____qualname____doc__rj   rv   r|   r~   r   r   r   markskipifr   r   r   r   r   r   r    r   r   r>   r>   S   s       %9 %9 %9NH H HH H HH H HH H H H H H [N*3HII
- 
- JI
-  (H H HH H HH H H6L L L L Lr   r>   r)   )r    )r   r   rp   r   numpyr   r   numpy.testingr   astropy.convolutionr   r   "astropy.utils.compat.optional_depsr   astropy.visualizationr   ro   r   r   r'   r0   r4   r9   r<   r>   r   r   r   <module>r      sU   
 
			 



       & & & & & & : : : : : : : : = = = = = = , , , , , ,    	 	 	= = = =% % %% % %A A A@ @ @lL lL lL lL lL lL lL lL lL lLr   