
[c           @   s9  d  d l  Z  d  d l Z d  d l Z d d l m Z m Z m Z m Z m	 Z	 d d l
 m Z d d l m Z m Z m Z d d l m Z d d	 l m Z d d
 l m Z m Z d d l m Z m Z d e f d     YZ d e f d     YZ d e f d     YZ d e e f d     YZ d e f d     YZ d S(   iNi   (   t   DELAYEDt	   _ValidHDUt   ExtensionHDUt   BITPIX2DTYPEt   DTYPE2BITPIXi   (   t   Header(   t   _is_pseudo_unsignedt   _unsigned_zerot   _is_int(   t   VerifyWarningi   (   t   string_types(   t   ranget   zip(   t
   isiterablet   lazypropertyt   _ImageBaseHDUc           B   sz  e  Z d  Z i d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6Z d( d( e e e e d  Z e d    Z	 e
 d    Z e
 d    Z e
 d    Z e
 d    Z e j d    Z e d    Z e j d    Z d   Z d( d  Z d( d d( d( d  Z d( d d( d( d d  Z d d  Z d    Z e e d!  Z d"   Z d#   Z d$   Z d%   Z d&   Z d'   Z RS()   s{   FITS image HDU base class.

    Attributes
    ----------
    header
        image header

    data
        image data
    s   conforms to FITS standardt   SIMPLEs   Image extensiont   XTENSIONs   array data typet   BITPIXs   number of array dimensionst   NAXISs
   has groupst   GROUPSs   number of parameterst   PCOUNTs   number of groupst   GCOUNTc         K   s(  d d l  m } t t |   j d | d |  | d  k	 r\ t | t  s\ t d   q\ n  | t	 k r | d  k r t d   q| |  _
 nIt |  t  r d d |  j d f }	 n d	 t |  j d	 f }	 |	 d
 d |  j d
 f d d |  j d f g }
 t |  |  r+|
 j d t |  j d f  n  t |  t | f  r}|
 j d d |  j d f  |
 j d d |  j d f  n  | d  k	 r| j   } t |
  } | j | d t d t d t n t |
  } | |  _
 | |  _ | |  _ | |  _ d |  j
 k } d |  j
 k } |  j
 j d d  |  _ |  j
 j d d  |  _ g  t |  j
 j d d   D]) } |  j
 j d t | d  d  ^ q]|  _ |  j
 j d
  |  _ |  j
 j d d  |  _ |  j
 j d d  |  _ | rd  n |  j
 j d  |  _ |  j   |  j |  _ |  j
 j d  |  _  |  j |  _! |  j |  _" d | k r^| d r^| d |  _# n  t$ |  _% | t	 k r| r|  j d k s|  j d k rt |  _& n  d  S| |  _' |  j(   |  j
 j d
  |  _ |  j
 j d  |  _ |  j
 j d  |  _ | s|  j |  _! n  | s$|  j |  _" n  d  S(   Ni   (   t	   GroupsHDUt   datat   headers   header must be a Header objects   No header to setup HDU.R   t   IMAGER   R   i   R   i    R   R   R   t   stript   updatet   endt   BZEROt   BSCALEt   BLANKt   name()   t   groupsR   t   superR   t   __init__t   Nonet
   isinstanceR   t
   ValueErrorR    t   _headerR   t   standard_keyword_commentst   Truet   appendt   copyt   extendt   _do_not_scale_image_datat   _uintt   _scale_backt   gett   _bzerot   _bscaleR   t   strt   _axest   _bitpixt   _gcountt   _pcountt   _blankt   _verify_blankt   _orig_bitpixt   _orig_blankt   _orig_bzerot   _orig_bscaleR!   t   Falset	   _modifiedt   _data_needs_rescaleR   t   update_header(   t   selfR   R   t   do_not_scale_image_datat   uintt
   scale_backt   ignore_blankt   kwargsR   t   c0t   cardst   origt   bzero_in_headert   bscale_in_headert   axis(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR$   (   s    "				K!
		
c         C   s
   t   d S(   s   
        _ImageBaseHDU is sort of an abstract class for HDUs containing image
        data (as opposed to table data) and should never be used directly.
        N(   t   NotImplementedError(   t   clsR   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyt   match_header   s    c         C   s   t  S(   N(   R*   (   RC   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyt   is_image   s    c         C   s
   t  |   S(   sB  
        Access a section of the image array without loading the entire array
        into memory.  The :class:`Section` object returned by this attribute is
        not meant to be used directly by itself.  Rather, slices of the section
        return the appropriate slice of the data, and loads *only* that section
        into memory.

        Sections are mostly obsoleted by memmap support, but should still be
        used to deal with very large scaled images.  See the
        :ref:`data-sections` section of the Astropy documentation for more
        details.
        (   t   Section(   RC   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyt   section   s    c         C   s   t  t |  j   S(   sX   
        Shape of the image array--should be equivalent to ``self.data.shape``.
        (   t   tuplet   reversedR5   (   RC   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyt   shape   s    c         C   s   |  j  S(   N(   R(   (   RC   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR      s    c         C   s    | |  _  t |  _ |  j   d  S(   N(   R(   R*   R@   RB   (   RC   R   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR      s    		c         C   sE   t  |  j  d k  r d S|  j |  j |  j  } |  j | j  | S(   s  
        Image/array data as a `~numpy.ndarray`.

        Please remember that the order of axes on an Numpy array are opposite
        of the order specified in the FITS file.  For example for a 2D image
        the "rows" or y-axis are the first dimension, and the "columns" or
        x-axis are the second dimension.

        If the data is scaled using the BZERO and BSCALE parameters, this
        attribute returns the data scaled to its physical values unless the
        file was opened with ``do_not_scale_image_data=True``.
        i   N(   t   lenR5   t   _get_scaled_image_datat   _data_offsetRW   t   _update_header_scale_infot   dtype(   RC   R   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR      s
    c         C   s  d |  j  k r[ |  j  d d  k	 r[ |  j  d | k r9 d  St |  _ t |  j  d j  } n t |  _ t } | d  k	 r t | t j	  r y t j
 |  } Wq t k
 r t d j |    q Xn  | |  j  d <t |  _ t | t j	  r@t | j j |  _ d |  _ d |  _ d  |  _ t | j  |  _ |  j j   n' |  j d  k r[g  |  _ n t d   |  j   | d  k	 r| r|  j | j  n  |  j |  _ |  j |  _ |  j |  _ | S(   NR   s5   data object {!r} could not be coerced into an ndarrayi   i    s   not a valid data array(    t   __dict__R%   R*   t   _data_replacedR   R\   R?   R&   t   npt   ndarrayt   arrayt	   Exceptiont	   TypeErrort   formatR@   R   R!   R6   R3   R2   R9   t   listRW   R5   t   reverseR   R'   RB   R[   R;   R>   R=   (   RC   R   t   was_unsigned(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR      s@    "							
c         C   sR  |  j  p0 |  j j  p0 |  j o0 |  j |  j j k s7 d S|  j j d d  } d |  j k rk |  j d } n |  j j d } |  j j d |  j	 | d d |  j r |  j |  j j k r t
 |  j j  |  _ |  j j   n  d |  j k r |  j j d } n |  j d } |  j j d t |  j  | d d x t |  j  D]} \ } } d t | d  } | |  j k r| |  j | <qA| d k rd } n d t |  } |  j j | | d | qAWxT t t |  j  d | d  D]2 } y |  j d t |  =Wqt k
 rqXqWd |  j k r;|  j d |  _ n  |  j   t |  _  d S(   sD   
        Update the header keywords to agree with the data.
        NR   i    R   t   afteri   R    (   R@   R(   t	   _has_dataRW   R   R1   R)   t   commentst   setR6   Re   R5   Rf   RX   t	   enumerateR4   R   t   KeyErrorR9   t   _update_uint_scale_keywordsR?   (   RC   t	   old_naxist   bitpix_commentt   naxis_commentt   idxRN   t   naxisnRh   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyRB   6  sB    	'
c         C   so  |  j    d k	 r* |  j    j d k } n t } |  j sW |  j d k r[ |  j d k r[ d S| d k rv |  j    } n  | d k	 r | j d k r |  j s |  j d k r d SxC d d g D]5 } y |  j | =|  j j	   Wq t
 k
 r q Xq W| d k r|  j    } n  | d k	 r1t | j |  j d <n  d |  _ d |  _ |  j d |  _ |  j j d d  |  _ d S(	   s?   
        Delete BSCALE/BZERO from header if necessary.
        t   ui    i   NR   R   R   R    (   t   _dtype_for_bitpixR%   t   kindR?   R.   R=   R>   R0   R(   R+   Rm   R   R!   R2   R3   R6   t   popR9   (   RC   R\   t   original_was_unsignedt   keyword(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR[   y  s2    	
		t   oldc         C   s,   |  j  d | d | d | d | d d  d S(   so  
        Scale image data by using ``BSCALE``/``BZERO``.

        Call to this method will scale `data` and update the keywords of
        ``BSCALE`` and ``BZERO`` in the HDU's header.  This method should only
        be used right before writing to the output file, as the data will be
        scaled and is therefore not very usable after the call.

        Parameters
        ----------
        type : str, optional
            destination data type, use a string representing a numpy
            dtype name, (e.g. ``'uint8'``, ``'int16'``, ``'float32'``
            etc.).  If is `None`, use the current data type.

        option : str, optional
            How to scale the data: ``"old"`` uses the original ``BSCALE`` and
            ``BZERO`` values from when the data was read/created (defaulting to
            1 and 0 if they don't exist). For integer data only, ``"minmax"``
            uses the minimum and maximum of the data to scale. User-specified
            ``bscale``/``bzero`` values always take precedence.

        bscale, bzero : int, optional
            User-specified ``BSCALE`` and ``BZERO`` values
        t   typet   optiont   bscalet   bzerot   blankN(   t   _scale_internalR%   (   RC   R{   R|   R}   R~   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyt   scale  s    i    c         C   s]  |  j  d k r d S| d k r/ t |  j } n  t t |  } | d k	 re | d k	 re | } | } n-| d k	 r | } d } n| d k	 r d } | } n | d k r |  j d k	 r |  j d k	 r |  j } |  j } n | d k rt | t j	  rt j
 j |  j  j  }	 t j j |  j  j  }
 | t j k rO|	 } |
 |	 d } q|
 |	 d } d |   j } |
 |	 d | d } n d } d } | d k rt j |  j  | d	 |  j  d
 d | |  j d <n" y |  j d =Wn t k
 rn X| r%| d k r%|  j  | |  _  | |  j d <n" y |  j d =Wn t k
 rFn X| d k	 rt | t j  r| |  j  t j |  j   <| |  j d <n  |  j  j j | k rt j t j |  j   d | |  _  n  t |  j  j j |  _ |  j j d d  |  _ |  j j d d  |  _ | |  _ |  j |  j d <|  j |  _ |  j |  _ |  j |  _ |  j |  _  d S(   s  
        This is an internal implementation of the `scale` method, which
        also supports handling BLANK properly.

        TODO: This is only needed for fixing #3865 without introducing any
        public API changes.  We should support BLANK better when rescaling
        data, and when that is added the need for this internal interface
        should go away.

        Note: the default of ``blank=0`` merely reflects the current behavior,
        and is not necessarily a deliberate choice (better would be to disallow
        conversion of floats to ints without specifying a BLANK if there are
        NaN/inf values).
        Ni    i   Rz   t   minmaxg       @i   i   t   outt   castingt   unsafeR   R   R    R\   R   g      p@g     o@(!   R   R%   R   R6   t   getattrR_   R>   R=   t
   issubclasst   floatingt   minimumt   reducet   flatt   maximumt   uint8t   itemsizet   addR(   Rm   t   integert   isnanR\   R{   Ra   t   aroundR   R!   R1   R2   R3   R9   R;   R<   (   RC   R{   R|   R}   R~   R   t   _typet   _scalet   _zerot   mint   maxt   nbytes(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR     sr    				#'	t   warnc         C   s*   |  j    |  j   t t |   j |  S(   N(   RB   R:   R#   R   t   _verify(   RC   R|   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR   6  s    

c         C   s   |  j  d  k r d  Sg  } t |  j   sM | j d j |  j    d  |  _  n  |  j d k su | j d  d  |  _  n  x | D] } t j | t  q| Wd  S(   Ns   Invalid value for 'BLANK' keyword in header: {0!r} The 'BLANK' keyword must be an integer.  It will be ignored in the meantime.i    s|   Invalid 'BLANK' keyword in header.  The 'BLANK' keyword is only applicable to integer data, and will be ignored in this HDU.(	   R9   R%   R   R+   Rd   R6   t   warningsR   R	   (   RC   t   messagest   msg(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR:   >  s    c         C   sh   |  j  r) |  j t |  j d |  j n  |  j   | rO |  j rO |  j } n  t t	 |   j
 | |  S(   NR   (   R0   R   R   R;   R<   RB   RA   R   R#   R   t   _prewriteto(   RC   t   checksumt   inplacet   _(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR   X  s    	
c         C   s>  d } |  j  d  k	 r:t j d k r- d } n d } t |  j  j  r t j |  j  t |  j  j  d d j	 |  j  j j
  } t } n% |  j  } | j j d } | | k } | j s#| r| j j r | j t  z | j |  Wd  | j t  Xq | j | j t   q#| j |  n  | | j | j
 7} n  | S(	   Ni    t   littlet   <t   =R\   s   >i{}(   R   R   (   R   (   R   R%   t   syst	   byteorderR   R\   R_   Ra   R   Rd   R   R?   R4   t   simulateonlyt   flagst	   writeablet   byteswapR*   t
   writearrayt   size(   RC   t   fileobjR   t
   swap_typest   outputt   should_swapR   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyt   _writedata_internale  s0    				c         C   s   |  j  } |  j r |  j d k r xt d t j d  f d t j d  f d t j d  f f D]3 \ } } | | k r^ |  j d | d >k r^ | Sq^ Wn  | d k r t j d  S| d	 k r t j d
  Sd S(   s   
        Determine the dtype that the data should be converted to depending on
        the BITPIX value in the header, and possibly on the BSCALE value as
        well.  Returns None if there should not be any change.
        i   i   t   uint16i    t   uint32i@   t   uint64t   float64i    t   float32N(   R;   R/   R>   R_   R\   R=   (   RC   t   bitpixt   bitsR\   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyRu     s    	"#c         C   sl   |  j    } | d k	 rh | j d k rh | j d } t j | d | } | t j d | d > 8} | Sd S(   sW  
        Handle "pseudo-unsigned" integers, if the user requested it.  Returns
        the converted data array if so; otherwise returns None.

        In this case case, we don't need to handle BLANK to convert it to NAN,
        since we can't do NaNs with integers, anyway, i.e. the user is
        responsible for managing blanks.
        Rt   i   R\   i   N(   Ru   R%   Rv   R   R_   Ra   R   (   RC   R   R\   R   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyt   _convert_pseudo_unsigned  s    
c         C   s5  t  |  j } |  j | | |  } | j j d  | _ |  j sm |  j d k rq |  j d k rq |  j d k rq | Sy |  j
 j r t d   n  Wn t k
 r n Xd } |  j d k o |  j d k s |  j |  } n  | d k r1d } |  j d k	 rM|  j d k rM| j |  j k } | j   t |  d k  rMt j |  } qMn  |  j   } | d k	 r}t j | d | } nK |  j
 d k	 r|  j
 j r| j   } n! | j j s| j   } n | } ~ |  j d k rt j | |  j |  n  |  j d k r| |  j 7} n  |  j r1t j | j | <q1n  | S(   s   
        Internal function for reading image data from a file and apply scale
        factors to it.  Normally this is used for the entire image, but it
        supports alternate offset/shape for Section support.
        t   >i    i   s`   Cannot load a memory-mapped image: BZERO/BSCALE/BLANK header keywords present. Set memmap=False.i   R\   N(   R   R;   t   _get_raw_dataR\   t   newbyteorderR.   R=   R>   R9   R%   t   _filet   strict_memmapR'   t   AttributeErrorR   R6   R   t   sumRX   R_   t   whereRu   Ra   t   memmapR,   R   R   t   multiplyt   nan(   RC   t   offsetRW   t   codet   raw_dataR   t   blankst	   new_dtype(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyRY     sJ    		c         C   s#  |  j  j } |  j rV |  j d k r- d } q |  j j j } | | j d  d } n |  j r~ t	 |  j  r~ t
 |  j } n d } | r |  j r |  j d k s |  j d k r |  j   } | d k	 r | d j | j  7} q n  t t |  j   } |  j |  j | t |  j  | | d f S(   sC   
        Summarize the HDU: name, dimensions, and formats.
        t    t   .i   i    s    (rescales to {0})N(   t	   __class__t   __name__t   _data_loadedR   R%   R\   R!   t   rfindRW   t   allR   R6   R.   R>   R=   Ru   Rd   RU   RV   t   verRX   R(   (   RC   t
   class_nameRd   R   RW   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyt   _summary  s     		c         C   si  |  j  rL|  j } t |  j j  ra t j |  j t |  j j  d d j |  j j j  } n  | j j	 d d k r | j
 j r t } | j t  } | j j d  | _ q | j t  } | j j d  | _ t } n t } |  j | j   j t j  d | } | rHt |  j j  rH| j t  | j j d  | _ n  | St t |   j d |  Sd S(   sJ   
        Calculate the value for the ``DATASUM`` card in the HDU.
        R\   s   i{}i    R   t   blockingR   N(   Ri   R   R   R\   R_   Ra   R   Rd   R   R4   R   R   R*   R   R   R?   t   _compute_checksumt   flattent   viewR   R#   R   t   _calculate_datasum(   RC   R   t   dt   byteswappedt   cs(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR   &  s,    				N(   R   t
   __module__t   __doc__R)   R%   R?   R*   R$   t   classmethodRQ   t   propertyRR   RT   RW   R   t   setterR   R   RB   R[   R   R   R   R:   R   R   Ru   R   RY   R   R   (    (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR      sB   

			>	C5h		*			I	!RS   c           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s  
    Image section.

    Slices of this object load the corresponding section of an image array from
    the underlying FITS file on disk, and applies any BSCALE/BZERO factors.

    Section slices cannot be assigned to, and modifications to a section are
    not saved back to the underlying file.

    See the :ref:`data-sections` section of the Astropy documentation for more
    details.
    c         C   s   | |  _  d  S(   N(   t   hdu(   RC   R   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR$   g  s    c         C   s  t  | t  s | f } n  t |  j j  } t d   | D  oR t |  | k } t d   | D  s{ | t f 7} n  t g  | D] } | t k r | ^ q  } t |  | | k s | d k r t d   n  t	 d   t
 | t f  D  } | |  t d   f | t |  d | | d } t d   | D  oTt |  | k } g  } d }	 xl t |  D]^ } |  j j | }
 t | | |
  } |	 |
 | j }	 t | |  sp| j | j  PqpqpW| j } xy t | d |  D]d } |  j j | }
 t | | |
  } | j | j  | j |
 k rM| j rM|	 |
 9}	 qt } qW| rt |  pld	 } |  j j } |  j j |	 t |  d }	 |  j j |	 |  } n |  j |  } | r| j   } n | r| j   } n  | S(
   Nc         s   s'   |  ] } t  | t t j f  Vq d  S(   N(   R&   t   intR_   R   (   t   .0t   k(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pys	   <genexpr>n  s    c         s   s   |  ] } | t  k Vq d  S(   N(   t   Ellipsis(   R   R   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pys	   <genexpr>p  s    i   s   too many indices for arrayc         s   s'   |  ] \ } } | t  k r | Vq d  S(   N(   R   (   R   t   iR   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pys	   <genexpr>x  s    c         s   s'   |  ] } t  | t t j f  Vq d  S(   N(   R&   R   R_   R   (   R   R   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pys	   <genexpr>z  s    i    i   (   i   (   R&   RU   RX   R   RW   R   t   anyR   t
   IndexErrort   nextRl   t   sliceR%   R   t
   _IndexInfoR   R   R+   t   nptst
   contiguousR?   R;   RZ   t   absRY   t   _getdatat   itemt   squeeze(   RC   t   keyt   naxist   return_scalarR   t   ellipsis_countRr   t   return_0dimt   dimsR   RN   t   indxt   is_contiguoust   jdxR   R   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyt   __getitem__j  sT    +"#5	
c   	      C   s  x t  t | |  j j   D]c \ } \ } } t | t  rV t | j |    } Pq t |  r t	 j
 | d t | } Pq q Wg  | D]' } |  | |  | f | | d ^ q } t d   | | d D  r t	 j |  St	 j g  | D] } t	 j |  ^ q  Sd  S(   NR\   i   c         s   s*   |  ]  } t  | t  p! t |  Vq d  S(   N(   R&   R   R   (   R   R   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pys	   <genexpr>  s   (   Rl   R   R   RW   R&   R   R   t   indicesR   R_   t   arangeR   R   Ra   t   concatenatet
   atleast_1d(	   RC   t   keysRr   R   RN   t   ksR   R   Ra   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR     s    .4	(   R   R   R   R$   R   R   (    (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyRS   Y  s   		7t
   PrimaryHDUc           B   sS   e  Z d  Z d Z d d e e e d d  Z e d    Z	 d   Z
 d d  Z RS(   s!   
    FITS primary HDU class.
    t   PRIMARYc         C   s   t  t |   j d | d | d | d | d | d |  | d k r |  j d } | d k re d	 } n  |  j j d
 t d d t |  n  d S(   s  
        Construct a primary HDU.

        Parameters
        ----------
        data : array or DELAYED, optional
            The data in the HDU.

        header : Header instance, optional
            The header to be used (as a template).  If ``header`` is `None`, a
            minimal header will be provided.

        do_not_scale_image_data : bool, optional
            If `True`, image data is not scaled using BSCALE/BZERO values
            when read. (default: False)

        ignore_blank : bool, optional
            If `True`, the BLANK header keyword will be ignored if present.
            Otherwise, pixels equal to this value will be replaced with
            NaNs. (default: False)

        uint : bool, optional
            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.
            (default: True)

        scale_back : bool, optional
            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.  Pseudo-unsigned integers are automatically
            rescaled unless scale_back is explicitly set to `False`.
            (default: None)
        R   R   RD   RE   RG   RF   R   i    R   t   EXTENDRh   N(   R#   R  R$   R%   R(   Rk   R*   R4   (   RC   R   R   RD   RG   RE   RF   t   dim(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR$     s    )	c         C   s?   | j  d } | j d k o> d | k s8 | d t k o> | j S(   Ni    R   R   (   RJ   Ry   R*   t   value(   RP   R   t   card(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyRQ     s    c         C   sp   t  t |   j   d |  j k rl t |  j  rM d t t |  j   } n d } |  j j d d | n  d  S(   NR  R   Rh   (   R#   R  RB   R(   RX   R5   R4   Rk   (   RC   Rh   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyRB     s    R   c         C   si   t  t |   j d |  } d |  j k re |  j j d d  } |  j d | d d   t | |  n  | S(   NR|   R  R   i    i   c         S   s   t  |  t  S(   N(   R&   t   bool(   t   v(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyt   <lambda>  s    (   R#   R  R   R(   R1   t	   req_cardsR*   (   RC   R|   t   errsR   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR     s    N(   R   R   R   t   _default_nameR%   R?   R*   R$   R   RQ   RB   R   (    (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR    s   	4		t   ImageHDUc           B   sJ   e  Z d  Z d Z d d d e e d d  Z e d    Z	 d d  Z
 RS(   s)   
    FITS image extension HDU class.
    R   c         C   s;   t  t |   j d | d | d | d | d | d |  d S(   s  
        Construct an image HDU.

        Parameters
        ----------
        data : array
            The data in the HDU.

        header : Header instance
            The header to be used (as a template).  If ``header`` is
            `None`, a minimal header will be provided.

        name : str, optional
            The name of the HDU, will be the value of the keyword
            ``EXTNAME``.

        do_not_scale_image_data : bool, optional
            If `True`, image data is not scaled using BSCALE/BZERO values
            when read. (default: False)

        uint : bool, optional
            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.
            (default: True)

        scale_back : bool, optional
            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.  Pseudo-unsigned integers are automatically
            rescaled unless scale_back is explicitly set to `False`.
            (default: None)
        R   R   R!   RD   RE   RF   N(   R#   R  R$   (   RC   R   R   R!   RD   RE   RF   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR$     s    *c         C   sP   | j  d } | j } t | t  r4 | j   } n  | j d k oO | |  j k S(   Ni    R   (   RJ   R  R&   R
   t   rstripRy   t
   _extension(   RP   R   R  t   xtension(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyRQ   L  s
    	R   c         C   sW   t  t |   j d |  } |  j j d d  } |  j d | d d   d | |  | S(   s)   
        ImageHDU verify method.
        R|   R   i    R   i   c         S   s   t  |   o |  d k S(   Ni    (   R   (   R	  (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR
  ^  s    (   R#   R  R   R(   R1   R  (   RC   R|   R  R   (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR   T  s
    N(   R   R   R   R  R%   R?   R*   R$   R   RQ   R   (    (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR    s   	.R   c           B   s   e  Z d    Z RS(   c         C   s   t  |  r^ d | k o# | k  n rF d |  _ | |  _ t |  _ q t d j |    n t | t  r | j	 |  \ } } } | | | |  _ | |  _ | d k |  _ nE t
 |  r t |  |  _ d |  _ t |  _ n t d j |    d  S(   Ni    i   s   Index {} out of range.s   Illegal index {}(   R   R   R   R*   R   R   Rd   R&   R   R   R   RX   R?   (   RC   R   R   t   startt   stopt   step(    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR$   d  s     				(   R   R   R$   (    (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyR   c  s   (    R   R   t   numpyR_   t   baseR    R   R   R   R   R   R   t   utilR   R   R   t   verifyR	   t
   extern.sixR
   t   extern.six.movesR   R   t   utilsR   R   R   t   objectRS   R  R  R   (    (    (    s8   lib/python2.7/site-packages/astropy/io/fits/hdu/image.pyt   <module>   s"   (   J^_M