ó
 ‰\c           @   s˜   d  d g Z  d d l j Z y d d l m Z WnA e k
 rr y d d l Z Wqs e k
 rn e d ƒ ‚ qs Xn Xd d „ Z e	 d „ Z
 d „  Z d S(	   t   imreadt   imread_collectioniÿÿÿÿN(   t   fitss|   PyFITS could not be found. Please refer to
http://www.stsci.edu/resources/software_hardware/pyfits
for further instructions.c         C   sw   t  j |  ƒ } d } xQ | D]I } t | t  j ƒ sF t | t  j ƒ r | j d k	 re | j } Pqe q q W| j ƒ  | S(   s•  Load an image from a FITS file.

    Parameters
    ----------
    fname : string
        Image file name, e.g. ``test.fits``.
    dtype : dtype, optional
        For FITS, this argument is ignored because Stefan is planning on
        removing the dtype argument from imread anyway.

    Returns
    -------
    img_array : ndarray
        Unlike plugins such as PIL, where different color bands/channels are
        stored in the third dimension, FITS images are greyscale-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(   t   pyfitst   opent   Nonet
   isinstancet   ImageHDUt
   PrimaryHDUt   datat   close(   t   fnamet   dtypet   hdulistt	   img_arrayt   hdu(    (    s>   lib/python2.7/site-packages/skimage/io/_plugins/fits_plugin.pyR       s    	
c   	      C   s6  t  |  ƒ } | t k	 r3 | t k	 r3 t d ƒ ‚ n  | t k	 rK |  g }  n  g  } xÉ |  D]Á } t j | ƒ } xŸ t t t | ƒ ƒ | ƒ D]‚ \ } } t	 | t j
 ƒ s¹ t	 | t j ƒ r‰ y | j ƒ  } Wn t k
 rå | j } n X| d k r| j | | f ƒ qq‰ q‰ W| j ƒ  qX Wt j | d t d | ƒS(   sê  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.
       converve_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.

    s-   Input must be a filename or list of filenamesi    t	   load_funct   conserve_memory(   t   typet   listt   strt	   TypeErrorR   R   t   zipt   ranget   lenR   R   R   t   sizet   appendR
   t   iot   ImageCollectiont   FITSFactory(	   t   load_patternR   t   intypet   ext_listt   filenameR   t   nR   t	   data_size(    (    s>   lib/python2.7/site-packages/skimage/io/_plugins/fits_plugin.pyR   ?   s(    (c         C   sÕ   t  |  t ƒ s t d ƒ ‚ n  t |  ƒ d k r? t d ƒ ‚ n  |  d } |  d } t | ƒ t k	 sw t | ƒ t k	 r† t d ƒ ‚ n  t j	 | ƒ } | | j
 } | j ƒ  | d k rÑ t d | | f ƒ ‚ n  | S(	   sª  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.

    s   Expected a tuplei   s   Expected a tuple of length 2i    i   s&   Expected a (filename, extension) tuples   Extension %d of %s has no dataN(   R   t   tupleR   R   t
   ValueErrorR   R   t   intR   R   R	   R
   R   t   RuntimeError(   t	   image_extR!   t   extnumR   R	   (    (    s>   lib/python2.7/site-packages/skimage/io/_plugins/fits_plugin.pyR   q   s    

$
(   t   __all__t
   skimage.ioR   t
   astropy.ioR   R   t   ImportErrorR   R    t   TrueR   R   (    (    (    s>   lib/python2.7/site-packages/skimage/io/_plugins/fits_plugin.pyt   <module>   s   .2