a
    
dw                     @   s^   d dgZ ddlmZ zddlmZ W n ey>   edY n0 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   sh   t | J}d}|D ]0}t|t js0t|t jr|jdur|j} qFqW d   n1 sZ0    Y  |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   h/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/skimage/io/_plugins/fits_plugin.pyr      s    

$Tc           	      C   s   t | }|tur |tur td|tur.| g} g }| D ]}t|}ttt||D ]\\}}t	|tj
sxt	|tjrXz
|j}W n ty   | }Y n0 |dkrX|||f qXW d   q61 s0    Y  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   N)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*    

0c                 C   s   t | tstdt| dkr&td| d }| d }t|tusNt|turVtdt	|}|| j
}W d   n1 s0    Y  |du 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