U
    e»{j   ã                   @   sR   d Z ddlZddlmZ G dd„ dejƒZG dd„ dejƒZG d	d
„ d
ejƒZ	dS )z¿ sextractor.py:
  Classes to read SExtractor table format

Built on daophot.py:
:Copyright: Smithsonian Astrophysical Observatory (2011)
:Author: Tom Aldcroft (aldcroft@head.cfa.harvard.edu)
é    Né   )Úcorec                   @   s   e Zd ZdZdZdd„ ZdS )ÚSExtractorHeaderz3Read the header from a file produced by SExtractor.z^\s*#\s*\S\D.*c                 C   sØ  i }t  dt j¡}d}|D ]`}| d¡s2|} q|q| |¡}|rt| d¡ƒ}| d¡}| d¡}	| d¡}
||	|
f||< qt|ƒ}|dk	ršt| 	¡ ƒ}n|d }d	||d
 < | 
|d
 ¡ t|ƒd
k�r>d}|D ]j}||d
 k�r8t|d
 |ƒD ]D}|| d d|| › � }|| d
 }|| d }|||f||< qò|}qÒt|ƒdd… }g | _|D ]}| j 
|| d ¡ �qX| j�s†t d¡‚g | _|D ]B}tj|| d d�}|| d
 |_|| d |_| j 
|¡ �q�dS )aM  
        Initialize the header Column objects from the table ``lines`` for a SExtractor
        header.  The SExtractor header is specialized so that we just copy the entire BaseHeader
        get_cols routine and modify as needed.

        Parameters
        ----------
        lines : list
            List of table lines

        a  ^\s* \# \s*             # possible whitespace around #
                (?P<colnumber> [0-9]+)\s+   # number of the column in table
                (?P<colname> [-\w]+)        # name of the column
                # column description, match any character until...
                (?:\s+(?P<coldescr> \w .+)
                # ...until [non-space][space][unit] or [not-right-bracket][end]
                (?:(?<!(\]))$|(?=(?:(?<=\S)\s+\[.+\]))))?
                (?:\s*\[(?P<colunit>.+)\])?.* # match units in brackets
                Nú#Ú	colnumberÚcolnameÚcoldescrÚcolunitéÿÿÿÿ)NNNr   r   Ú_é   z*No column names found in SExtractor header)Úname)ÚreÚcompileÚVERBOSEÚ
startswithÚsearchÚintÚgroupÚsortedÚlenÚsplitÚappendÚrangeÚnamesr   ZInconsistentTableErrorÚcolsÚColumnÚdescriptionÚunit)ÚselfÚlinesÚcolumnsZre_name_defZdatalineÚlineÚmatchr   r   r   r	   Z
colnumbersZn_data_colsZprevious_columnÚnÚcZcolumn_nameZcolumn_descrZcolumn_unitÚcol© r'   úZ/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/io/ascii/sextractor.pyÚget_cols   s`    	ö




ÿÿzSExtractorHeader.get_colsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úcommentr)   r'   r'   r'   r(   r      s   r   c                   @   s   e Zd ZdZdZdZdS )ÚSExtractorDatar   ú z\s*#N)r*   r+   r,   Ú
start_lineÚ	delimiterr.   r'   r'   r'   r(   r/   p   s   r/   c                       sB   e Zd ZdZdZdZdZeZe	Z
ejZ‡ fdd„Zdd„ Z‡  ZS )	Ú
SExtractoraª  SExtractor format table.

    SExtractor is a package for faint-galaxy photometry (Bertin & Arnouts
    1996, A&A Supp. 317, 393.)

    See: https://sextractor.readthedocs.io/en/latest/

    Example::

      # 1 NUMBER
      # 2 ALPHA_J2000
      # 3 DELTA_J2000
      # 4 FLUX_RADIUS
      # 7 MAG_AUTO [mag]
      # 8 X2_IMAGE Variance along x [pixel**2]
      # 9 X_MAMA Barycenter position along MAMA x axis [m**(-6)]
      # 10 MU_MAX Peak surface brightness above background [mag * arcsec**(-2)]
      1 32.23222 10.1211 0.8 1.2 1.4 18.1 1000.0 0.00304 -3.498
      2 38.12321 -88.1321 2.2 2.4 3.1 17.0 1500.0 0.00908 1.401

    Note the skipped numbers since flux_radius has 3 columns.  The three
    FLUX_RADIUS columns will be named FLUX_RADIUS, FLUX_RADIUS_1, FLUX_RADIUS_2
    Also note that a post-ID description (e.g. "Variance along x") is optional
    and that units may be specified at the end of a line in brackets.

    Z
sextractorFzSExtractor format tablec                    s"   t ƒ  |¡}d|jkr|jd= |S )z�
        Read input data (file-like object, filename, list of strings, or
        single string) into a Table and return the result.
        Úcomments)ÚsuperÚreadÚmeta)r   ÚtableÚout©Ú	__class__r'   r(   r6   š   s    
zSExtractor.readc                 C   s   t ‚d S )N)ÚNotImplementedError)r   r8   r'   r'   r(   Úwrite¥   s    zSExtractor.write)r*   r+   r,   r-   Z_format_nameZ_io_registry_can_writeZ_descriptionr   Zheader_classr/   Z
data_classr   ZContinuationLinesInputterZinputter_classr6   r=   Ú__classcell__r'   r'   r:   r(   r3   v   s   r3   )
r-   r   Ú r   Z
BaseHeaderr   ZBaseDatar/   Z
BaseReaderr3   r'   r'   r'   r(   Ú<module>   s
   	`