
[c        	   @   s7  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m	 Z	 d  d l
 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 m Z m Z m Z m Z d d	 l m Z m Z d
 d l m Z m  Z  m! Z! d
 d l" m# Z# m$ Z$ d
 d l% m& Z& m' Z' m( Z( d
 d l) m* Z* d d d g Z+ i
 d d 6d d 6d d 6d d 6d d 6d d 6d d 6d  d! 6d" d# 6d$ d% 6Z, d&   e  e,  D Z- d e- d' <d e- d( <d e- d) <d e- d* <d e- d+ <d d d d d d d# d% g Z. i d d 6d# d! 6Z/ i d$ d% 6d d 6d d 6d d, 6d d 6d d 6Z0 i d- d% 6d. d 6d. d 6d/ d, 6d d 6d d 6Z1 i d d0 f d% 6d1 d0 f d 6d2 d0 f d 6d2 d3 f d 6d4 d3 f d, 6d5 d6 f d 6Z2 d7 d8 d9 d: d; d< d= d> d? f	 Z3 d@ dA dB dC dD dE dF dG dH f	 Z4 e	 e$ e3 e4   Z5 e	 e$ e4 e3   Z6 e j7 dI e j8  Z9 e j7 dJ  Z: e j7 dK  Z; e j7 dL  Z< e j7 dM  Z= d0 Z> dN Z? d e@ f dO     YZA dP eB f dQ     YZC dR eC f dS     YZD dT eC f dU     YZE dV eB f dW     YZF dX eB f dY     YZG dZ eG f d[     YZH d\ e@ f d]     YZI d e f d^     YZJ d e f d_     YZK d` eK f da     YZL db e jM f dc     YZN dd   ZO de   ZP df   ZQ eR dg  ZS dh   ZT eU di  ZV dj   ZW dk   ZX dl   ZY dm   ZZ dn   Z[ do   Z\ eU dp  Z] eU dq  Z^ d S(r   iN(   t   reduce(   t   OrderedDict(   t   chari   (   t   _numpy_hacks(   t   Cardt   CARD_LENGTH(   t   pairwiset   _is_intt   _convert_arrayt   encode_asciit   cmpt   NotifierMixin(   t   VerifyErrort   VerifyWarningi   (   t   string_typest	   iteritemst   PY2(   t   ranget   zip(   t   lazypropertyt
   isiterablet   indent(   t   suppresst   Columnt   ColDefst   Delayedt   i1t   Lt   u1t   Bt   i2t   It   i4t   Jt   i8t   Kt   f4t   Et   f8t   Dt   c8t   Ct   c16t   Mt   at   Ac         C   s   i  |  ] \ } } | |  q S(    (    (   t   .0t   keyt   val(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pys
   <dictcomp>-   s   	 t   b1t   u2t   u4t   u8t   f2t   Ft    t   dt   fi    i
   i   i   i   i   i   t   TTYPEt   TFORMt   TUNITt   TNULLt   TSCALt   TZEROt   TDISPt   TBCOLt   TDIMt   namet   formatt   unitt   nullt   bscalet   bzerot   dispt   startt   dims@   (?P<repeat>^[0-9]*)(?P<format>[LXBIJKAEDCMPQ])(?P<option>[!-~]*)sl   (?:(?P<format>[AIJ])(?P<width>[0-9]+)?)|(?:(?P<formatf>[FED])(?:(?P<widthf>[0-9]+)\.(?P<precision>[0-9]+))?)s   [0-9a-zA-Z_]+s)   (?P<label>^T[A-Z]*)(?P<num>[1-9][0-9 ]*$)s)   \(\s*(?P<dims>(?:\d+,\s*)+\s*\d+)\s*\)\s*s   ---c           B   s&   e  Z d  Z d d d  Z d   Z RS(   s   Delayed file-reading data.c         C   s   t  j |  |  _ | |  _ d  S(   N(   t   weakreft   proxyt   hdut   field(   t   selfRN   RO   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __init__   s    c         C   s   |  j  j | |  j S(   N(   RN   t   dataRO   (   RP   R/   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __getitem__   s    N(   t   __name__t
   __module__t   __doc__t   NoneRQ   RS   (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR      s   t   _BaseColumnFormatc           B   s>   e  Z d  Z d   Z d   Z e d    Z e d    Z RS(   s   
    Base class for binary table column formats (just called _ColumnFormat)
    and ASCII table column formats (_AsciiColumnFormat).
    c         C   sm   | s
 t  St | t  rY t | |  j  s] y |  j |  } WqV t k
 rR t  SXq] n t  S|  j | j k S(   N(   t   Falset
   isinstancet   strt	   __class__t
   ValueErrort	   canonical(   RP   t   other(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __eq__   s    c         C   s   t  |  j  S(   N(   t   hashR^   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __hash__   s    c         C   s   t  j |  j  S(   sX   
        The Numpy dtype object created from the format's associated recformat.
        (   t   npt   dtypet	   recformat(   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRd      s    c         C   s   |  j  | j  S(   s  Creates a column format object from another column format object
        regardless of their type.

        That is, this can convert a _ColumnFormat to an _AsciiColumnFormat
        or vice versa at least in cases where a direct translation is possible.
        (   t   from_recformatRe   (   t   clsRD   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   from_column_format   s    	(	   RT   RU   RV   R`   Rb   R   Rd   t   classmethodRh   (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRX      s
   		t   _ColumnFormatc           B   sD   e  Z d  Z d   Z e d    Z e d    Z e d    Z RS(   s  
    Represents a FITS binary table column format.

    This is an enhancement over using a normal string for the format, since the
    repeat count, format code, and option are available as separate attributes,
    and smart comparison is used.  For example 1J == J.
    c         C   s   t  t |   j |  |  } t |  \ | _ | _ | _ | j j   | _ | j d k r | j d k r{ t j	 |  } n t
 j	 |  } | j | _ n	 d  | _ | S(   Nt   Pt   Q(   Rk   Rl   (   t   superRj   t   __new__t   _parse_tformatt   repeatRD   t   optiont   uppert   _FormatPt
   from_tformt   _FormatQt   p_formatRW   (   Rg   RD   RP   Re   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRn      s    	c         C   s   |  t  | d t  S(   s9   Creates a column format from a Numpy record dtype format.t   reverse(   t   _convert_formatt   True(   Rg   Re   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRf      s    c         C   s
   t  |   S(   s2   Returns the equivalent Numpy record format string.(   Rx   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRe      s    c         C   s@   |  j  d k r d } n t |  j   } d j | |  j |  j  S(   s*  
        Returns a 'canonical' string representation of this format.

        This is in the proper form of rTa where T is the single character data
        type code, a is the optional part, and r is the repeat.  If repeat == 1
        (the default) it is left out of this representation.
        i   R7   s   {}{}{}(   Rp   R[   RD   Rq   (   RP   Rp   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR^      s    
	(	   RT   RU   RV   Rn   Ri   Rf   R   Re   R^   (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRj      s
   	t   _AsciiColumnFormatc           B   sV   e  Z d  Z e d  Z e d    Z e d    Z e d    Z	 e d    Z
 RS(   sj  Similar to _ColumnFormat but specifically for columns in ASCII tables.

    The formats of ASCII table columns and binary table columns are inherently
    incompatible in FITS.  They don't support the same ranges and types of
    values, and even reuse format codes in subtly different ways.  For example
    the format code 'Iw' in ASCII columns refers to any integer whose string
    representation is at most w characters wide, so 'I' can represent
    effectively any integer that will fit in a FITS columns.  Whereas for
    binary tables 'I' very explicitly refers to a 16-bit signed integer.

    Conversions between the two column formats can be performed using the
    ``to/from_binary`` methods on this class, or the ``to/from_ascii``
    methods on the `_ColumnFormat` class.  But again, not all conversions are
    possible and may result in a `ValueError`.
    c         C   sI   t  t |   j |  |  } t | |  \ | _ | _ | _ t | _ | S(   N(	   Rm   Rz   Rn   t   _parse_ascii_tformatRD   t   widtht	   precisionRY   t   _pseudo_logical(   Rg   RD   t   strictRP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRn   
  s    !	c         C   s1   |  j  | j  } | j d k r- t | _ n  | S(   NR   (   Rf   Re   RD   Ry   R~   (   Rg   RD   t   inst(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRh     s    c         C   s   |  t  | d t  S(   s9   Creates a column format from a Numpy record dtype format.Rw   (   t   _convert_ascii_formatRy   (   Rg   Re   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRf     s    c         C   s
   t  |   S(   s2   Returns the equivalent Numpy record format string.(   R   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRe   "  s    c         C   sA   |  j  d k r+ d j  |  j  |  j |  j  Sd j  |  j  |  j  S(   sO  
        Returns a 'canonical' string representation of this format.

        This is in the proper form of Tw.d where T is the single character data
        type code, w is the width in characters for this field, and d is the
        number of digits after the decimal place (for format codes 'E', 'F',
        and 'D' only).
        R%   R6   R'   s   {}{}.{}s   {}{}(   R%   R6   R'   (   RD   R|   R}   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR^   (  s    (   RT   RU   RV   RY   Rn   Ri   Rh   Rf   R   Re   R^   (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRz      s   
t   _FormatXc           B   s2   e  Z d  Z d d  Z d   Z e d    Z RS(   s   For X format in binary tables.i   c         C   sG   | d d d } t  t |   j |  t | f  d  } | | _ | S(   Ni   i   R   (   Rm   R   Rn   t   reprRp   (   Rg   Rp   t   nbytest   obj(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRn   <  s    (	c         C   s
   |  j  f S(   N(   Rp   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __getnewargs__C  s    c         C   s   d j  |  j  S(   Ns   {}X(   RD   Rp   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   tformF  s    (   RT   RU   RV   Rn   R   t   propertyR   (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR   9  s   	Rs   c           B   sn   e  Z d  Z d Z d Z e j e j e   Z d Z	 d d d  Z d   Z e d    Z e d    Z RS(	   s&   For P format in variable length table.s?   (?P<repeat>\d+)?{}(?P<dtype>[LXBIJKAEDCM])(?:\((?P<max>\d*)\))?Rk   t   2i4c         C   sJ   t  t |   j |  |  j  } t | | _ | | _ | | _ | | _ | S(   N(	   Rm   Rs   Rn   t   _descriptor_formatt
   NUMPY2FITSRD   Rd   Rp   t   max(   Rg   Rd   Rp   R   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRn   Y  s    			c         C   s   |  j  |  j |  j f S(   N(   Rd   Rp   R   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR   a  s    c         C   s   |  j  j |  } | s. | j d  t k rF t d j |    n  | j d  } | j d  } | j d  } | s d  } n  |  t | d | d | S(   NRd   s   Invalid column format: {}Rp   R   (   t
   _format_ret   matcht   groupt
   FITS2NUMPYR   RD   RW   (   Rg   RD   t   mRp   t   array_dtypeR   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRt   d  s    	c         C   sX   |  j  d  k r d n |  j  } |  j d  k r3 d n |  j } d j | |  j |  j |  S(   NR7   s
   {}{}{}({})(   Rp   RW   R   RD   t   _format_code(   RP   Rp   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR   p  s    N(   RT   RU   RV   t   _format_re_templateR   t   ret   compileRD   R   R   RW   Rn   R   Ri   Rt   R   R   (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRs   N  s   	Ru   c           B   s5   e  Z d  Z d Z e j e j j e   Z	 d Z
 RS(   s   Carries type description of the Q format for variable length arrays.

    The Q format is like the P format but uses 64-bit integers in the array
    descriptors, allowing for heaps stored beyond 2GB into a file.
    Rl   t   2i8(   RT   RU   RV   R   R   R   Rs   R   RD   R   R   (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRu   w  s   t   ColumnAttributec           B   s>   e  Z d  Z d   Z d d  Z d   Z d   Z d   Z RS(   s>  
    Descriptor for attributes of `Column` that are associated with keywords
    in the FITS header and describe properties of the column as specified in
    the FITS standard.

    Each `ColumnAttribute` may have a ``validator`` method defined on it.
    This validates values set on this attribute to ensure that they meet the
    FITS standard.  Invalid values will raise a warning and will not be used in
    formatting the column.  The validator should take two arguments--the
    `Column` it is being assigned to, and the new value for the attribute, and
    it must raise an `AssertionError` if the value is invalid.

    The `ColumnAttribute` itself is a decorator that can be used to define the
    ``validator`` for each column attribute.  For example::

        @ColumnAttribute('TTYPE')
        def name(col, name):
            if not isinstance(name, str):
                raise AssertionError

    The actual object returned by this decorator is the `ColumnAttribute`
    instance though, not the ``name`` function.  As such ``name`` is not a
    method of the class it is defined in.

    The setter for `ColumnAttribute` also updates the header of any table
    HDU this column is attached to in order to reflect the change.  The
    ``validator`` should ensure that the value is valid for inclusion in a FITS
    header.
    c         C   s*   | |  _  d  |  _ d t |  j  |  _ d  S(   Nt   _(   t   _keywordRW   t
   _validatort   KEYWORD_TO_ATTRIBUTEt   _attr(   RP   t   keyword(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRQ     s    		c         C   s$   | d  k r |  St | |  j  Sd  S(   N(   RW   t   getattrR   (   RP   R   t   objtype(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __get__  s    c         C   sn   |  j  d  k	 r" |  j  | |  n  t | |  j d   } t | |  j |  | j d | |  j d | |  d  S(   Nt   column_attribute_changedi   (   R   RW   R   R   t   setattrt   _notify(   RP   R   t   valuet	   old_value(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __set__  s    c         C   s   | |  _  |  S(   s   
        Set the validator for this column attribute.

        Returns ``self`` so that this can be used as a decorator, as described
        in the docs for this class.
        (   R   (   RP   t   func(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __call__  s    	c         C   s   d j  |  j j |  j  S(   Ns
   {0}('{1}')(   RD   R\   RT   R   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __repr__  s    N(	   RT   RU   RV   RQ   RW   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s   	
			c           B   s  e  Z d  Z d d d d d d d d d d d d  Z d   Z d   Z d   Z e d    Z	 e	 j
 d    Z	 e	 j d    Z	 e d  d	    Z e d
  Z e d  Z e d  Z e d  Z e d  Z e d  Z e d  Z e d  Z e d    Z e d    Z d   Z e d    Z e d d d d d d d d d d d 
  Z e d    Z e d    Z d   Z  RS(   s   
    Class which contains the definition of one column, e.g.  ``ttype``,
    ``tform``, etc. and the array containing values for the column.
    c         C   sC  | d
 k r t d   n  i | d 6} x@ t D]8 } t   | } t | t  r] | j } n  | | | <q/ W|  j |   \ } } | r d g } x+ | j   D] } | j	 t
 | d   q Wt d j |    n  x' t D] } t |  | | j |   q W| d } |  j |  _ |	 |  _ t |  _ t |
 t j t j t f  sy" |
 d
 k	 rft j |
  }
 n  Wqt k
 ry) t | d  } t j |
 d | }
 Wqt k
 rt | t  rt |
 d | j }
 qt d	 j |    qXqXn  |  j |
  }
 t |
 t j  r$t |  _  n	 t |  _  d
 |  _! |
 |  _ d
 S(   s  
        Construct a `Column` by specifying attributes.  All attributes
        except ``format`` can be optional; see :ref:`column_creation` and
        :ref:`creating_ascii_table` for more information regarding
        ``TFORM`` keyword.

        Parameters
        ----------
        name : str, optional
            column name, corresponding to ``TTYPE`` keyword

        format : str
            column format, corresponding to ``TFORM`` keyword

        unit : str, optional
            column unit, corresponding to ``TUNIT`` keyword

        null : str, optional
            null value, corresponding to ``TNULL`` keyword

        bscale : int-like, optional
            bscale value, corresponding to ``TSCAL`` keyword

        bzero : int-like, optional
            bzero value, corresponding to ``TZERO`` keyword

        disp : str, optional
            display format, corresponding to ``TDISP`` keyword

        start : int, optional
            column starting position (ASCII table only), corresponding
            to ``TBCOL`` keyword

        dim : str, optional
            column dimension corresponding to ``TDIM`` keyword

        array : iterable, optional
            a `list`, `numpy.ndarray` (or other iterable that can be used to
            initialize an ndarray) providing initial data for this column.
            The array will be automatically converted, if possible, to the data
            format of the column.  In the case were non-trivial ``bscale``
            and/or ``bzero`` arguments are given, the values in the array must
            be the *physical* values--that is, the values of column as if the
            scaling has already been applied (the array stored on the column
            object will then be converted back to its storage values).

        ascii : bool, optional
            set `True` if this describes a column for an ASCII table; this
            may be required to disambiguate the column format
        s(   Must specify format to construct Column.t   asciis7   The following keyword arguments to Column were invalid:i   s   
Re   t   itemsizeRd   s*   Data is inconsistent with the format `{}`.N("   RW   R]   t   KEYWORD_ATTRIBUTESt   localsRZ   R   R   t   _verify_keywordst   valuest   appendR   R   t   joinR   t   getRK   t   _dimsRY   t   _pseudo_unsigned_intsRc   t   ndarrayt	   chararrayR   t   arrayt	   Exceptiont   intRs   t   _VLFRd   RD   t   _convert_to_valid_data_typeRy   t   _physical_valuest   _parent_fits_rec(   RP   RC   RD   RE   RF   RG   RH   RI   RJ   RK   R   R   t   kwargst   attrR   t   valid_kwargst   invalid_kwargst   msgR0   Re   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRQ     sP    6	
					c         C   sY   d } xH t  D]@ } t |  |  } | d  k	 r | | d t |  d 7} q q W| d  S(   NR7   s    = s   ; i(   R   R   RW   R   (   RP   t   textR   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR   T  s    #c         C   s:   |  j  j   |  j f } | j  j   | j f } | | k S(   s   
        Two columns are equal if their name and format are the same.  Other
        attributes aren't taken into account at this time.
        (   RC   t   lowerRD   (   RP   R_   R,   t   b(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR`   \  s    c         C   s   t  |  j j   |  j f  S(   s   
        Like __eq__, the hash of a column should be based on the unique column
        name and format, and be case-insensitive with respect to the column
        name.
        (   Ra   RC   R   RD   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRb   g  s    c         C   sW   d |  j  k r |  j  d S|  j d k	 rO |  j   } | d k	 rS | |  j Sn d Sd S(   s  
        The Numpy `~numpy.ndarray` associated with this `Column`.

        If the column was instantiated with an array passed to the ``array``
        argument, this will return that array.  However, if the column is
        later added to a table, such as via `BinTableHDU.from_columns` as
        is typically the case, this attribute will be updated to reference
        the associated field in the table, which may no longer be the same
        array.
        R   N(   t   __dict__R   RW   RC   (   RP   t   parent(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR   p  s    Dc         C   s   | } x t  r t | d  r t | j t  r xa | j D]S } | |  k r: |  j d  k r: t j |  |  _ d |  j	 k r |  j	 d =n  d  Sq: Wn  t
 | d d   d  k	 r | j } q	 Pq	 W| |  j	 d <d  S(   Nt   _coldefsR   t   base(   Ry   t   hasattrRZ   R   R   R   RW   RL   t   refR   R   R   (   RP   R   R   t   col(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s    
	c         C   s/   y |  j  d =Wn t k
 r! n Xd  |  _ d  S(   NR   (   R   t   KeyErrorRW   R   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s
    R:   c         C   s   | d  k r d  St | t  rK t j |  rK t j d j |  t  n  t | t  s| t	 t
 t d |    t k r t d   n  d  S(   Ns   It is strongly recommended that column names contain only upper and lower-case ASCII letters, digits, or underscores for maximum compatibility with other software (got {0!r}).R:   s   Column name must be a string able to fit in a single FITS card--typically this means a maximum of 68 characters, though it may be fewer if the string contains special characters like quotes.(   RW   RZ   R   t   TTYPE_RER   t   warningst   warnRD   R   t   lenR[   R   R   t   AssertionError(   R   RC   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRC     s    !R;   R<   R=   R>   R?   R@   RA   RB   c         C   s   t  |  j t  S(   s=   Whether this `Column` represents an column in an ASCII table.(   RZ   RD   Rz   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s    c         C   s
   |  j  j S(   N(   RD   Rd   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRd     s    c         C   s%   t  d d  } |  j j   | _ | S(   s1   
        Return a copy of this `Column`.
        RD   R   (   R   R   t   copy(   RP   t   tmp(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s    c         C   s   t  |  t  r |  |  j f S|  t k rS t t   |  } | j |   }  Wd QXn  y | |   }  |  j } Wn& t k
 r t d j |     n X|  | f S(   s  The format argument to this class's initializer may come in many
        forms.  This uses the given column format class ``cls`` to convert
        to a format of that type.

        TODO: There should be an abc base class for column format classes
        Ns   Illegal format `{}`.(   RZ   RX   Re   R   R   R   Rf   RD   (   RD   Rg   Re   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRx     s    c         C   s  i  } i  } |  j  | | |	 |
  \ } } | j d | d |  x] d | f d | f d | f d | f g D]1 \ } } | d k	 rk | d k rk | | | <qk qk W| d k	 r| d k rd } t | t  rt |  } t |  | j k rid j |  } qinf t	 |  s!d	 j |  } n  d  } | j | k pQ| j d! k oQ| j
 | k sid j | |  } n  | d k r| | d <q| | f | d <n  | d k	 r.| d k r.d } t | t  sd j |  } n  t | t  r| d j   d k rd } n  | d k r| | d <q.| | f | d <n  | d k	 r| d k rd } t | t  smd j |  } n  y t |  } Wn t t f k
 rn Xt	 |  r| d k  rd j |  } n  | d k r| | d <q| | f | d <n  |	 d k	 r|	 d k rd } t   } t | t  r6d j |	  } n< t |	 t  rTt |	  } n t |	 t  rl|	 } n d } | rt t j |  | j k rd j | | |	  } qn  | d k r| | d <q|	 | f | d <n  | | f S("   s  
        Given the keyword arguments used to initialize a Column, specifically
        those that typically read from a FITS header (so excluding array),
        verify that each keyword has a valid value.

        Returns a 2-tuple of dicts.  The first maps valid keywords to their
        values.  The second maps invalid keywords to a 2-tuple of their value,
        and a message explaining why they were found invalid.
        RD   Re   RC   RE   RG   RH   R7   sn   ASCII table null option (TNULLn) is longer than the column's character width and will be truncated (got {!r}).s   Column null option (TNULLn) must be an integer for binary table columns (got {!r}).  The invalid value will be ignored for the purpose of formatting the data in this column.R   R   R!   R#   Rk   Rl   s   Column null option (TNULLn) is invalid for binary table columns of type {!r} (got {!r}).  The invalid value will be ignored for the purpose of formatting the data in this column.RF   s   Column disp option (TDISPn) must be a string (got {!r}).The invalid value will be ignored for the purpose of formatting the data in this column.i    R   s   Column disp option (TDISPn) may not use the 'L' format with ASCII table columns.  The invalid value will be ignored for the purpose of formatting the data in this column.RI   s   Column start option (TBCOLn) is not allowed for binary table columns (got {!r}).  The invalid keyword will be ignored for the purpose of formatting the data in this column.i   s   Column start option (TBCOLn) must be a positive integer (got {!r}).  The invalid value will be ignored for the purpose of formatting the data in this column.RJ   s   Column dim option (TDIMn) is not allowed for ASCII table columns (got {!r}).  The invalid keyword will be ignored for the purpose of formatting this column.s   `dim` argument must be a string containing a valid value for the TDIMn header keyword associated with this column, or a tuple containing the C-order dimensions for the column.  The invalid value will be ignored for the purpose of formatting this column.s   The repeat count of the column format {!r} for column {!r} is fewer than the number of elements per the TDIM argument {!r}.  The invalid TDIMn value will be ignored for the purpose of formatting this column.RK   N(   R   R   R!   R#   (   Rk   Rl   (   t   _determine_formatst   updateRW   RZ   Rz   R[   R   R|   RD   R   Rv   R   Rr   R   t	   TypeErrorR]   t   tuplet   _parse_tdimR    t   operatort   mulRp   (   Rg   RC   RD   RE   RF   RG   RH   RI   RJ   RK   R   t   validt   invalidRe   t   kt   vR   t   tnull_formatst
   dims_tuple(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR   7  s    			c         C   s   t  | t j  r* t |  \ } } } n  | d k rd t  | t  rd |  j | | |  \ } } nl | r t  | t  r |  j | t  \ } } n: | r t  | t	  r |  j | t	  \ } } n	 | j
 } | | f S(   s  
        Given a format string and whether or not the Column is for an
        ASCII table (ascii=None means unspecified, but lean toward binary table
        where ambiguous) create an appropriate _BaseColumnFormat instance for
        the column's format, and determine the appropriate recarray format.

        The values of the start and dim keyword arguments are also useful, as
        the former is only valid for ASCII tables and the latter only for
        BINARY tables.
        N(   RZ   Rc   Rd   t   _dtype_to_recformatRW   RX   t   _guess_formatRx   Rj   Rz   Re   (   Rg   RD   RJ   RK   R   R   Re   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s    		c         C   s   | r | r t  d   nI | r* t } n: | r9 t } n+ t t   t | d t } Wd  QXt } y |  j | |  \ } } WnA t k
 r | t k r t n t } |  j | |  \ } } n X| | f S(   Ns   Columns cannot have both a start (TCOLn) and dim (TDIMn) option, since the former is only applies to ASCII tables, and the latter is only valid for binary tables.R   (   R]   Rz   Rj   R   R   Ry   Rx   (   Rg   RD   RJ   RK   t   guess_formatRe   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s"    		c   	      C   sy  t  | t  r | S| d  k r# | S|  j } |  j } | r| d | k rQ | d  n | } t |  f | } | j |  } n  d | k s d | k r | Sd | k r| j j d k r | r | d } n t	 j | j
  j } t j | d | St | t	 j | j
   Snhd | k r| j t	 j d  k rYt	 j | t	 j k t d	  t d
   St	 j | d k t d	  t d
   Sn d | k rt | t	 j d   S| j j | j
 } i t	 j d  d 6t	 j d  d 6t	 j d  d 6} | j j d k rV| j j | k rV|  j d k rV|  j | | j j k rV| j d d  } t |  _ n  t	 j |  j } t | |  Sd  S(   NR-   iRk   Rl   t   SUR   R   t   boolR6   t   Ti    t   Xt   uint8i   i   i   i   i?   i   t   ui   R7   t   ii   I       l            (   i   NR7   (   RZ   R   RW   RD   R   R   t   reshapeRd   R   Rc   Re   R   R   R   R   t   wheret   False_t   ordt	   byteordert   uint16t   uint32t   uint64t   kindRG   RH   t   replaceRy   R   R   (	   RP   R   RD   t   dimst   shapet   fsizet   numpy_formatt   bzerosRd   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR   *  sH    		((#N(!   RT   RU   RV   RW   RQ   R   R`   Rb   R   R   t   settert   deleterR   RC   RD   RE   RF   RG   RH   RI   RJ   RK   R   R   Rd   R   t   staticmethodRx   Ri   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s<   				M		%+c           B   s[  e  Z d  Z d Z e Z e d  Z d   Z e d  Z	 d   Z
 d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z d   Z d   Z d   Z d d  Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d  d" d!  Z& RS(#   s  
    Column definitions class.

    It has attributes corresponding to the `Column` attributes
    (e.g. `ColDefs` has the attribute ``names`` while `Column`
    has ``name``). Each attribute in `ColDefs` is a list of
    corresponding attribute values from all `Column` objects.
    s    c         C   sy   |  } t  | d  r3 t | j t  r3 | j } n* t  | d  r] t | j t  r] t } n  | rl t } n  t j |  S(   Nt   _columns_typet   _col_format_cls(	   R   t
   issubclassR   R   R   Rz   t   _AsciiColDefst   objectRn   (   Rg   t   inputR   t   klass(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRn   y  s    		c         C   s
   |  j  f S(   N(   t   _arrays(   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s    c         C   s  d d l  m } d d l m } t | t  r? |  j |  n t | |  ry t | d  ry | j ry |  j | j  n{ t | t	 j
  r | j j d k	 r |  j |  nG t |  r |  j |  n+ t | |  r |  j |  n t d   x |  j D] } | j |   q Wd S(   s:  
        Parameters
        ----------

        input : sequence of `Column`, `ColDefs`, other
            An existing table HDU, an existing `ColDefs`, or any multi-field
            Numpy array or `numpy.recarray`.

        ascii : bool
            Use True to ensure that ASCII table columns are used.

        i   (   t   _TableBaseHDU(   t   FITS_recR   sQ   Input to ColDefs must be a table HDU, a list of Columns, or a record/field array.N(   t	   hdu.tableR  t   fitsrecR  RZ   R   t   _init_from_coldefsR   R   Rc   R   Rd   t   fieldsRW   t   _init_from_arrayR   t   _init_from_sequencet   _init_from_tableR   t   columnst   _add_listener(   RP   R  R   R  R  R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRQ     s     	$c         C   s)   g  | D] } |  j  |  ^ q |  _ d S(   s{   Initialize from an existing ColDefs object (just copy the
        columns and convert their formats if necessary).
        N(   t   _copy_columnR  (   RP   t   coldefsR   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR    s    c         C   sU   xA t  |  D]3 \ } } t | t  s t d j |    q q W|  j |  d  S(   Ns0   Element {} in the ColDefs input is not a Column.(   t	   enumerateRZ   R   R   RD   R  (   RP   R  t   idxR   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR    s
    	c   	      C   s  g  |  _  xt t | j   D]} | j j | } | j j | d } |  j j |  } | j | j d  d  d  } | r t |  d k s d | k r d | k r | j | j	 j
 f | } n  t |  j d d  } n d  } d  } d | k r| t j d  k rt j d  } nf d | k rR| t j d  k rRt j d  } n3 d | k r| t j d  k rt j d  } n  t d | d | d | j t j  | d | d |  } |  j  j |  q Wd  S(   Ni    ii   R-   t    R7   R   R   i   i   R!   R   i   R#   R   i?   RC   RD   R   RH   RK   i   I       l            (   R  R   R   Rd   t   namesR  R   Rf   R   R   R   R   R   RW   Rc   R   R   R   R   t   viewR   R   (	   RP   R   R  t   cnamet   ftypeRD   RK   RH   t   c(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR    s,    	$!!!	c         C   s  | j  } | d } g  t |  D] } i  ^ q  } x t |  D] \ } } t j |  } y | j d  } Wn t k
 r q? n X| t k r? t | j d   }	 |	 | k r |	 d k r t	 | }
 |
 d k r |  j
 |  } n  | | |	 d |
 <q q? q? Wx t |  D] \ } } t j |   \ } } x8 | j   D]* } t j d j | d | d  t  q<W| d =d	 | k r| d	 | d	 <n  | | | <qWx+ t |  D] }	 t | |	  | |	 d
 <qWg  | D] } t |   ^ q|  _ |  j |  d  S(   Nt   TFIELDSt   labelt   numi    RD   i   s!   Invalid keyword for column {}: {}Re   RK   R   (   t   _headerR   R   t   TDEF_RER   R   R   t   KEYWORD_NAMESR   R   R   R  R   R   R   R   R   RD   R   R   R  R  (   RP   t   tablet   hdrt   nfieldsR   t   col_keywordsR   R   R/   R   R   R  R   R   R   R0   t   attrs(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR    s<    	

"c         C   s   |  j  |   S(   N(   R\   (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __copy__  s    c         C   s/   |  j  g  |  j D] } t j | |  ^ q  S(   N(   R\   R  R   t   deepcopy(   RP   t   memoR  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __deepcopy__  s    c         C   s   t  | j |  j  r | j   S| j   } |  j j | j  | _ t  | j t  s| d | _ | j d k	 r d | _ q nN | j d k	 r t	 | _ n  | j
 d k	 r | j
 j   j d  r d | _
 n  | S(   s   Utility function used currently only by _init_from_coldefs
        to help convert columns from binary format to ASCII format or vice
        versa if necessary (otherwise performs a straight copy).
        R   N(   RZ   RD   R   R   Rh   Rz   RW   RJ   RF   t   DEFAULT_ASCII_TNULLRI   Rr   t
   startswith(   RP   t   columnt
   new_column(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR    s    
		c         C   s   | d  } | t  k rr | d d k rr g  } x? |  j D]4 } t | |  } | j | d k	 rc | n d  q6 W| St |   d S(   s   
        Automatically returns the values for the given keyword attribute for
        all `Column`s in this list.

        Implements for example self.units, self.formats, etc.
        it   sR7   N(   R   R  R   R   RW   t   AttributeError(   RP   RC   R  R   R   R0   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __getattr__L  s    
#c         C   s  g  } d g } x t  |  j |  j |  j  D] \ } } } | j } t |  t |  j  k  ry | j | d | j  n  | r | j d k r t	 j | j
 t | d  | d  f  } q t	 j | j | f  } n  t r t |  } n  | j | | f  q+ Wt j t	 j |  |  S(   Ni    iR-   (   R   R  t   formatsR   Rd   R   R   R   RD   Rc   R   R[   R   R   t   nht   realign_dtype(   RP   R  t   offsetsRC   t   format_RK   t   dt(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRd   \  s    	+	-c         C   s   g  |  j  D] } | j ^ q
 S(   N(   R  RC   (   RP   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR    s    c         C   s   g  |  j  D] } | j ^ q
 S(   N(   R  RD   (   RP   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR2    s    c         C   s   g  |  j  D] } | j ^ q
 S(   N(   R  R   (   RP   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR    s    c         C   s   g  |  j  D] } | j ^ q
 S(   N(   R2  Re   (   RP   t   fmt(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   _recformats  s    c         C   s   g  |  j  D] } | j ^ q
 S(   s<   Returns the values of the TDIMn keywords parsed into tuples.(   R  R   (   RP   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s    c         C   sO   t  | t  r$ t |  j |  } n  |  j | } t |  rA | St |  Sd  S(   N(   RZ   R   t
   _get_indexR  R  R   R   (   RP   R/   t   x(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRS     s    c         C   s   t  |  j  S(   N(   R   R  (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __len__  s    c         C   sr   d } t  |  d  rd |  j rd | d 7} | d j g  |  j D] } t |  ^ q;  7} | d 7} n  | d 7} | S(   Ns   ColDefs(R  s   
    s   
t   )(   R   R  R   R   (   RP   t   repR  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s    
/
t   leftc         C   s   t  | t  r | g } n- t  | t  r< t | j  } n t d   | d k rj t |  j  | } n | t |  j  } t |  S(   Ns   Wrong type of input.R?  (   RZ   R   R   t   listR  R   (   RP   R_   Rq   R   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __add__  s    c         C   s   |  j  | d  S(   Nt   right(   RA  (   RP   R_   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __radd__  s    c         C   s   t  | t t f  s! | g } n  g  | D] } t |  j |  ^ q( } t t t |     } x | D] } | j |  qe Wg  | D] } |  | ^ q } t |  S(   N(	   RZ   R@  R   R:  R  R   R   t   removeR   (   RP   R_   R/   t   _othert   indxR;  R   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __sub__  s    %c         C   s   d } x- t  |  j  D] \ } } | | k r Pq q W| d k rK |  ` n | d k r` |  ` n  |  j d | | | | |  d S(   s  
        Handle column attribute changed notifications from columns that are
        members of this `ColDefs`.

        `ColDefs` itself does not currently do anything with this, and just
        bubbles the notification up to any listening table HDUs that may need
        to update their headers, etc.  However, this also informs the table of
        the numerical index of the column that changed.
        i    RC   RD   R   N(   R  R  R  R2  R   (   RP   R-  R   R   t	   new_valueR  R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt    _update_column_attribute_changed  s    		c         C   s}   t  | t  s t  n  |  j j | j  |  ` |  ` |  ` |  `	 |  `
 |  j j |  | j |   |  j d |  |  |  S(   s?   
        Append one `Column` to the column definition.
        t   column_added(   RZ   R   R   R  R   R   Rd   R9  R   R  R2  R  R  R   (   RP   R-  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   add_col  s    	c         C   su   t  |  j |  } |  j | } |  j | =|  ` |  ` |  ` |  ` |  ` |  j | =| j |   |  j	 d |  |  |  S(   s   
        Delete (the definition of) one `Column`.

        col_name : str or int
            The column's name or index
        t   column_removed(
   R:  R  R  R  Rd   R9  R   R2  t   _remove_listenerR   (   RP   t   col_nameRF  R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   del_col  s    

c         C   s   t  |  | | |  d S(   sJ  
        Change an attribute (in the ``KEYWORD_ATTRIBUTES`` list) of a `Column`.

        Parameters
        ----------
        col_name : str or int
            The column name or index to change

        attrib : str
            The attribute name

        new_value : object
            The new value for the attribute
        N(   R   (   RP   RN  t   attribRH  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   change_attrib  s    c         C   sJ   | | k r3 | |  j  k r3 t d j |    n |  j | d |  d S(   s   
        Change a `Column`'s name.

        Parameters
        ----------
        col_name : str
            The current name of the column

        new_name : str
            The new name of the column
        s   New name {} already exists.RC   N(   R  R]   RD   RQ  (   RP   RN  t   new_name(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   change_name,  s    c         C   s   |  j  | d |  d S(   s   
        Change a `Column`'s unit.

        Parameters
        ----------
        col_name : str or int
            The column name or index

        new_unit : str
            The new unit for the column
        RE   N(   RQ  (   RP   RN  t   new_unit(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   change_unit>  s    t   allc         C   sN  | d	 k r t j } n  | j   j   d
 k r9 t } no | j d  } x] t t |   D]I } | | j   j   | | <| | d d k r[ t	 | d  | | <q[ q[ Wi  } x | D] } | r%| t k r | j
 d j |   q n  | j
 d j |   | j
 d j t |  | d    q t |  | d  | | <q W| sJ| Sd	 S(   s  
        Get attribute(s) information of the column definition.

        Parameters
        ----------
        attrib : str
            Can be one or more of the attributes listed in
            ``astropy.io.fits.column.KEYWORD_ATTRIBUTES``.  The default is
            ``"all"`` which will print out all attributes.  It forgives plurals
            and blanks.  If there are two or more attribute names, they must be
            separated by comma(s).

        output : file, optional
            File-like object to output to.  Outputs to stdout by default.
            If `False`, returns the attributes as a `dict` instead.

        Notes
        -----
        This function doesn't return anything by default; it just prints to
        stdout.
        RV  R7   t   ,iR/  s4   '{}' is not an attribute of the column definitions.
s   {}:
s       {}
N(   RV  R7   (   RW   t   syst   stdoutt   stripR   R   t   splitR   R   R@  t   writeRD   R   (   RP   RP  t   outputt   lstR  t   retR   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   infoM  s*    	
&N('   RT   RU   RV   t   _padding_byteRj   R   RY   Rn   R   RQ   R  R  R  R  R'  R*  R  R1  R   Rd   R  R2  R  R9  R   RS   R<  R   RA  RC  RG  RI  RK  RO  RQ  RS  RU  RW   R`  (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR   l  sB   	)			!	2			0	%	
				
						R  c           B   sn   e  Z d  Z d Z e Z e d  Z e d    Z	 e
 d    Z e d    Z d   Z d   Z d   Z RS(	   s(   ColDefs implementation for ASCII tables.R  c         C   s~   t  t |   j |  t | t  s2 |  j   nH x- t | j  D] \ } } | |  j | _ qB W| j	 |  _
 | j |  _ d  S(   N(   Rm   R  RQ   RZ   t   _update_field_metricsR  t   startsR  RJ   t   spanst   _spanst   _width(   RP   R  R   R  R/  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRQ     s    c         C   si   i  } xS t  t |    D]? } d t |  j |  } | |  j | d f | |  j | <q Wt j |  S(   Nt   Si   (   R   R   R[   Rd  Rc  R  Rc   Rd   (   RP   Rd   t   jt	   data_type(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRd     s
    &c         C   s   |  j  S(   s0   A list of the widths of each field in the table.(   Re  (   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRd    s    c         C   s   t  |   d k r g  } n, g  t |  j  D] \ } } | | ^ q+ } | j |  j |  j d d  g  | D] } d t |  ^ qm S(   Ni   iR,   (   R   R   Rc  R   Rf  R[   (   RP   t   widthsR;  t   yt   w(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR9    s
    	,c         C   s$   t  t |   j |  |  j   d  S(   N(   Rm   R  RK  Rb  (   RP   R-  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRK    s    c         C   s$   t  t |   j |  |  j   d  S(   N(   Rm   R  RO  Rb  (   RP   RN  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRO    s    c         C   s   d g t  |  j  } d } x] t |  j  D]L \ } } | j j } | j s] | d | _ n  | j | d } | | | <q, W| |  _ | |  _ d S(   s   
        Updates the list of the start columns, the list of the widths of each
        field, and the total width of each record in the table.
        i    i   N(   R   R  R  RD   R|   RJ   Re  Rf  (   RP   Rd  t   end_colR  R   R|   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRb    s    		(   RT   RU   RV   Ra  Rz   R   Ry   RQ   R   Rd   R   Rd  R9  RK  RO  Rb  (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR    s   
		R   c           B   s,   e  Z d  Z d d  Z d   Z d   Z RS(   s   Variable length field object.R,   c         C   s   | d k rd y, g  | D] } t  j | d d ^ q } Wqd t k
 r` t d j |    qd Xn  t j | d t j } t j j |  d t	 |  f d | d t j } d | _
 | | _ | S(	   sp   
        Parameters
        ----------
        input
            a sequence of variable-sized elements.
        R,   R   i   s"   Inconsistent input data array: {0}Rd   R   t   bufferi    (   R   R   R   R]   RD   Rc   R  R   Rn   R   R   t   element_dtype(   Rg   R  Rd   R;  R,   RP   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRn     s    ,$		c         C   s,   | d  k r d  S| j |  _ | j |  _ d  S(   N(   RW   R   Ro  (   RP   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   __array_finalize__  s    c         C   s   t  | t j  r' | j |  j k r' nc t  | t j  rK | j d k rK n? |  j d k rr t j | d d } n t j | d |  j } t j j |  | |  t	 |  j	 t
 |   |  _	 d S(   sc   
        To make sure the new item has consistent data type to avoid
        misalignment.
        i   R,   R   Rd   N(   RZ   Rc   R   Rd   R   R   Ro  R   t   __setitem__R   R   (   RP   R/   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRq    s    $!(   RT   RU   RV   Rn   Rp  Rq  (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s   	c         C   s  t  |  r t |  } n t | t  r y |  j | j    } Wqt k
 r | j   j   } g  |  D] } | j   j   ^ ql }  |  j |  } | d k r |  j |  } q | d k r t	 d j
 |    q t	 d j
 |    qXn t	 d j
 |    | S(   s  
    Get the index of the ``key`` in the ``names`` list.

    The ``key`` can be an integer or string.  If integer, it is the index
    in the list.  If string,

        a. Field (column) names are case sensitive: you can have two
           different columns called 'abc' and 'ABC' respectively.

        b. When you *refer* to a field (presumably with the field
           method), it will try to match the exact name first, so in
           the example in (a), field('abc') will get the first field,
           and field('ABC') will get the second field.

        If there is no exact name matched, it will try to match the
        name with case insensitivity.  So, in the last example,
        field('Abc') will cause an exception since there is no unique
        mapping.  If there is a field named "XYZ" and no other field
        name is a case variant of "XYZ", then field('xyz'),
        field('Xyz'), etc. will get this field.
    i   i    s   Key '{}' does not exist.s   Ambiguous key name '{}'.s   Illegal key '{!r}'.(   R   R   RZ   R   t   indext   rstripR]   R   t   countR   RD   (   R  R/   RF  t   _keyt   nRt  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR:    s     %c   	   	   C   s   t  j d d d d d d d d g d	 d
 } | d d d } x t |  D]s } | d } t | d d |  } xI t | |  D]8 } t  j |  d | f | | | d  | d | f <q WqL Wd S(   s   
    Unwrap the X format column into a Boolean array.

    Parameters
    ----------
    input
        input ``Uint8`` array of shape (`s`, `nbytes`)

    output
        output Boolean array of shape (`s`, `repeat`)

    repeat
        number of bits
    i   i@   i    i   i   i   i   i   Rd   R   .N(   Rc   R   R   t   mint   bitwise_and(	   R  R]  Rp   t   pow2R   R   t   _mint   _maxRh  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   _unwrapx4  s    -
c   	      C   s  d | d <| d d d } | d | } x t  |  D] } | d } t | d d |  } x~ t  | |  D]m } | | k r t j | d | f d | d | f  n  t j | d | f |  d | f | d | f  qn Wq7 Wt j | d | f | | d | f  d S(   s  
    Wrap the X format column Boolean array into an ``UInt8`` array.

    Parameters
    ----------
    input
        input Boolean array of shape (`s`, `repeat`)

    output
        output ``Uint8`` array of shape (`s`, `nbytes`)

    repeat
        number of bits
    i    .i   i   N(   R   Rw  Rc   t
   left_shiftt   add(	   R  R]  Rp   R   t   unusedR   Rz  R{  Rh  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   _wrapxM  s    

*9c   	      C   sb  d } | s t  |   } n  t d g | d | j } | j d k rO d } n t j g  d | j j } x t |  D] } | t  |   k  r |  | } n/ | j d k r d | j } n d g | j } | j d k r t	 j t
 |  d d | | <n t j | d | j | | <t  | |  | | d f <| | | d f <| t  | |  | 7} qw W| S(   s  
    Construct the P (or Q) format column array, both the data descriptors and
    the data.  It returns the output "data" array of data type `dtype`.

    The descriptor location will have a zero offset for all columns
    after this call.  The final offset will be calculated when the file
    is written.

    Parameters
    ----------
    array
        input object array

    descr_output
        output "descriptor" array of data type int32 (for P format arrays) or
        int64 (for Q format arrays)--must be nrows long in its first dimension

    format
        the _FormatP object representing the format of the variable array

    nrows : int, optional
        number of rows to create in the column; defaults to the number of rows
        in the input array
    i    Rd   R,   i   R  R   N(   R   R   RW   Rd   Rc   R   R   R   R   R   R	   (	   R   t   descr_outputRD   t   nrowst   _offsett   data_outputt   _nbytesR  t   rowval(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   _makepl  s*    	c         C   s   y( t  j |  j    j   \ } } } Wn& t k
 rP t d j |     n X| d k rf d } n t |  } | | j   | f S(   s_   Parse ``TFORMn`` keyword for a binary table into a
    ``(repeat, format, option)`` tuple.
    s   Format {!r} is not recognized.R7   i   (	   t
   TFORMAT_RER   RZ  t   groupsR   R   RD   R   Rr   (   R   Rp   RD   Rq   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRo     s    (	c            s  t  j   j    } | s3 t d j      n  | j d  } | d k r | j d  j   } | j d  } | j d  } | d k s | d k r/| r t d   q | d k r d n | } | d k r d n | } q/nK | j   } | j d	  } | d k r)| r t d   q)d } n  d }   f d
   } | rf| rf| |  | |  } } n% | r{| |  } n t | \ } } | d k rt d j      n  | | k rt d j   |    n  | | | f S(   s   
    Parse the ``TFORMn`` keywords for ASCII tables into a ``(format, width,
    precision)`` tuple (the latter is always zero unless format is one of 'E',
    'F', or 'D').
    s   Format {!r} is not recognized.RD   t   formatft   widthfR}   s7   Format {!r} is not unambiguously an ASCII table format.i    i   R|   c            sI   d } y t  |   }  Wn, t t f k
 rD t | j      n X|  S(   NsM   Format {!r} is not valid--field width and decimal precision must be integers.(   R   R]   R   R   RD   (   R0   R   (   R   (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   convert_int  s    s@   Format {!r} not valid--field width must be a positive integeter.sb   Format {!r} not valid--the number of decimal digits must be less than the format's total width {}.N(	   t   TFORMAT_ASCII_RER   RZ  R   RD   R   RW   Rr   t   ASCII_DEFAULT_WIDTHS(   R   R   R   RD   R|   R}   R  (    (   R   s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR{     sB    	
		c         C   s[   |  o t  j |   } | rT | j d  } t d   | j d  D  d d d  St   S(   s{   Parse the ``TDIM`` value into a tuple (may return an empty tuple if
    the value ``TDIM`` value is empty or invalid).
    R   c         s   s!   |  ] } t  | j    Vq d  S(   N(   R   RZ  (   R.   R8   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pys	   <genexpr>  s    RW  Ni(   t   TDIM_RER   R   R   R[  (   t   tdimR   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s
    *c         C   s   x? t  t t f D]. } y | |   }  PWq t k
 r= q q Xq Wt j |   j } | d } y t | } t j	 | |  SWn" t
 k
 r d t t |    SXd S(   s   
    Given a scalar value or string, returns the minimum FITS column format
    that can represent that value.  'minimum' is defined by the order given in
    FORMATORDER.
    i   R-   N(   R   t   floatt   complexR]   Rc   t   min_scalar_typeR[   R   t   FITSUPCONVERTERSR   R   R   (   R   t   type_t   numpy_dtype_strt   fits_format(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   _scalar_to_format  s    	

c         C   sy   |  d d k rA | d d k rA t  t |  d  t | d   St |  t | }  } t  t j |   t j |   Sd S(   sP   
    Compares two numpy recformats using the ordering given by FORMATORDER.
    i    R,   i   N(   R
   R   R   t   FORMATORDERRr  (   t   f1R5   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   _cmp_recformats,  s     !c         C   s:  t  |   \ } } } | t k r | d k r t | t |  } |  j   d d k r | d k r t | t t |   } q q6d } | d k r t |  } n  | t | } n | d k r t |  } nf | d k r t j |   } nH | d k rt j |   } n* | d k r!d	 } n t	 d
 j
 |     | S(   s9   
    Convert FITS format spec to record format spec.
    R-   i    R7   i   R   Rk   Rl   R6   R&   s   Illegal format `{}`.(   Ro   R   R[   t   lstripR   R   Rs   Rt   Ru   R]   RD   (   RD   Rp   Rd   Rq   t   output_formatt
   repeat_str(    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   _convert_fits2record8  s(    " 	c         C   s/  t  |   \ } } } | j } | j j } | j d k rF | d } n  t |  } t |  } d } | d k r t j | d d j	   }	 |	 d k r |	 } q n  | d k r t
 |  t
 |  }
 t |
  d } nS | t k r| d k r t |  } n d	 } | t | } n t d
 j |     | S(   s9   
    Convert record format spec to FITS format spec.
    t   Ui   i   i    Rd   R"   R,   R-   R7   s   Illegal format `{}`.(   R   R   R   R   R   R[   R   Rc   R   t   prodR   R   R]   RD   (   RD   Re   R   Rd   R   R   Rq   t   ndimsRp   t   nelt   ntotR  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   _convert_record2fits^  s,    	c         C   sr   t  |  t j  s$ t j |   }  n  |  j j } | d k rI d } } n |  j j } | t |  } | | |  f S(   s  
    Utility function for converting a dtype object or string that instantiates
    a dtype (e.g. 'float32') into one of the two character Numpy format codes
    that have been traditionally used by Astropy.

    In particular, use of 'a' to refer to character data is long since
    deprecated in Numpy, but Astropy remains heavily invested in its use
    (something to try to get away from sooner rather than later).
    R  Rg  R,   (   R  Rg  (   RZ   Rc   Rd   R   R   R   R[   (   Rd   R   Re   R   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s    c         C   s   | r t  |   St |   Sd S(   s_   
    Convert FITS format spec to record format spec.  Do the opposite if
    reverse=True.
    N(   R  R  (   RD   Rw   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyRx     s    
c         C   s\  | r t  |   \ } } } | j } | d k r> d t |  St j |  d k rW d S| d k r d t t d | d   } t | t d	 d
  } d	 t |  S| d k rX| d k r d }  n d }  d j d   t |  D  } |  | Snc t	 |   \ }  } } t
 |  } |  d	 k r5| d k r5d } n |  d k rT| t |  7} n  | Sd S(   s6   Convert ASCII table format spec to record format spec.R,   R-   R   t   A1R   i   i   i   R   i    R9   R'   R%   t   .c         s   s   |  ] } t  |  Vq d  S(   N(   R[   (   R.   Rl  (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pys	   <genexpr>  s    i   R   N(   R   R   R[   R   R   R   R   R  R   R{   t   ASCII2NUMPY(   RD   Rw   Re   R   Rd   R   R|   R}   (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyR     s0    		
	(_   R   R   R   RX  R   RL   t	   functoolsR    t   collectionsR   t   numpyRc   R   R   R7   R   R3  t   cardR   R   t   utilR   R   R   R	   R
   R   t   verifyR   R   t
   extern.sixR   R   R   t   extern.six.movesR   R   t   utilsR   R   R   t   utils.compatR   t   __all__R   R   R  R  R  t	   ASCII2STRR  R!  R   R   t   ATTRIBUTE_TO_KEYWORDR   R   R  R  R   R   R  t
   ASCIITNULLR+  R  R   R[   RX   Rj   Rz   R   Rs   Ru   R   R   R   R  R   R   R:  R|  R  RW   R  Ro   RY   R{   R   R  R  R  R  R   Rx   R   (    (    (    s5   lib/python2.7/site-packages/astropy/io/fits/column.pyt   <module>   s   .-




	00**	,8@)H    R3	.		>	E				&	,	