o
    hw                     @   sZ   d dgZ ddlmZ zddlmZ W n ey   edw 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   sz   t | .}d}|D ]}t|t jst|t jr"|jdur"|j} n	q
W d   |S W d   |S 1 s6w   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hdulist	img_arrayhdu r   Z/var/www/html/scripts/venv/lib/python3.10/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 ]O}t|@}ttt||D ].\}}t	|tj
s<t	|tjrZz|j}W n tyN   | }Y nw |dkrZ|||f q,W d   n1 sew   Y  qt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)	load_funcconserve_memory)typeliststr	TypeErrorr   r   ziprangelenr   r   r   sizeappendioImageCollectionFITSFactory)	load_patternr   intypeext_listfilenamer   nr   	data_sizer   r   r   r   6   s4   

c                 C   s   t | ts	tdt| dkrtd| d }| d }t|tus't|tur+tdt	|}|| j
}W d   n1 s@w   Y  |du rTt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)	image_extr!   extnumr   r	   r   r   r   r   f   s    
r   )T)	__all__
skimage.ior   
astropy.ior   ImportErrorr   r   r   r   r   r   r   <module>   s    
(0