U
    e»{jâ  ã                   @   sL   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d„Zddd„Z	dS )é    N)Úlog)Úgetdata)Úsimple_normÚfits2bitmapÚmainÚlinearç      ð?çš™™™™™¹?ÚGreys_rc                 C   sš  ddl }ddlm} ddlm} zt|ƒ}W n tk
r@   Y nX zt| |ƒ}W n2 tk
r‚ } zt	 
|¡ W Y ¢dS d}~X Y nX |jdkr t	 
d|› d�¡ |dkrÚtj | ¡d }| d¡rÒtj |¡d }|d	7 }tj |¡d dd… }z2||d
ƒ�r|j|  nddl m} | |¡ W n, ttfk
�rP   t	 
|› d�¡ Y dS X t||||||||	|
d�	}|j|||ƒ|d|d� t	 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 Ú.)Ú
matplotlibZmatplotlib.imageÚimageZastropy.utils.introspectionr   ÚintÚ
ValueErrorr   Ú	Exceptionr   ÚcriticalÚndimÚosÚpathÚsplitextÚendswithZ	colormapsr   Zget_cmapÚKeyErrorr   ZimsaveÚinfo)ÚfilenameÚextÚout_fnr   r   r   r   r   r   r   r   r   r   Zmimgr   r   ÚeZ
out_formatr   Znorm© r-   úh/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/visualization/scripts/fits2bitmap.pyr      sR    D


÷c                 C   sB  dd l }|jdd�}|jdddddd� |jd	d
td dd� |jdtddd� |jdtddd� |jdtddd� |jdtd dd� |jdtd dd� |jdtd dd� |jdtd dd� |jdtd d d� |jd!d"td#d$d� |jd
d%d&d'� | | ¡} | jD ]<}t|| j| j	| j
| j| j| j| j| j| j| j| jd(� �q d S ))Nr   z'Create a bitmap file from a FITS image.)Údescriptionz-ez--extZhduz8Specify the HDU extension number or name (Default is 0).)ÚmetavarÚdefaultÚhelpz-or)   zZFilename for the output image (Default is a PNG file with the same name as the FITS file).)r0   Útyper1   r2   z	--stretchr   z^Type of image stretching ("linear", "sqrt", "power", "log", or "asinh") (Default is "linear").)r3   r1   r2   z--powerr   z4Power index for "power" stretching (Default is 1.0).z	--asinh_ar	   z•The 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--cmapZcolormap_namer
   z1matplotlib color map name (Default is "Greys_r").ú+z)Path to one or more FITS files to convert)Únargsr2   )r*   r+   r   r   r   r   r   r   r   r   r   )ÚargparseÚArgumentParserÚadd_argumentÚstrÚfloatÚ
parse_argsr)   r   r*   Úor   r   r   r   r   r   r   r   r   )Úargsr6   Úparserr)   r-   r-   r.   r   ˆ   s¼    ÿûú
û	üûüüû	û	û
û  ÿ

ô)r   Nr   r   r	   NNNNNr
   )N)
r#   Zastropyr   Zastropy.io.fitsr   Z#astropy.visualization.mpl_normalizer   Ú__all__r   r   r-   r-   r-   r.   Ú<module>   s"              ô
|