
    IR-e                     `    d dl Z d dlmZ d dlmZ d dlmZ ddgZ	 	 	 	 	 	 	 	 	 	 	 ddZddZ	dS )    N)log)getdata)simple_normfits2bitmapmainlinear      ?皙?Greys_rc                    ddl }ddlm} ddlm} 	 t          |          }n# t          $ r Y nw xY w	 t          | |          }n,# t          $ r}t          j
        |           Y d}~dS d}~ww xY w|j        dk    rt          j
        d| d           |dt          j                            |           d         }|                    d          r%t          j                            |          d         }|d	z  }t          j                            |          d         dd         }	  ||d
          r|j        |          nddl m} |                    |           n/# t          t&          f$ r t          j
        | d           Y dS w xY wt)          ||||||||	|
	  	        }|                    | ||          |d|           t          j        d| d           dS )a	  
    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'.
    r   N)
minversion      zdata in FITS extension z is not a 2D arrayz.fitsz.pngz3.5)cmz) is not a valid matplotlib colormap name.)stretchpowerasinh_amin_cutmax_cutmin_percentmax_percentpercentlower)cmaporiginformatzSaved file to .)
matplotlibmatplotlib.imageimageastropy.utils.introspectionr   int
ValueErrorr   	Exceptionr   criticalndimospathsplitextendswith	colormapsr   get_cmapKeyErrorr   imsaveinfo)filenameextout_fnr   r   r   r   r   r   r   r   r   r   mimgr   r    e
out_formatr   norms                       Ilib/python3.11/site-packages/astropy/visualization/scripts/fits2bitmap.pyr   r      sc   H ######666666#hh   #&&   Qqqqqq zQFsFFFGGG~!!(++A.??7## 	1W%%f--a0F& !!&))!,QRR0J	:j%(( 	 &&&%%%%%%KK!   GGGHHHqq 
 
 
D 	KKU$wzKRRRH'f'''(((((s5   " 
//A 
A-A((A-'5E (F	F	c                    dd l }|                    d          }|                    ddddd           |                    d	d
t          d d           |                    dt          dd           |                    dt          dd           |                    dt          dd           |                    dt          d d           |                    dt          d d           |                    dt          d d           |                    dt          d d           |                    dt          d d            |                    d!d"t          d#d$           |                    d
d%d&'           |                    |           } | j        D ]T}t          || j        | j	        | j
        | j        | j        | j        | j        | j        | j        | j        | j        (           Ud S ))Nr   z'Create a bitmap file from a FITS image.)descriptionz-ez--exthduz8Specify the HDU extension number or name (Default is 0).)metavardefaulthelpz-or0   zZFilename for the output image (Default is a PNG file with the same name as the FITS file).)r;   typer<   r=   z	--stretchr   z^Type of image stretching ("linear", "sqrt", "power", "log", or "asinh") (Default is "linear").)r>   r<   r=   z--powerr	   z4Power index for "power" stretching (Default is 1.0).z	--asinh_ar
   zThe value in normalized image where the asinh curve transitions from linear to logarithmic behavior (used only for "asinh" stretch) (Default is 0.1).z	--min_cutzHThe pixel value of the minimum cut level (Default is the image minimum).z	--max_cutzHThe pixel value of the maximum cut level (Default is the image maximum).z--min_percentzLThe percentile value used to determine the minimum cut level (Default is 0).z--max_percentzNThe percentile value used to determine the maximum cut level (Default is 100).z	--percentz}The percentage of the image values used to determine the pixel values of the minimum and maximum cut levels (Default is 100).z--cmapcolormap_namer   z1matplotlib color map name (Default is "Greys_r").+z)Path to one or more FITS files to convert)nargsr=   )r1   r2   r   r   r   r   r   r   r   r   r   )argparseArgumentParseradd_argumentstrfloat
parse_argsr0   r   r1   or   r   r   r   r   r   r   r   r   )argsrB   parserr0   s       r7   r   r      s   OOO$$= %  F G     =  	 	 	 A     C	        
 
 
 W	     W	     0     2     3  	 	 	 @     #$O     T""DM 
 
6LLL((L*L	
 	
 	
 	
 	

 
    )r   Nr   r	   r
   NNNNNr   )N)
r'   astropyr   astropy.io.fitsr   #astropy.visualization.mpl_normalizer   __all__r   r    rK   r7   <module>rQ      s    
			       # # # # # # ; ; ; ; ; ;&
!
 	

	y) y) y) y)xs
 s
 s
 s
 s
 s
rK   