B
    ÿNŽ[µ  ã               @   sh   d Z ddlmZmZmZ ddlmZ ddlmZ da	dd„ Z
G d	d
„ d
eƒZeddddƒZe e¡ dS )z  Plugin for reading FITS files.
é    )Úabsolute_importÚprint_functionÚdivisioné   )Úformats)ÚFormatNc               C   s2   yddl ma W n tk
r,   tdƒ‚Y nX tS )Nr   )ÚfitszoThe FITS format relies on the astropy package.Please refer to http://www.astropy.org/ for further instructions.)Z
astropy.ior   Ú_fitsÚImportError© r   r   ú3lib/python3.7/site-packages/imageio/plugins/fits.pyÚload_lib   s    r   c               @   s2   e Zd ZdZdd„ Zdd„ ZG dd„ dejƒZdS )	Ú
FitsFormataB	   Flexible Image Transport System (FITS) is an open standard defining a
    digital file format useful for storage, transmission and processing of
    scientific and other images. FITS is the most commonly used digital
    file format in astronomy.
    
    This format requires the ``astropy`` package.

    Parameters for reading
    ----------------------
    cache : bool
        If the file name is a URL, `~astropy.utils.data.download_file` is used
        to open the file.  This specifies whether or not to save the file
        locally in Astropy's download cache (default: `True`).
    uint : bool
        Interpret signed integer data where ``BZERO`` is the
        central value and ``BSCALE == 1`` as unsigned integer
        data.  For example, ``int16`` data with ``BZERO = 32768``
        and ``BSCALE = 1`` would be treated as ``uint16`` data.

        Note, for backward compatibility, the kwarg **uint16** may
        be used instead.  The kwarg was renamed when support was
        added for integers of any size.
    ignore_missing_end : bool
        Do not issue an exception when opening a file that is
        missing an ``END`` card in the last header.
    checksum : bool or str
        If `True`, verifies that both ``DATASUM`` and
        ``CHECKSUM`` card values (when present in the HDU header)
        match the header and data of all HDU's in the file.  Updates to a
        file that already has a checksum will preserve and update the
        existing checksums unless this argument is given a value of
        'remove', in which case the CHECKSUM and DATASUM values are not
        checked, and are removed when saving changes to the file.
    disable_image_compression : bool, optional
        If `True`, treats compressed image HDU's like normal
        binary table HDU's.
    do_not_scale_image_data : bool
        If `True`, image data is not scaled using BSCALE/BZERO values
        when read.
    ignore_blank : bool
        If `True`, the BLANK keyword is ignored if present.
    scale_back : bool
        If `True`, when saving changes to a file that contained scaled
        image data, restore the data to the original type and reapply the
        original BSCALE/BZERO values.  This could lead to loss of accuracy
        if scaling back to integer values after performing floating point
        operations on the data.
    c             C   s   |j | jkS )N)Ú	extensionÚ
extensions)ÚselfÚrequestr   r   r   Ú	_can_readO   s    zFitsFormat._can_readc             C   s   dS )NFr   )r   r   r   r   r   Ú
_can_writeT   s    zFitsFormat._can_writec               @   s6   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )zFitsFormat.ReaderFc             K   s„   t s
tƒ  t j| j ¡ fd|i|—Ž}g | _xLttt|ƒƒ|ƒD ]6\}}t	|t j
ƒs`t	|t jƒr@|jdkr@| j |¡ q@W || _d S )NÚcacher   )r	   r   Úopenr   Zget_fileÚ_indexÚzipÚrangeÚlenÚ
isinstanceZImageHDUZ
PrimaryHDUÚsizeÚappendÚ_hdulist)r   r   ÚkwargsZhdulistÚnZhdur   r   r   Ú_open[   s    
zFitsFormat.Reader._openc             C   s   | j  ¡  d S )N)r   Úclose)r   r   r   r   Ú_closei   s    zFitsFormat.Reader._closec             C   s
   t | jƒS )N)r   r   )r   r   r   r   Ú_get_lengthl   s    zFitsFormat.Reader._get_lengthc             C   s8   |dk s|t | jƒkrtdƒ‚| j| j|  j}|i fS )Nr   z*Index out of range while reading from fits)r   r   Ú
IndexErrorr   Údata)r   ÚindexZimr   r   r   Ú	_get_datao   s    zFitsFormat.Reader._get_datac             C   s   t dƒ‚d S )Nz+The fits format does not support meta data.)ÚRuntimeError)r   r'   r   r   r   Ú_get_meta_dataw   s    z FitsFormat.Reader._get_meta_dataN)F)Ú__name__Ú
__module__Ú__qualname__r!   r#   r$   r(   r*   r   r   r   r   ÚReaderZ   s
   
r.   N)r+   r,   r-   Ú__doc__r   r   r   r.   r   r   r   r   r      s   1r   r   z-Flexible Image Transport System (FITS) formatzfits fit ftsZiIvV)r/   Z
__future__r   r   r   Ú r   Zcorer   r	   r   r   ÚformatZ
add_formatr   r   r   r   Ú<module>   s   a