
    HR-e                       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Zd dlm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mZ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# g dZ$ddddddddddd
Z%d e%&                                D             Z'de'd<   de'd<   de'd<   de'd <   d!e'd"<   g d#Z(d$d%d&Z)ddddddd'Z*d(d)d)d*d!d!d'Z+d+d,d-d.d/d0d1Z,i Z- ej.        d2          e-d3<    ej.        d4          xe-d5<   e-d<    ej.        d6          xe-d<   xe-d7<   xe-d8<   e-d9<    ej.        d:          xe-d!<   xe-d;<   e-d$<    ej.        d<          xe-d=<   e-d><   d?d@dAdBdCdDdEZ/dFxe/d5<   e/d<   dGxe/d!<   xe/d$<   xe/d=<   e/d><   dHZ0dIZ1	  e e2e0e1                    Z3 e e2e1e0                    Z4 ej.        dJej5                  Z6 ej.        dK          Z7 ej.        dL          Z8	  ej.        dM          Z9 ej.        dN          Z:d Z;dOZ< G dP dQ          Z= G dR dSe>          Z? G dT dUe?          Z@ G dV dWe?          ZA G dX dYe>          ZB G dZ d[e>          ZC G d\ d]eC          ZD G d^ d_          ZE G d` dae          ZF G db dce          ZG G dd deeG          ZH G df dgejI                  ZJdh ZKdi ZLdj ZMdzdkZNdl ZOd{dnZPdo ZQdp ZRdq ZSdr ZTds ZUdt ZVd{duZWd{dvZXdw ZYdx ZZd{dyZ[dS )|    N)OrderedDict)suppress)reduce)char)indent
isiterablelazyproperty)AstropyUserWarning   )CARD_LENGTHCard)NotifierMixin_convert_array_is_intcmpencode_asciipairwise)VerifyErrorVerifyWarning)ColumnColDefsDelayedi1u1i2i4i8f4f8c8c16a)
LBIJKEDCMAc                     i | ]\  }}||	S  r.   ).0keyvals      6lib/python3.11/site-packages/astropy/io/fits/column.py
<dictcomp>r3   4   s    :::83c3:::    r#   b1r%   u2r&   u4r'   u8r(   f2)r#   r$   r%   r&   r'   r)   r+   r,   r)   r+   )r(   r*   )r,   r%   r&   Fr(   r)    df)r   r   )
   r   )   r   )r?      )   r@   )      )r,   r%   r&   r(   r:   r)   zE(?:(?P<formatc>[F])(?:(?P<width>[0-9]+)\.{1}(?P<precision>[0-9])+)+)|r:   z((?:(?P<formatc>[AL])(?P<width>[0-9]+)+)|r,   zN(?:(?P<formatc>[IBOZ])(?:(?P<width>[0-9]+)(?:\.{0,1}(?P<precision>[0-9]+))?))|r$   OZzf(?:(?P<formatc>[EGD])(?:(?P<width>[0-9]+)\.(?P<precision>[0-9]+))+)(?:E{0,1}(?P<exponential>[0-9]+)?)|GzF(?:(?P<formatc>E[NS])(?:(?P<width>[0-9]+)\.{1}(?P<precision>[0-9])+)+)ENESz{{:{width}d}}z{{:{width}b}}z{{:{width}o}}z{{:{width}x}}z{{:{width}.{precision}f}}z{{:{width}.{precision}g}})r%   r$   rD   rE   r:   rF   z{{:>{width}}}z{{:{width}.{precision}e}})TTYPETFORMTUNITTNULLTSCALTZEROTDISPTBCOLTDIMTCTYPTCUNITCRPXTCRVLTCDLTTRPOS)nameformatunitnullbscalebzerodispstartdim
coord_type
coord_unitcoord_ref_pointcoord_ref_value	coord_inctime_ref_posz@(?P<repeat>^[0-9]*)(?P<format>[LXBIJKAEDCMPQ])(?P<option>[!-~]*)zq(?:(?P<format>[AIJ])(?P<width>[0-9]+)?)|(?:(?P<formatf>[FED])(?:(?P<widthf>[0-9]+)(?:\.(?P<precision>[0-9]+))?)?)z[0-9a-zA-Z_]+z)(?P<label>^T[A-Z]*)(?P<num>[1-9][0-9 ]*$)z0\(\s*(?P<dims>(?:\d+\s*)(?:,\s*\d+\s*)*\s*)\)\s*z---c                        e Zd ZdZddZd ZdS )r   zDelayed file-reading data.Nc                 F    t          j        |          | _        || _        d S N)weakrefproxyhdufield)selfrl   rm   s      r2   __init__zDelayed.__init__   s    =%%


r4   c                 <    | j         j        |         | j                 S ri   )rl   datarm   )rn   r0   s     r2   __getitem__zDelayed.__getitem__   s    
 x}S!$*--r4   NN)__name__
__module____qualname____doc__ro   rr   r.   r4   r2   r   r      s=        $$   . . . . .r4   r   c                   J    e Zd ZdZd Zd Zed             Zed             Z	dS )_BaseColumnFormatz
    Base class for binary table column formats (just called _ColumnFormat)
    and ASCII table column formats (_AsciiColumnFormat).
    c                     |sdS t          |t                    r>t          || j                  s(	 |                     |          }n# t          $ r Y dS w xY wndS | j        |j        k    S NF)
isinstancestr	__class__
ValueError	canonicalrn   others     r2   __eq__z_BaseColumnFormat.__eq__   s     	5eS!! 	eT^44 !! NN511EE! ! ! ! 55!! 5~00s   A 
AAc                 *    t          | j                  S ri   )hashr   rn   s    r2   __hash__z_BaseColumnFormat.__hash__  s    DN###r4   c                 4    t          j        | j                  S )zX
        The Numpy dtype object created from the format's associated recformat.
        )npdtype	recformatr   s    r2   r   z_BaseColumnFormat.dtype  s    
 x'''r4   c                 6    |                      |j                  S )a  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.
        )from_recformatr   )clsrY   s     r2   from_column_formatz$_BaseColumnFormat.from_column_format  s     !!&"2333r4   N)
rt   ru   rv   rw   r   r   r	   r   classmethodr   r.   r4   r2   ry   ry      sr         
1 1 1$ $ $ ( ( \( 4 4 [4 4 4r4   ry   c                   d     e Zd ZdZ fdZed             Zed             Zed             Z	 xZ
S )_ColumnFormata  
    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                    t                                          | |          }t          |          \  |_        |_        |_        |j                                        |_        |j        dv rM|j        dk    rt                              |          }nt                              |          }|j        |_
        nd |_
        |S )NPQr   )super__new___parse_tformatrepeatrY   optionupper_FormatP
from_tform_FormatQp_format)r   rY   rn   r   r~   s       r2   r   z_ColumnFormat.__new__,  s    wwsF++0>v0F0F-T[$+k''));*$$ {c!!$//77		$//77	%,DMM DMr4   c                 6     | t          |d                    S z9Creates a column format from a Numpy record dtype format.T)reverse_convert_formatr   r   s     r2   r   z_ColumnFormat.from_recformat=  s!     s?9d;;;<<<r4   c                      t          |           S z2Returns the equivalent Numpy record format string.r   r   s    r2   r   z_ColumnFormat.recformatB  s     t$$$r4   c                 j    | j         dk    rd}nt          | j                   }| | j         | j         S )a*  
        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.
        r   r;   )r   r}   rY   r   )rn   r   s     r2   r   z_ColumnFormat.canonicalG  sA     ;!FF%%F4$+4t{444r4   )rt   ru   rv   rw   r   r   r   r	   r   r   __classcell__r~   s   @r2   r   r   #  s             " = = [= % % \% 5 5 \5 5 5 5 5r4   r   c                   |     e Zd ZdZd fd	Zed             Zed             Zed             Z	ed             Z
 xZS )	_AsciiColumnFormataj  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`.
    Fc                     t                                          | |          }t          ||          \  |_        |_        |_        ||j        k    rt          |         |_        d|_        |S r{   )	r   r   _parse_ascii_tformatrY   width	precisionASCII2NUMPYr   _pseudo_logical)r   rY   strictrn   r~   s       r2   r   z_AsciiColumnFormat.__new__i  s`    wwsF++2Fvv2V2V/TZ T[  (0DN  %r4   c                 ^    |                      |j                  }|j        dk    rd|_        |S )Nr#   T)r   r   rY   r   )r   rY   insts      r2   r   z%_AsciiColumnFormat.from_column_formatv  s2    !!&"233=C#'D r4   c                 6     | t          |d                    S r   _convert_ascii_formatr   s     r2   r   z!_AsciiColumnFormat.from_recformat~  s"     s(DAAABBBr4   c                      t          |           S r   r   r   s    r2   r   z_AsciiColumnFormat.recformat  s     %T***r4   c                 d    | j         dv r| j          | j         d| j         S | j          | j         S )aO  
        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(   r:   r)   .)rY   r   r   r   s    r2   r   z_AsciiColumnFormat.canonical  sE     ;/))k@4:@@@@@++tz+++r4   F)rt   ru   rv   rw   r   r   r   r   r	   r   r   r   r   s   @r2   r   r   X  s                  [ C C [C + + \+ , , \, , , , ,r4   r   c                   @     e Zd ZdZd fd	Zd Zed             Z xZS )_FormatXzFor X format in binary tables.r   c                     |dz
  dz  dz   }t                                          | t          |f          dz             }||_        |S )Nr      r   )r   r   reprr   )r   r   nbytesobjr~   s       r2   r   z_FormatX.__new__  sF    A:!#q(ggooc4	??T#9::

r4   c                     | j         fS ri   r   r   s    r2   __getnewargs__z_FormatX.__getnewargs__  s    ~r4   c                     | j          dS )NXr   r   s    r2   tformz_FormatX.tform  s    +    r4   )r   )	rt   ru   rv   rw   r   r   propertyr   r   r   s   @r2   r   r     sm        ((        ! ! X! ! ! ! !r4   r   c                        e Zd ZdZdZdZ ej        e                    e                    Z	dZ
d
 fd	Zd Zed             Zed	             Z xZS )r   z&For P format in variable length table.z?(?P<repeat>\d+)?{}(?P<dtype>[LXBIJKAEDCM])(?:\((?P<max>\d*)\))?r   2i4Nc                     t                                          | | j                  }t          |         |_        ||_        ||_        ||_        |S ri   )r   r   _descriptor_format
NUMPY2FITSrY   r   r   max)r   r   r   r   r   r~   s        r2   r   z_FormatP.__new__  sC    ggooc3#9::&
	

r4   c                 *    | j         | j        | j        fS ri   )r   r   r   r   s    r2   r   z_FormatP.__getnewargs__  s    
DK22r4   c                 N   | j                             |          }|r|                    d          t          vrt	          d|           |                    d          }|                    d          }|                    d          }|sd } | t          |         ||          S )Nr   zInvalid column format: r   r   )r   r   )
_format_rematchgroup
FITS2NUMPYr   )r   rY   mr   array_dtyper   s         r2   r   z_FormatP.from_tform  s    N  (( 	BAGGG$$J66@@@AAA""ggg&&ggenn 	Cs:k*6sCCCCr4   c                 n    | j         dn| j         }| j        dn| j        }| | j         | j         d| dS )Nr;   ())r   r   _format_coderY   )rn   r   r   s      r2   r   z_FormatP.tform  sL    {*H$bb$(A$+AT[AA3AAAAr4   rs   )rt   ru   rv   rw   _format_re_templater   recompilerY   r   r   r   r   r   r   r   r   r   r   s   @r2   r   r     s        00
 	K  L/66|DDEEJ     3 3 3 	D 	D [	D B B XB B B B Br4   r   c                   j    e Zd ZdZdZ ej        ej        	                    e                    Z
dZdS )r   zCarries 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.
    r   2i8N)rt   ru   rv   rw   r   r   r   r   r   rY   r   r   r.   r4   r2   r   r     sI          LH8??MMNNJr4   r   c                   2    e Zd ZdZd ZddZd Zd Zd ZdS )	ColumnAttributea>  
    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                 V    || _         d | _        dt          | j                  z   | _        d S )N_)_keyword
_validatorKEYWORD_TO_ATTRIBUTE_attr)rn   keywords     r2   ro   zColumnAttribute.__init__  s*     />>


r4   Nc                 4    || S t          || j                  S ri   )getattrr   )rn   r   objtypes      r2   __get__zColumnAttribute.__get__  s    ;K3
+++r4   c                     | j         |                      ||           t          || j        d           }t          || j        |           |                    d|| j        dd          ||           d S )Ncolumn_attribute_changedr   )r   r   r   setattr_notify)rn   r   value	old_values       r2   __set__zColumnAttribute.__set__  sq    ?&OOC'''CT22	TZ'''.TZ^YPUVVVVVr4   c                     || _         | S )z
        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   )rn   funcs     r2   __call__zColumnAttribute.__call__  s     r4   c                 0    | j         j         d| j         dS )Nz('z'))r~   rt   r   r   s    r2   __repr__zColumnAttribute.__repr__%  s     .)>>T]>>>>r4   ri   )	rt   ru   rv   rw   ro   r   r   r   r   r.   r4   r2   r   r     sq         <? ? ?, , , ,W W W	 	 	? ? ? ? ?r4   r   c                      e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 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          d             Z ed          d             Z ed          d             Z ed          d             Z ed          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$            Z#e"d%             Z$e"d&             Z%d' Z&dS )*r   z
    Class which contains the definition of one column, e.g.  ``ttype``,
    ``tform``, etc. and the array containing values for the column.
    Nc                 v   |t          d          d|i}t          D ]7}t                      |         }t          |t                    r|j        }|||<   8 | j        di |\  }}|rddg}|                                D ]*}|                    t          |d                              +t          d                    |                    t          D ]&}t          | ||                    |                     '|d         }| j        | _        |	| _        d| _        t          |
t"          j        t&          j        t(          f          s	 |
t#          j        |
          }
n# t,          $ r 	 t/          |dd                   }t'          j        |
|	          }
nO# t           $ rB t          |t0                    rt3          |
|j        
          }
nt          d| d          Y nw xY wY nw xY w|                     |
          }
t          |
t"          j                  rd| _        nd| _        d| _        |
| _        dS )a
  
        Construct a `Column` by specifying attributes.  All attributes
        except ``format`` can be optional; see :ref:`astropy:column_creation`
        and :ref:`astropy: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

        coord_type : str, optional
            coordinate/axis type corresponding to ``TCTYP`` keyword

        coord_unit : str, optional
            coordinate/axis unit corresponding to ``TCUNI`` keyword

        coord_ref_point : int-like, optional
            pixel coordinate of the reference point corresponding to ``TCRPX``
            keyword

        coord_ref_value : int-like, optional
            coordinate value at reference point corresponding to ``TCRVL``
            keyword

        coord_inc : int-like, optional
            coordinate increment at reference point corresponding to ``TCDLT``
            keyword

        time_ref_pos : str, optional
            reference position for a time coordinate column corresponding to
            ``TRPOS`` keyword
        Nz(Must specify format to construct Column.asciiz7The following keyword arguments to Column were invalid:r   
r   Fitemsizer   z&Data is inconsistent with the format ``.Tr.   )r   KEYWORD_ATTRIBUTESlocalsr|   r   r   _verify_keywordsvaluesappendr   r   joinr   getr`   _dims_pseudo_unsigned_intsr   ndarray	chararrayr   array	Exceptionintr   _VLFr   _convert_to_valid_data_type_physical_values_parent_fits_rec)rn   rX   rY   rZ   r[   r\   r]   r^   r_   r`   r  r   ra   rb   rc   rd   re   rf   kwargsattrr   valid_kwargsinvalid_kwargsmsgr1   r   r  s                              r2   ro   zColumn.__init__/  s   x >GHHH 5!& 	! 	!DHHTNE%&& $ F4LL'<t'<'F'Fv'F'F$n 	.LMC%,,.. + +

6#a&>>****diinn---& 	8 	8DD$ 0 0 6 67777 !-	 X
 &+" %"*i.A7!KLL 	$HUOOE   "9QRR=11H%OEHEEEEE!    ")X66  $U)/ B B B(OVOOO   		 0077
 eRZ(( 	*$(D!!$)D! $


s7   E 
G**-FG*A	G$!G*#G$$G*)G*c                     d}t           D ]/}t          | |          }|||dz   t          |          z   dz   z  }0|d d         S )Nr;   z = z; )r  r   r   )rn   textr  r   s       r2   r   zColumn.__repr__  sX    & 	: 	:DD$''E utE{{2T99CRCyr4   c                     | j                                         | j        f}|j                                         |j        f}||k    S )z
        Two columns are equal if their name and format are the same.  Other
        attributes aren't taken into account at this time.
        )rX   lowerrY   )rn   r   r"   bs       r2   r   zColumn.__eq__  s?     Y__,Z.Avr4   c                 \    t          | j                                        | j        f          S )z
        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.
        )r   rX   r  rY   r   s    r2   r   zColumn.__hash__  s%     TY__&&4555r4   c                     d| j         v r| j         d         S | j        %|                                 }||| j                 S dS dS )a  
        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)__dict__r  rX   )rn   parents     r2   r  zColumn.array  s[    F dm##=))".**,,F!di(( "! 4r4   c                 .   |}	 t          |d          r\t          |j        t                    rB|j        D ]:}|| u r4| j        -t          j        |          | _        d| j        v r| j        d=  d S ;t          |dd           |j	        }nn|| j        d<   d S )NT_coldefsr  base)
hasattrr|   r&  r   r  rj   refr#  r   r'  )rn   r  r'  cols       r2   r  zColumn.array>  s     	tZ(( 	Zw-O-O 	=  Cd{{t'<'D07D0A0A- #dm33 $g 6tVT**6y	" "'gr4   c                 H    	 | j         d= n# t          $ r Y nw xY wd | _        d S )Nr  )r#  KeyErrorr  r   s    r2   r  zColumn.array\  sD    	g&& 	 	 	D	 !%s    
rI   c                 t   |d S t          |t                    rGt                              |          s-t	          j        d                    |          t                     t          |t                    r3t          t          t          d|                              t          k    rt          d          d S )NzIt is strongly recommended that column names contain only upper and lower-case ASCII letters, digits, or underscores for maximum compatibility with other software (got {!r}).rI   zColumn 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.)r|   r}   TTYPE_REr   warningswarnrY   r   lenr   r   AssertionError)r*  rX   s     r2   rX   zColumn.namee  s    < F dC   	)=)= 	M %fTll   $$$ 	CWd0C0C,D,D(E(E(T(T ;   )U(Tr4   rR   c                 |    |d S t          |t                    rt          |          dk    rt          d          d S )Nr   z=Coordinate/axis type must be a string of atmost 8 characters.)r|   r}   r1  r2  )r*  ra   s     r2   ra   zColumn.coord_type  sM    F*c** 	c*oo.A.A O   /B.Ar4   rS   c                 V    |$t          |t                    st          d          d S d S )Nz&Coordinate/axis unit must be a string.r|   r}   r2  )r*  rb   s     r2   rb   zColumn.coord_unit  s4    !*Z*E*E! !IJJJ "!!!r4   rT   c                 `    |)t          |t          j                  st          d          d S d S )NzCPixel coordinate of the reference point must be real floating type.r|   numbersRealr2  )r*  rc   s     r2   rc   zColumn.coord_ref_point  sC    &zW\0
 0
& !U   '&&&r4   rU   c                 `    |)t          |t          j                  st          d          d S d S )Nz?Coordinate value at reference point must be real floating type.r7  )r*  rd   s     r2   rd   zColumn.coord_ref_value  sC    &zW\0
 0
& !Q   '&&&r4   rV   c                 `    |)t          |t          j                  st          d          d S d S )Nz0Coordinate increment must be real floating type.r7  )r*  re   s     r2   re   zColumn.coord_inc  s6     Iw|)L)L  !STTT !   r4   rW   c                 V    |$t          |t                    st          d          d S d S )Nz)Time reference position must be a string.r5  )r*  rf   s     r2   rf   zColumn.time_ref_pos  s4    #J|S,I,I# !LMMM $###r4   rJ   rK   rL   rM   rN   rO   rP   rQ   c                 6    t          | j        t                    S )z<Whether this `Column` represents a column in an ASCII table.)r|   rY   r   r   s    r2   r   zColumn.ascii  s     $+'9:::r4   c                     | j         j        S ri   )rY   r   r   s    r2   r   zColumn.dtype  s    {  r4   c                 b    t          d          }| j                                        |_        |S )z1
        Return a copy of this `Column`.
        r%   rY   )r   r#  copy)rn   tmps     r2   rA  zColumn.copy  s.     C   }))++
r4   c                 H   t          | t                    r	| | j        fS | t          v rCt	          t
                    5  | }|                    |           } ddd           n# 1 swxY w Y   	  ||           } | j        }n!# t
          $ r t          d|  d          w xY w| |fS )a  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
        NIllegal format `r  )r|   ry   r   r   r   r   r   )rY   r   r   s      r2   r   zColumn._convert_format  s	    f/00 	,6+++Z+&& 4 4"	++F334 4 4 4 4 4 4 4 4 4 4 4 4 4 4
	=S[[F(II 	= 	= 	=;;;;<<<	= y  s   A  A$'A$,A? ?Bc                 	   i }i }	 |                      |||	|
          \  }}|                    ||           nM# t          t          f$ r}d|d}||f|d<   Y d}~n*d}~wt          $ r}d|d|d}||f|d<   Y d}~nd}~ww xY wd	|fd
|fd|fd|ffD ]\  }}||dk    r|||<   ||dk    rd}t          |t                    r=t          |          }t          |          |j	        k    rd
                    |          }nXd}t          |          sd
                    |          }n1|j
        |v s(|j
        dv r	|j        |v sd
                    ||          }|||d<   n||f|d<   ||dk    rd}t          |t                    sd|d}n5t          |t                    r |d                                         dk    rd}|:	 t          |           ||d<   n+# t          $ r}d|d}||f|d<   Y d}~nd}~ww xY w||f|d<   ||dk    rd}t          |t                    sd
                    |          }nR	 t          |          }n# t           t          f$ r Y nw xY wt          |          r|dk     rd
                    |          }|||d<   n||f|d<   |	|	dk    rd}t#                      }t          |t                    rd
                    |	          }n?t          |	t                    rt%          |	          }nt          |	t"                    r|	}nd}|rRt          |t&                    rd}n:t)          t*          j        |          |j        k    rd 
                    |||	          }|||d!<   n|	|f|d!<   |j|dk    rdd}t          |t                    sd"
                    |          }n(t          |          d#k    rd$
                    |          }|||d%<   n||f|d%<   |A|dk    r;d}t          |t                    sd&
                    |          }|||d'<   n||f|d'<   d(|fd)|fd*|ffD ]Z\  }}|S|dk    rMd}t          |t0          j                  s"d+
                    |t4          |         |          }||||<   S||f||<   [|A|dk    r;d}t          |t                    sd,
                    |          }|||d-<   n||f|d-<   ||fS ).a  
        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.
        )rY   r   z3Column format option (TFORMn) failed verification: zY The invalid value will be ignored for the purpose of formatting the data in this column.rY   NzSColumn format option (TFORMn) must be a string with a valid FITS table format (got : z[). The invalid value will be ignored for the purpose of formatting the data in this column.rX   rZ   r\   r]   r;   znASCII table null option (TNULLn) is longer than the column's character width and will be truncated (got {!r}).)r$   r%   r&   r'   zColumn 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   zColumn 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.r[   z2Column disp option (TDISPn) must be a string (got r   r#   zColumn 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.r^   z1Column disp option (TDISPn) failed verification: zColumn 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.r   zColumn 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.r_   zColumn 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.z`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.zThe 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.r`   zCoordinate/axis type option (TCTYPn) must be a string (got {!r}). The invalid keyword will be ignored for the purpose of formatting this column.r   zCoordinate/axis type option (TCTYPn) must be a string of atmost 8 characters (got {!r}). The invalid keyword will be ignored for the purpose of formatting this column.ra   zCoordinate/axis unit option (TCUNIn) must be a string (got {!r}). The invalid keyword will be ignored for the purpose of formatting this column.rb   rc   rd   re   zColumn {} option ({}n) must be a real floating type (got {!r}). The invalid value will be ignored for the purpose of formatting the data in this column.zTime coordinate reference position option (TRPOSn) must be a string (got {!r}). The invalid keyword will be ignored for the purpose of formatting this column.rf   )_determine_formatsupdater   r   AttributeErrorr|   r   r}   r1  r   rY   r   r   r   _parse_tdisp_formatr  	TypeErrortuple_parse_tdimr   r   operatormulr   r8  r9  ATTRIBUTE_TO_KEYWORD)r   rX   rY   rZ   r[   r\   r]   r^   r_   r`   r   ra   rb   rc   rd   re   rf   validinvalidr   errr  kvtnull_formats
dims_tuples                             r2   r  zColumn._verify_keywords  s   : 	. # 6 6vuc5 Q QFILL)L<<<<K( 	. 	. 	.6c 6 6 6 
 "(GH 	. 	. 	.6*06 6696 6 6  "(GH	. TNTNve	
 	 	DAq }ba
 

C&"455 "4yyt99v|++&&,fTll  !5t}} 3 4:6$<<	 C M]2233=8X8X3 4:6&$3G3G	  { $f#'+ 

CdC(( EE E E  F$677 DGMMOOs<R<R  {	2'---$(E&MM" 2 2 2II I I 
 (,SkGFOOOOOO2 $(+ "Cf&899  %fUmm	 JJEE!:.   D u~~ IIOPU  {!&g$)3<  ?sbyyCJ &"455 AAG  C%% (--

C'' 	 

1   i22  CCHL*55EEE FLV &#F F	  {)e"%s!jB&6&6Cj#.. 99?
9K9K 
 Z1$$ %fZ00	  {&0l##)3S(9%!jB&6&6Cj#.. 99?
9K9K  {&0l##)3S(9% 00)$
 	* 	*DAq
 }b!!W\22 ??Ev3A6@ @  ; E!HH"#SGAJ#(:(:ClC00 ==CVL=Q=Q  {(4n%%+7*='g~sK   29 B
AB)A>>BG 
G>'G99G>>I I"!I"c                    t          |t          j                  rt          |          \  }}}|0t          |t                    s|                     |||          \  }}ns|s4t          |t                    s|                     |t                    \  }}n=|r4t          |t                    s|                     |t                    \  }}n|j	        }||fS )a  
        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.
        )
r|   r   r   _dtype_to_recformatry   _guess_formatr   r   r   r   )r   rY   r_   r`   r   r   r   s          r2   rG  zColumn._determine_formats	  s     fbh'' 	7.v66LFAq =F4E!F!F=
 !$ 1 1&% E EFII 	)z&2CDD 	) # 3 3FM J JFII 	):f.@AA 	) # 3 3F<N O OFII (Iy  r4   c                    |r|rt          d          |rt          }nN|rt          }nDt          t                    5  t          |d          }d d d            n# 1 swxY w Y   t          }	 |                     ||          \  }}n@# t          $ r3 |t          u rt          nt          }|                     ||          \  }}Y nw xY w||fS )NzColumns 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.T)r   )r   r   r   r   r   r   )r   rY   r_   r`   guess_formatr   s         r2   rZ  zColumn._guess_format,  s`    	)S 	)P  
  	)-LL 	)(LL +&& A A+F4@@@A A A A A A A A A A A A A A A
 )L	J # 3 3FL I IFII 		J 		J 		J
 '3m&C&C"" 
 !$ 3 3FL I IFIII		J y  s#   AA!A-B :CCc                    t          |t                    r|S ||S | j        }| j        }|rA|j        dvr8d|v r
|d d         n|}t	          |          f|z   }|                    |          }d|v sd|v r|S d|v ru|j        j        dv r@|r	|d         }nt          j        |j	                  j
        }t          j        ||d          S t          |t          j        |j	                            S d	|v r|j        t          j        d
          k    r>t          j        |t          j        k    t!          d          t!          d                    S t          j        |dk    t!          d          t!          d                    S d|v r"t          |t          j        d                    S |j        j        |j	        z   }t          j        d          t          j        d          t          j        d          d}|j        j        dk    rO|j        j
        |v rA| j        dv r8| j        ||j        j
                 k    r|                    dd          }d| _        t          j        |          j        }t          ||          S )NPQr,   r   r   SUF)r  rA  r#   boolr:   Tr   r   uint8                       )      r   u)r   Nr;   iT)r|   r   rY   r  r1  reshaper   r   r   r   r  r  r  r   whereFalse_ord	byteorderuint16uint32uint64kindr\   r]   replacer  r'  )	rn   r  rY   dimsshapefsizenumpy_formatbzerosr   s	            r2   r  z"Column._convert_to_valid_data_typeW  sp   eW%% A	4L]L[F:D -T11%(F]]SbS		U-e,,f}}v;#t++ D !%R ")9 : : C$?55uMMMM)%&:J1K1KLLL;"(6"2"2228ERY$6C#c((KKK8EQJC#c((CCC%eRXg->->???  %{4v7GG y''y''y''  K$++,66}44
fU[-A&BBB $0#7#7S#A#AL15D.
 ..3%eU333r4   )NNNNNNNNNNNNNNNNN)NNNNNNNNNNNNNNNN)'rt   ru   rv   rw   ro   r   r   r   r   r  setterdeleterr   rX   ra   rb   rc   rd   re   rf   rY   rZ   r[   r\   r]   r^   r_   r`   r	   r   r   rA  staticmethodr   r   r  rG  rZ  r  r.   r4   r2   r   r   )  s         %g g g gR    6 6 6 I I XIV \' ' \': ]% % ]% _W  6 _W   _WK K K _W   _W   _WU U U _WN N N _W%%F?7##D?7##D_W%%FOG$$E?7##DOG$$E
/&
!
!C; ; \; ! ! \!   ! ! \!6  #d d d [dL	  !  ! [ !D (! (! [(!TC4 C4 C4 C4 C4r4   r   c                   6   e Zd ZdZdZeZd%dZd Zd%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$Z%d#S )(r   a  
    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.
     Fc                    | }t          |d          r"t          |j        t                    r|j        }n1t          |d          r!t          |j        t
                    rt          }|rt          }t                              |          S )N_columns_type_col_format_cls)	r(  
issubclassr  r   r  r   _AsciiColDefsobjectr   )r   inputr   klasss       r2   r   zColDefs.__new__  s    5/** 	"z%:Mw/W/W 	"'EEU-.. 	":!#54
 4
 	" "E 	"!E~~e$$$r4   c                     | j         fS ri   )_arraysr   s    r2   r   zColDefs.__getnewargs__  s    r4   c                 b   ddl m} ddlm} t	          |t
                    r|                     |           nt	          ||          r2t          |d          r"|j        r|                     |j                   nt	          |t          j
                  r"|j        j        |                     |           nZt          |          r|                     |           n5t	          ||          r|                     |           nt#          d          | j        D ]}|                    |            dS )aT  
        Parameters
        ----------
        input : sequence of `Column` or `ColDefs` or ndarray or `~numpy.recarray`
            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.

        r   )FITS_rec)_TableBaseHDUr&  NzQInput to ColDefs must be a table HDU, a list of Columns, or a record/field array.)fitsrecr  	hdu.tabler  r|   r   _init_from_coldefsr(  r&  r   r  r   fields_init_from_arrayr   _init_from_sequence_init_from_tablerK  columns_add_listener)rn   r  r   r  r  r*  s         r2   ro   zColDefs.__init__  sl    	&%%%%%,,,,,,eW%% 	##E****uh''	z**	 	 ##EN3333rz** 	u{/A/M!!%(((( 
	$$U++++}-- 	!!%((((7   < 	$ 	$Cd####	$ 	$r4   c                 .      fd|D              _         dS )z{Initialize from an existing ColDefs object (just copy the
        columns and convert their formats if necessary).
        c                 :    g | ]}                     |          S r.   )_copy_column)r/   r*  rn   s     r2   
<listcomp>z.ColDefs._init_from_coldefs.<locals>.<listcomp>  s'    BBB3))#..BBBr4   Nr  )rn   coldefss   ` r2   r  zColDefs._init_from_coldefs  s%     CBBB'BBBr4   c                     t          |          D ]-\  }}t          |t                    st          d| d          .|                     |           d S )NzElement z& in the ColDefs input is not a Column.)	enumerater|   r   rK  r  )rn   r  idxr*  s       r2   r  zColDefs._init_from_sequence  sn    !'** 	X 	XHCc6** X V3 V V VWWWX 	(((((r4   c           
        
 g | _         t          t          j                            D ]A}j        j        |         
j        j        
         d         }|j        dk    r
fdt          t                              D             }t          |          dk    st          j        d          |v rt          d
 d|           |	                                }| j
                            |          }d| d}n| j
                            |          }j        |         j        d d d	         }|rt          |          dk    sd
|v rpd
|v rFt          t          j        dt!          |j        d                             d                   }|f|z   }dd                    d |D                       z   dz   }nd }d }|j        j        dk    rJd|v rt          j        d          }n1d|v rt          j        d          }nd|v rt          j        d          }t/          
|                    t          j                  
         ||          }	| j                             |	           Cd S )Nr   rD   c                 Z    h | ]'}t          j                 |                   j        (S r.   )r   r  r   )r/   rj  r  cnames     r2   	<setcomp>z+ColDefs._init_from_array.<locals>.<setcomp>  s.    UUUa"(5<?339UUUr4   r   zColumn 'z4' contains unsupported object types or mixed types: r   z()r_  r,   z[0-9]+r   ,c              3   4   K   | ]}t          |          V  d S ri   r}   r/   r<   s     r2   	<genexpr>z+ColDefs._init_from_array.<locals>.<genexpr>  s(      $9$9SVV$9$9$9$9$9$9r4   r   ri  r%   rd  r&   re  r'   rf  )rX   rY   r  r]   r`   )r  ranger1  r   namesr  rs  r   rK  popr  r   rv  r  r   findallr}   subdtyper	  r'  rp  rq  rr  r   viewr  r  )rn   r  r  ftypedtypesrY   r`   dimelr]   cr  s    `        @r2   r  zColDefs._init_from_array  s   U[))** /	# /	#CK%c*EK&u-a0EzS  UUUUU5UCTCTUUUKK!OO#&)@)@#15 1 1(.1 1   

-<<UCC'V-<<UCC +c"(2.C 	C1v&==
8S9J5K5K L LQ OPPE !(S.CCHH$9$9S$9$9$9999C? Ez#%%&==Ie,,EEF]]Ie,,EEF]]Ie,,Ejj,,U3  A L""""_/	# /	#r4   c           	      v   |j         }|d         }d t          |          D             }|D ]}t                              |          }	 |                    d          }n# t
          $ r Y ?w xY w|t          v rpt          |                    d                    }d|cxk     r|k    rAn ~t          |         }	||         }
|	dk    r| 	                    |
          }
|
||dz
           |	<   t          |          D ]p\  }}t          j        di |\  }}|                                D ]+}t          j        d|dz    d	|d          t                      ,|d
= d|v r|d         |d<   |||<   qt          |          D ]}t#          ||          ||         d<   d |D             | _        |                     |           d S )NTFIELDSc                     g | ]}i S r.   r.   )r/   rj  s     r2   r  z,ColDefs._init_from_table.<locals>.<listcomp>/  s    333q333r4   labelnumr   rY   r   zInvalid keyword for column rF  r   r`   r  c                 &    g | ]}t          d i |S )r.   )r   )r/   attrss     r2   r  z,ColDefs._init_from_table.<locals>.<listcomp>U  s"    BBBEBBBr4   r.   )_headerr  TDEF_REr   r   r  KEYWORD_NAMESr  r   r  r  r   r  r  r/  r0  r   r   r  r  )rn   tablehdrnfieldscol_keywordsr   r0   r  r*  r  r   r  r  r  r  r1   s                   r2   r  zColDefs._init_from_table)  s2   mi. 43E'NN333 	8 	8G--((C		'**   %%#))E**++s%%%%g%%%%%/6DLEx'' !% 4 4U ; ;27Lq)$/ %\22 	- 	-KC+1+B+L+LV+L+L(L.%,,..  E#'EESVEE}   
 [)$$&,UmU# ,L >> 	= 	=C)0)<)<Lg&& CB\BBB
 	5!!!!!s   A
A+*A+c                 ,    |                      |           S ri   r   r   s    r2   __copy__zColDefs.__copy__\  s    ~~d###r4   c                 P    |                      fd| j        D                       S )Nc                 :    g | ]}t          j        |          S r.   )rA  deepcopy)r/   r  memos     r2   r  z(ColDefs.__deepcopy__.<locals>.<listcomp>`  s%    LLL!t}Q55LLLr4   )r~   r  )rn   r  s    `r2   __deepcopy__zColDefs.__deepcopy___  s,    ~~LLLLt|LLLMMMr4   c                    t          |j        | j                  r|                                S |                                }| j                            |j                  |_        t          |j        t
                    sd|_        |j        d|_        nM|j        t          |_        |j	        3|j	        
                                                    d          rd|_	        |S )zUtility 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).
        Nr#   )r|   rY   r  rA  r   r   r_   r[   DEFAULT_ASCII_TNULLr^   r   
startswith)rn   column
new_columns      r2   r  zColDefs._copy_columnb  s    
 fmT%9:: 	! ;;== [[]]
 !0CCFMRR
 *+-?@@ 	'#J* #'
 *"5
*z/D/D/F/F/Q/QRU/V/V*
 #'
r4   c                     |dd         }|t           v rC|d         dk    r7g }| j        D ]+}t          ||          }|                    ||nd           ,|S t	          |          )z
        Automatically returns the values for the given keyword attribute for
        all `Column`s in this list.

        Implements for example self.units, self.formats, etc.
        Nr_  sr;   )r  r  r   r  rI  )rn   rX   r  r  r*  r1   s         r2   __getattr__zColDefs.__getattr__  s~     SbS	&&&48s??D| < <c5))3?CC;;;;KT"""r4   c                 $   g }dg}t          | j        | j                  D ]\  }}|j        }t	          |          t	          | j                  k     r#|                    |d         |j        z              |ri|j        dvr`|j        dk    r:t          j        |j	        t          |d                   z   |d d         f          }nt          j        |j        |f          }|                    |           t          j        | j        ||d          S )Nr   r_  r^  r,   )r  formatsoffsets)zipr  r  r   r1  r  r  rY   r   r   r}   r'  r  )rn   r  r  format_r`   dts         r2   r   zColDefs.dtype  s
    #dj99 	 	LGSB7||c$,////
 wr{R[8999 2w~T11 >S((27SR\\#93ss8"DEEBB27C.11BNN2x$*WUUVVVr4   c                 $    d | j         D             S )Nc                     g | ]	}|j         
S r.   )rX   r/   r*  s     r2   r  z!ColDefs.names.<locals>.<listcomp>  s    111S111r4   r  r   s    r2   r  zColDefs.names  s    11DL1111r4   c                 $    d | j         D             S )Nc                     g | ]	}|j         
S r.   r@  r  s     r2   r  z#ColDefs.formats.<locals>.<listcomp>  s    333s
333r4   r  r   s    r2   r  zColDefs.formats  s    33dl3333r4   c                 $    d | j         D             S )Nc                     g | ]	}|j         
S r.   )r  r  s     r2   r  z#ColDefs._arrays.<locals>.<listcomp>      222c	222r4   r  r   s    r2   r  zColDefs._arrays  s    22T\2222r4   c                 $    d | j         D             S )Nc                     g | ]	}|j         
S r.   )r   )r/   fmts     r2   r  z'ColDefs._recformats.<locals>.<listcomp>  s    666#666r4   )r  r   s    r2   _recformatszColDefs._recformats  s    666666r4   c                 $    d | j         D             S )z<Returns the values of the TDIMn keywords parsed into tuples.c                     g | ]	}|j         
S r.   )r  r  s     r2   r  z!ColDefs._dims.<locals>.<listcomp>  r  r4   r  r   s    r2   r  zColDefs._dims  s     32T\2222r4   c                     t          |t                    rt          | j        |          }| j        |         }t          |          r|S t          |          S ri   )r|   r}   
_get_indexr  r  r   r   )rn   r0   xs      r2   rr   zColDefs.__getitem__  sP    c3 	.TZ--CL3<< 	H1::r4   c                 *    t          | j                  S ri   )r1  r  r   s    r2   __len__zColDefs.__len__  s    4<   r4   c                     d}t          | d          r8| j        r1|dz  }|d                    d | j        D                       z  }|dz  }|dz  }|S )NzColDefs(r  z
    c                 ,    g | ]}t          |          S r.   )r   )r/   r  s     r2   r  z$ColDefs.__repr__.<locals>.<listcomp>  s    !@!@!@a$q''!@!@!@r4   r   r   )r(  r  r	  )rn   reps     r2   r   zColDefs.__repr__  sk    4## 	 	 8OC8==!@!@4<!@!@!@AAAC4KCs

r4   leftc                 .   t          |t                    r|g}n9t          |t                    rt          |j                  }nt          d          |dk    rt          | j                  |z   }n|t          | j                  z   }t          |          S )NzWrong type of input.r  )r|   r   r   listr  rK  )rn   r   r   r   rB  s        r2   __add__zColDefs.__add__  s    eV$$ 	4AAw'' 	4U]##AA2333Vt|$$q(CCd4<(((Cs||r4   c                 .    |                      |d          S )Nright)r  r   s     r2   __radd__zColDefs.__radd__  s    ||E7+++r4   c                     t          |t          t          f          s|g} fd|D             }t          t          t	                                         }|D ]}|                    |            fd|D             }t          |          S )Nc                 :    g | ]}t          j        |          S r.   )r  r  )r/   r0   rn   s     r2   r  z#ColDefs.__sub__.<locals>.<listcomp>   s%    ???#*TZ--???r4   c                      g | ]
}|         S r.   r.   )r/   rj  rn   s     r2   r  z#ColDefs.__sub__.<locals>.<listcomp>  s    %%%1tAw%%%r4   )r|   r  rL  r  r1  remover   )rn   r   _otherindxr  rB  s   `     r2   __sub__zColDefs.__sub__  s    %$// 	GE???????E#d))$$%% 	 	AKKNNNN%%%%%%%s||r4   c                     d}t          | j                  D ]\  }}||u r n|dk    r| `n|dk    r| `|                     d|||||           dS )a  
        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.
        r   rX   rY   r   N)r  r  r  r  r   )rn   r  r  r   	new_valuer  r*  s          r2    _update_column_attribute_changedz(ColDefs._update_column_attribute_changed  s     !$,// 	 	HCf}}  6>>

X&T9i	
 	
 	
 	
 	
r4   c                 F   t          |t                    st          |                     d           | j                            |j                   | `| `| `	| `
| `| j                            |           |                    |            |                     d| |           | S )z?
        Append one `Column` to the column definition.
        	load_datacolumn_added)r|   r   r2  r   r  r  r  r   r  r  r  r  r  r  )rn   r  s     r2   add_colzColDefs.add_col  s     &&)) 	!   	[!!!FL)))JJJLF### 	T""" 	^T6222r4   c                     |                      d           t          | j        |          }| j        |         }| j        |= | `| `| `| `| `| j        |= |	                    |            |                      d| |           | S )z
        Delete (the definition of) one `Column`.

        col_name : str or int
            The column's name or index
        r  column_removed)
r   r  r  r  r  r   r  r  r  _remove_listener)rn   col_namer  r*  s       r2   del_colzColDefs.del_col;  s     	[!!!$*h//l4 LJJJLLT""" 	%tT222r4   c                 4    t          | |         ||           dS )aJ  
        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   )rn   r  attribr  s       r2   change_attribzColDefs.change_attrib[  s      	X	22222r4   c                 x    ||k    r|| j         v rt          d| d          |                     |d|           dS )z
        Change a `Column`'s name.

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

        new_name : str
            The new name of the column
        z	New name z already exists.rX   N)r  r   r  )rn   r  new_names      r2   change_namezColDefs.change_namel  sS     xH
$:$:CCCCDDDx:::::r4   c                 4    |                      |d|           dS )z
        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
        rZ   N)r  )rn   r  new_units      r2   change_unitzColDefs.change_unit}  s"     	8VX66666r4   allNc           	         |t           j        }|                                                                dv rt          }n|                    d          }t          t          |                    D ][}||                                                                         ||<   ||         d         dk    rt          |         dd         ||<   \i }|D ]}|rf|t          vr|	                    d| d           '|	                    | d           |	                    d	t          | |dz              d
           jt          | |dz             ||<   |s|S dS )a  
        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-like, 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.
        N)r  r;   r  r_  r  'z1' is not an attribute of the column definitions.
z:
z    r   )sysstdoutstripr  r  splitr  r1  r  writer   )rn   r  outputlstr  retr  s          r2   infozColDefs.info  sv   , >ZF<<>>!![00$CC,,s##CSXX . .s8>>++1133Cs8B<3&&#Cy"~CH 
	6 
	6D 	6111LLTDTTT   \\\***AGD$*$=$=AAABBBB#D$*55D		 	J	 	r4   r   )r  )r  N)&rt   ru   rv   rw   _padding_byter   r  r   r   ro   r  r  r  r  r  r  r  r  r	   r   r  r  r  r  r  rr   r  r   r  r  r  r  r  r  r  r	  r  r  r.   r4   r2   r   r     sW         M#O% % % %  +$ +$ +$ +$ZC C C) ) )1# 1# 1#f1" 1" 1"f$ $ $N N N+ + +Z# # #  W W \W@ 2 2 \2 4 4 \4 3 3 \3 7 7 \7 3 3 \3  ! ! !	 	 	   , , ,  
 
 
0  8  @3 3 3"; ; ;"7 7 71 1 1 1 1 1r4   r   c                        e Zd ZdZdZeZd fd	Zed             Z	e
d             Zed             Z fdZ fd	Zd
 Z xZS )r  z(ColDefs implementation for ASCII tables. Tc                 (   t                                          |           t          |t                    s|                                  d S t          |j                  D ]\  }}|| j        |         _        |j	        | _
        |j        | _        d S ri   )r   ro   r|   r  _update_field_metricsr  startsr  r_   spans_spans_width)rn   r  r   r  r  r~   s        r2   ro   z_AsciiColDefs.__init__  s     %// 	'&&(((((#EL11 , ,Q*+S!''+DK,DKKKr4   c                     i }t          t          |                     D ]?}dt          | j        |                   z   }|| j        |         dz
  f|| j        |         <   @t          j        |          S )NSr   )r  r1  r}   r  r  r  r   r   )rn   r   j	data_types       r2   r   z_AsciiColDefs.dtype  so    s4yy!! 	C 	CAc$*Q-000I$-t{1~/A#BE$*Q-  xr4   c                     | j         S )z0A list of the widths of each field in the table.)r   r   s    r2   r  z_AsciiColDefs.spans  s     {r4   c                     t          |           dk    rg }nd t          | j                  D             }|                    | j        | j        d         z
  dz              d |D             S )Nr   c                     g | ]
\  }}||z
  S r.   r.   )r/   r  ys      r2   r  z-_AsciiColDefs._recformats.<locals>.<listcomp>  s     >>>1a!e>>>r4   r_  c                 2    g | ]}d t          |          z   S r"   r  r/   ws     r2   r  z-_AsciiColDefs._recformats.<locals>.<listcomp>  s"    ---c!ff---r4   )r1  r   r  r  r!  )rn   widthss     r2   r  z_AsciiColDefs._recformats  so    t99>>FF>>(=(=>>>F
 	dkDKO3a7888--f----r4   c                 r    t                                          |           |                                  d S ri   )r   r  r  )rn   r  r~   s     r2   r  z_AsciiColDefs.add_col  s1    ""$$$$$r4   c                 r    t                                          |           |                                  d S ri   )r   r  r  )rn   r  r~   s     r2   r  z_AsciiColDefs.del_col  s1    !!!""$$$$$r4   c                     dgt          | j                  z  }d}t          | j                  D ]4\  }}|j        j        }|j        s
|dz   |_        |j        |z   dz
  }|||<   5|| _        || _        dS )z
        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.
        r   r   N)r1  r  r  rY   r   r_   r   r!  )rn   r  end_colr  r*  r   s         r2   r  z#_AsciiColDefs._update_field_metrics  s    
 c$,'''!$,// 		 		HCJ$E
 9 (#aK	i%'!+GE#JJr4   )T)rt   ru   rv   rw   r  r   r  ro   r	   r   r   r  r  r  r  r  r   r   s   @r2   r  r    s        22M(O' ' ' ' ' '   \   X 
. 
. \
.% % % % %% % % % %      r4   r  c                   6     e Zd ZdZddZd Zd Z fdZ xZS )r  zVariable length field object.r"   c                 ,   |dk    r.	 d |D             }n # t           $ r t          d|           w xY wt          j        |t                    }t          j                            | t          |          f|t                    }d|_        ||_	        |S )zp
        Parameters
        ----------
        input
            a sequence of variable-sized elements.
        r"   c                 :    g | ]}t          j        |d           S )r   r   )r  r  )r/   r  s     r2   r  z _VLF.__new__.<locals>.<listcomp>  s'    GGGAQ777GGGr4   zInconsistent input data array: r  )rv  bufferr   r   )
r  r   r   r  r  r  r   r1  r   element_dtype)r   r  r   r"   rn   s        r2   r   z_VLF.__new__  s     C<<L HGGGG L L L !J5!J!JKKKL HU&)))z!!#c%jj]1F!SS"s    2c                 >    |d S |j         | _         |j        | _        d S ri   )r   r7  )rn   r   s     r2   __array_finalize__z_VLF.__array_finalize__'  s&    ;F7 .r4   c                    t          |t          j                  r|j        | j        k    rnct          |t          j                  r|j        dk    rn=| j        dk    rt	          j        |d          }nt          j        || j                  }t          j                            | ||           |j	        }t          j
        |          }t          | j        |          | _        dS )zc
        To make sure the new item has consistent data type to avoid
        misalignment.
        r   r"   r   r  N)r|   r   r  r   r  r  r7  r  __setitem__rv  prodr   )rn   r0   r   nelem	len_values        r2   r;  z_VLF.__setitem__-  s    
 eRZ(( 	>U[DJ-F-Fy233 	>!8K8K3&&OEA666EEHU$*<===E

tS%000GENN	tx++r4   c                 X    d t                                                      D             S )Nc                 ,    g | ]}t          |          S r.   )r  )r/   items     r2   r  z_VLF.tolist.<locals>.<listcomp>@  s    888tT

888r4   )r   tolist)rn   r~   s    r2   rB  z_VLF.tolist?  s%    88uww~~'7'78888r4   r+  )	rt   ru   rv   rw   r   r9  r;  rB  r   r   s   @r2   r  r    sp        ''   */ / /, , ,$9 9 9 9 9 9 9 9 9r4   r  c                 $   t          |          rt          |          }nt          |t                    r	 |                     |                                          }n# t          $ r |                                                                }d | D             } |                     |          }|dk    r|                     |          }n,|dk    rt          d| d          t          d| d          Y nw xY wt          d|d          |S )	a  
    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.
    c                 Z    g | ](}|                                                                 )S r.   )r  rstrip)r/   ns     r2   r  z_get_index.<locals>.<listcomp>b  s,    777AQWWYY%%''777r4   r   r   zKey 'z' does not exist.zAmbiguous key name 'z'.zIllegal key ')
r   r  r|   r}   indexrE  r   r  countr,  )r  r0   r  _keyrH  s        r2   r  r  C  s*   , s|| 23xx	C		 2	?;;szz||,,DD 
	? 
	? 
	?99;;%%''D77777EKK%%Ezz{{4((!=s===>>>=c===>>>	 
	? 0s000111Ks   'A BC:9C:c           	      (   t          j        g dd          }|dz
  dz  dz   }t          |          D ]^}|dz  }t          |dz   dz  |          }t          ||          D ]0}t          j        | d|f         |||dz  z
                     |d|f<   1_dS )z
    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
    )   @       rA   r   rh  rg  r   rc  r  r   r   .N)r   r  r  minbitwise_and)	r  r  r   pow2r   rj  _min_maxr$  s	            r2   _unwrapxrS  p  s     8111AAADza1$F6]] L L1uAEQ;''tT"" 	L 	LA^E#q&M4AE	?KKF36NN	LL Lr4   c           	         d|d<   |dz
  dz  dz   }|dz  |z
  }t          |          D ]}|dz  }t          |dz   dz  |          }t          ||          D ]\}||k    r&t          j        |d|f         d|d|f                    t          j        |d|f         | d|f         |d|f                    ]t          j        |d|f         ||d|f                    dS )a  
    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
    r   .r   r   N)r  rN  r   
left_shiftadd)	r  r  r   r   unusedrj  rQ  rR  r$  s	            r2   _wrapxrX    s    F3Kza1$FaZ& F6]] B B1uAEQ;''tT"" 	B 	BADyyfS!VnaQ@@@F6#q&>5a=&a.AAAA	B M&a.&&a.99999r4   c                 t   d}|st          |           }t          dg|z  |j                  }|j        dk    rd}n t          j        g |j                  j        }t          |          D ]}|t          |           k     r	| |         }n!|j        dk    rd|j        z  }ndg|j        z  }|j        dk    r't          j        t          |          d          ||<   nt          j        ||j                  ||<   ||         j
        }	t          j        |	          ||df<   |||df<   |||df         |z  z  }|S )a  
    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
    r   Nr  r"   r   r  r   )r1  r  r   r   r  r  r  r   r  r   rv  r<  )
r  descr_outputrY   nrows_offsetdata_output_nbytesr  rowvalr=  s
             r2   _makepr`    sZ   8 G E

v~V\:::K|s(2V\222;U|| 2 2U3ZFF|s""{.{.<3(|F/C/CaPPPK!xflCCCKC &!wu~~S!V&S!V<Q''11r4   c                 *   	 t                               |                                                                           \  }}}n!# t          $ r t          d| d          w xY w|dk    rd}nt          |          }||                                |fS )z_Parse ``TFORMn`` keyword for a binary table into a
    ``(repeat, format, option)`` tuple.
    Format  is not recognized.r;   r   )
TFORMAT_REr   r  groupsr  r   r  r   )r   r   rY   r   s       r2   r   r     s    B#-#3#3EKKMM#B#B#I#I#K#K  B B B @E@@@AAA	B ||VFLLNNF++s   AA A#Fc                 
    t                                                                          }|st          d d          |                    d          }|s|                    d                                          }|                    d          }|                    d          }|||rt          d          |d	n|}|d
n|}n@|                                }|                    d          }||rt          d          d	}d	} fd}|r|r ||           ||          }}n|r ||          }nt          |         \  }}|d	k    rt          d d          ||k    rt          d d| d          |||fS )z
    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').
    rb  rc  rY   Nformatfwidthfr   z7Format {!r} is not unambiguously an ASCII table format.r   r   r   c                     d}	 t          |           } n7# t          t          f$ r# t          |                                        w xY w| S )NzMFormat {!r} is not valid--field width and decimal precision must be integers.)r  r   rK  r   rY   )r1   r  r   s     r2   convert_intz)_parse_ascii_tformat.<locals>.convert_int	  s`      		1c((CCI& 	1 	1 	1cjj//000	1 
s	    4A	z5 not valid--field width must be a positive integeter.zT not valid--the number of decimal digits must be less than the format's total width r   )TFORMAT_ASCII_REr   r  r   r   r   ASCII_DEFAULT_WIDTHS)r   r   r   rY   r   r   rj  s   `      r2   r   r     s    ""5;;==11E B@E@@@AAA [[""F~Y''--//H%%KK,,	=I- B!M   #]!*!2AA		G$$= !M  
 	
 
 
 
 
  8 8&;u--{{9/E/Ey	 8E"" 07yzzTeTTT
 
 	
 ECe C C:?C C C
 
 	

 5)##r4   c                     | ot                               |           }|rJ|                    d          }t          d |                    d          D                       ddd         S t                      S )z{Parse the ``TDIM`` value into a tuple (may return an empty tuple if
    the value ``TDIM`` value is empty or invalid).
    ru  c              3   X   K   | ]%}t          |                                          V  &d S ri   )r  r  r  s     r2   r  z_parse_tdim.<locals>.<genexpr>H	  s0      ==S^^======r4   r  Nr_  )TDIM_REr   r   rL  r  )tdimr   ru  s      r2   rM  rM  A	  so     	$t$$A Dwwv==TZZ__=====dddCC 77Nr4   c                 `   t           t          t          fD ]}	  ||           }  n# t          $ r Y w xY wt	          j        |           j        }|dd         }	 t          |         }t          	                    ||          S # t          $ r" dt          t          |                     z   cY S w xY w)z
    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.
    r   Nr,   )r  floatcomplexr   r   min_scalar_typer}   r   FITSUPCONVERTERSr
  r,  r1  )r   type_numpy_dtype_strfits_formats       r2   _scalar_to_formatry  N	  s     ug&  	E%LLEE 	 	 	H	 (//3O%abb)O% 1##K=== % % %SU__$$$$%s   %
22'B )B-,B-c                 Z   | d         dk    rF|d         dk    r:t          t          | dd                   t          |dd                             S t          |          t          |         }} t          t                              |           t                              |                    S )zP
    Compares two numpy recformats using the ordering given by FORMATORDER.
    r   r"   r   N)r   r  r   FORMATORDERrG  )f1r9   s     r2   _cmp_recformatsr}  g	  s     
!u||13r!""v;;BqrrF,,,BBB;$$R((+*;*;B*?*?@@@r4   c                 Z   t          |           \  }}}|t          v r|dk    rlt          |         t          |          z   }|                                 d         dk    r0|dk    r*t          |         t          t	          |                    z   }nd}|dk    rt          |          }|t          |         z   }nt|dk    rt          |          }n^|dk    rt                              |           }n=|dk    rt                              |           }n|dk    rd	}nt          d
|  d          |S )z9
    Convert FITS format spec to record format spec.
    r,   r   r;   r   r   r   r   r:   r   rD  r  )
r   r   r}   lstripr  r   r   r   r   r   )rY   r   r   r   output_format
repeat_strs         r2   _convert_fits2recordr  r	  s/    +622FE6
C<<&u-F;M }}q!S((Vr\\ *5 1CF4D4D DJ{{ [[
&E)::MM	# ((	# ++F33	# ++F33	#6F666777r4   c                 R   t          |           \  }}}|j        }|j        j        }|j        dk    s|j        |j        d         j        dk    r|dz  }t          |          }t          |          }d}|dk    r0t          j	        |d          
                                }	|	dk    r|	}|dk    r2t          |          t          |          z  }
t          |
          d	z   }nE|t          v r)|dk    rt          |          }nd
}|t          |         z   }nt          d|  d          |S )z9
    Convert record format spec to FITS format spec.
    UNr   rh  r   r   r  r"   r,   r;   rD  r  )rY  rv  r'  r  r   r  r}   r1  r   r  r<  r  r   r   )rY   r   rs  r   rv  r  r   ndimsr   nelntotr  s               r2   _convert_record2fitsr  	  s8    188ItUKEz"HzS"u~a'8'='D'D
 q=]]FJJEFqyyhuD)))..0077Fs{{ 6{{S[[(D		C	j	 	 Q;;[[FFFI!666F666777r4   c                     t          | t          j                  st          j        |           } | j        j        }|dv rdx}}n| j        j        }|t          |          z   }||| fS )a  
    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  r#  r"   )r|   r   r   r'  rs  r  r}   )r   rs  r   r  s       r2   rY  rY  	  sl     eRX&&  :?Dz	DD:&3x==(	dE!!r4   c                 B    |rt          |           S t          |           S )z_
    Convert FITS format spec to record format spec.  Do the opposite if
    reverse=True.
    )r  r  )rY   r   s     r2   r   r   	  s(    
  ,#F+++#F+++r4   c                    |rt          |           \  }}}|j        }|dk    rdt          |          z   S t                              |          dk    rdS |dk    rXdt          t          d|dz  z                      z   }t          |t          d	         d
                   }d	t          |          z   S |dk    r:|dk    rd} nd} d                    d t          |          D                       }| |z   S dS t          |           \  } }}t          |          }| d	k    r|dk    rd}n!|dk    rd}n| dk    r|t          |          z  }|S )z6Convert ASCII table format spec to record format spec.r"   r,   r#   A1rj  r   rg  r   r%   r   r=   r)   r(   r   c              3   4   K   | ]}t          |          V  d S ri   r  r,  s     r2   r  z(_convert_ascii_format.<locals>.<genexpr>
  s(      JJSVVJJJJJJr4   rh  r   	   r   N)rY  r  r}   r   r
  r1  r   rl  r	  r   r   )rY   r   r   rs  r   r  r   r   s           r2   r   r   	  sx    2!4V!<!<	4>3;;X&&^^I&&#-- 4S[[ Chl 344555E3C8;<<EU##S[[ 1}}HHJJ-A&-IJJJJJEE>! [ $8#?#? y  '	 S==zz 		 	s]]U#Ir4   c                    |                                  } | d         dk    st          |           dk    r| d         dvr| d         n	| dd         }	 t          |         }n!# t          $ r t	          d|  d          w xY w|                    |                                            }|r|                    d	          t	          d|  d          |                    d	          }|                    d
          }d}d}| d         dv r|                    d          }|d}| d         dv r#| d         dvr|                    d          }|d}||||fS )a  
    Parse the ``TDISPn`` keywords for ASCII and binary tables into a
    ``(format, width, precision, exponential)`` tuple (the TDISP values
    for ASCII and binary are identical except for 'Lw',
    which is only present in BINTABLE extensions.

    Parameters
    ----------
    tdisp : str
        TDISPn FITS Header keyword.  Used to specify display formatting.

    Returns
    -------
    formatc: str
        The format characters from TDISPn
    width: str
        The width int value from TDISPn
    precision: str
        The precision int value from TDISPn
    exponential: str
        The exponential int value from TDISPn

    r   r(   r   NSNrg  rb  rc  formatcr   )r%   r$   rD   rE   r:   r(   rF   r)   r   )r(   r)   rF   )Nr#  exponential)r  r1  TDISP_RE_DICTr,  r   r   r   )tdispfmt_keytdisp_rer   r  r   r   r  s           r2   rJ  rJ  
  s   2 KKMME 8s??s5zzA~~%($2F2F 	a2A2Y 
@ ) @ @ @>E>>>???@ NN5;;==))E @EKK	**2>E>>>???kk)$$GKK  EIK Qx;;;KK,,	IQx?""uQxz'A'Akk-00K E9k11s   A A=c                     t          |           \  }}}}	 t          |         }|                    ||          S # t          $ r t	          d| d          w xY w)a  
    Turn the TDISPn fortran format pieces into a final Python format string.
    See the format_type definitions above the TDISP_FMT_DICT. If codes is
    changed to take advantage of the exponential specification, will need to
    add it as another input parameter.

    Parameters
    ----------
    tdisp : str
        TDISPn FITS Header keyword.  Used to specify display formatting.

    Returns
    -------
    format_string: str
        The TDISPn keyword string translated into a Python format string.
    )r   r   rb  rc  )rJ  TDISP_FMT_DICTrY   r,  r   )r  format_typer   r   r  r  s         r2   _fortran_to_python_formatr  Y
  sz    " 2EU1K1K.K	;F[)zzz;;; F F FDKDDDEEEFs	   #: Ac                    dddddddddddddd	}| d
v rdS | d         dk    r/| dk    r)|                      d                              d          }n$| d         dk    r|                      d          }n| }d\  }}|d                                         r,|d         dk    r |d         dk    r|d         }|dd         }n|d         dk    r,|dk    r&|d         }|dd                              d          }n|d                                         rt	          |          dk    r|d         dk    r||d                  }|dd         }d|v ro|                    d          \  }}d}|dk    rN|dk    r|nd}t          t          |          t          |         d         t          |         d         z
  z             }n#|}n t          j
        d|  dt                     dS |rd}||z   |z   |z   S )a  
    Turn the Python format string to a TDISP FITS compliant format string. Not
    all formats convert. these will cause a Warning and return None.

    Parameters
    ----------
    format_string : str
        TDISPn FITS Header keyword.  Used to specify display formatting.
    logical_dtype : bool
        True is this format type should be a logical type, 'L'. Needs special
        handling.

    Returns
    -------
    tdsip_string: str
        The TDISPn keyword string translated into a Python format string.
    r,   r%   r$   rD   rE   r:   rF   r(   )r"   r  r<   r   or  r   r=   r:   grF   er(   )Nr;   {}Nr   {r  z{:}%)r;   r;   r_  >r   0r"   r  r   r;   rb  zg cannot be mapped to the accepted TDISPn keyword values.  Format will not be moved into TDISPn keyword.r#   )r  rE  isdigitisalphar1  r  r}   r  rl  r/  r0  r
   )	format_stringlogical_dtypefmt_to_tdispfmt_strr   sepr  r   r0   s	            r2   python_to_tdispr  t
  s   &  L  (((t Q3=D#8#8&&t,,33C88	q	S	 	 &&s++NIs r{ !s!2!2wqzS7H7HS!			3S!##C(( 
				 3w<<!#3#3
c8I8IWR[)#2#, '>>&}}S11E9C{{$||ee	NN+C036J36OPQ6RRT  EE 	Mm M M M	
 	
 	

 t  5=3**r4   ri   r   )\rA  r8  rN  r   r  r/  rj   collectionsr   
contextlibr   	functoolsr   numpyr   r   r  astropy.utilsr   r   r	   astropy.utils.exceptionsr
   cardr   r   utilr   r   r   r   r   r   verifyr   r   __all__r   itemsr   r{  ru  r   	ASCII2STRrl  r  r   r  r  r  r  r   rP  r%   rd  rk  r.  r  ro  
ASCIITNULLr  r   r}   ry   r   r   r   r   r   r   r   r   r  r  r  r  rS  rX  r`  r   r   rM  ry  r}  r  r  rY  r   r   rJ  r  r  r.   r4   r2   <module>r     s      				 



   # # # # # #                 # # # # # # : : : : : : : : : : 7 7 7 7 7 7 # # # # # # # # U U U U U U U U U U U U U U U U . . . . . . . .
*
*
* 
									 
 ;:z'7'7'9'9:::
 
4 
4 
4 
4  
4  766 3''  dDt$OO 3Ss3GG	
 
					   RZL c  +5"*/+ + c ]3'
 BJ, c  ]3' -*<}@ @Jrz+@ @ c  ]3'-*<
 -7BJM- - d mD)2 
				$	$  -< ;s nS)   s   nS)  N4,@>D" " L #{33}6H#I#IJJ "{33'9=#I#IJJ  RZG 
 2:"   2:&''
 "*A
B
B "*H
I
I 
  . . . . . . . .'4 '4 '4 '4 '4 '4 '4 '4T25 25 25 25 25% 25 25 25j=, =, =, =, =,* =, =, =,@! ! ! ! !s ! ! !*'B 'B 'B 'B 'Bs 'B 'B 'BT	 	 	 	 	x 	 	 	C? C? C? C? C? C? C? C?Lq4 q4 q4 q4 q4] q4 q4 q4h_ _ _ _ _m _ _ _DJ J J J JG J J J`19 19 19 19 192: 19 19 19h* * *ZL L L0: : :<: : : :z, , ,(G$ G$ G$ G$T
 
 
% % %2A A A" " "J* * *Z" " "0, , , ,4 4 4 4n82 82 82vF F F6W+ W+ W+ W+ W+ W+r4   