U
    ?hw                     @   s`   d dgZ ddlmZ zddlmZ W n ek
r@   edY nX dd  ZdddZd	d
 ZdS )imreadimread_collection    N)fitszAstropy could not be found. It is needed to read FITS files.
Please refer to https://www.astropy.org for installation
instructions.c              	   C   sT   t | @}d}|D ]0}t|t js0t|t jr|jdk	r|j} qFqW 5 Q R X |S )a  Load an image from a FITS file.

    Parameters
    ----------
    fname : string
        Image file name, e.g. ``test.fits``.

    Returns
    -------
    img_array : ndarray
        Unlike plugins such as PIL, where different color bands/channels are
        stored in the third dimension, FITS images are grayscale-only and can
        be N-dimensional, so an array of the native FITS dimensionality is
        returned, without color channels.

        Currently if no image is found in the file, None will be returned

    Notes
    -----
    Currently FITS ``imread()`` always returns the first image extension when
    given a Multi-Extension FITS file; use ``imread_collection()`` (which does
    lazy loading) to get all the extensions at once.

    N)r   open
isinstanceImageHDU
PrimaryHDUdata)fnamehdulistZ	img_arrayhdu r   Q/var/www/html/venv/lib/python3.8/site-packages/skimage/io/_plugins/fits_plugin.pyr      s    

Tc           	      C   s   t | }|tk	r |tk	r td|tk	r.| g} g }| D ]}t|x}ttt||D ]^\}}t	|tj
sxt	|tjrXz
|j}W n tk
r   | }Y nX |dkrX|||f qXW 5 Q R X q6tj|t|dS )a  Load a collection of images from one or more FITS files

    Parameters
    ----------
    load_pattern : str or list
        List of extensions to load. Filename globbing is currently
        unsupported.
    conserve_memory : bool
        If True, never keep more than one in memory at a specific
        time. Otherwise, images will be cached once they are loaded.

    Returns
    -------
    ic : ImageCollection
        Collection of images.

    z-Input must be a filename or list of filenamesr   )Z	load_funcconserve_memory)typeliststr	TypeErrorr   r   ziprangelenr   r   r   sizeappendioZImageCollectionFITSFactory)	Zload_patternr   ZintypeZext_listfilenamer   nr   	data_sizer   r   r   r   6   s*    

c              	   C   s   t | tstdt| dkr&td| d }| d }t|tk	sNt|tk	rVtdt	|}|| j
}W 5 Q R X |dkrtd| d	| d
|S )a  Load an image extension from a FITS file and return a NumPy array

    Parameters
    ----------
    image_ext : tuple
        FITS extension to load, in the format ``(filename, ext_num)``.
        The FITS ``(extname, extver)`` format is unsupported, since this
        function is not called directly by the user and
        ``imread_collection()`` does the work of figuring out which
        extensions need loading.

    zExpected a tuple   zExpected a tuple of length 2r      z&Expected a (filename, extension) tupleNz
Extension z of z has no data)r   tupler   r   
ValueErrorr   r   intr   r   r	   RuntimeError)Z	image_extr   Zextnumr   r	   r   r   r   r   f   s    
r   )T)	__all__Z
skimage.ior   Z
astropy.ior   ImportErrorr   r   r   r   r   r   r   <module>   s   
(
0