
    HR-e                         d Z ddlZddlmZ  G d dej                  Z G d dej                  Z G d	 d
ej                  Z	dS )zsextractor.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                       e Zd ZdZdZd ZdS )SExtractorHeaderz3Read the header from a file produced by SExtractor.z^\s*#\s*\S\D.*c                    i }t          j        dt           j                  }d}|D ]}|                    d          s|} n|                    |          }|rit          |                    d                    }|                    d          }|                    d          }	|                    d          }
||	|
f||<   t          |          }|"t          |	                                          }n|d         }d	||d
z   <   |
                    |d
z              t          |          d
k    rcd}|D ]^}||d
z   k    rQt          |d
z   |          D ]=}||         d         d||z
   z   }||         d
         }||         d         }|||f||<   >|}_t          |          dd         }g | _        |D ](}| j        
                    ||         d                    )| j        st          j        d          g | _        |D ]c}t          j        ||         d                   }||         d
         |_        ||         d         |_        | j        
                    |           dd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   InconsistentTableErrorcolsColumndescriptionunit)selflinescolumnsre_name_defdatalinelinematchr	   r
   r   r   
colnumbersn_data_colsprevious_columnnccolumn_namecolumn_descrcolumn_unitcols                       ;lib/python3.11/site-packages/astropy/io/ascii/sextractor.pyget_colszSExtractorHeader.get_cols   s     j J
 
  	F 	FD??3'' F#**400 F #EKK$<$< = =I#kk)44G${{:66H#kk)44G*18W)EGI&G__

 hnn..//KK %R.K#5a +/***w<<!O 	$ 	$!+++"?Q#6:: N N#O4Q7:Sa/>Q:S:SS $ (/'?'B&-o&>q&A&1<%M

"#G__SbS)

 	- 	-AJgajm,,,,z 	-<   	 	" 	"A+71:a=111C%ajmCOqz!}CHIS!!!!		" 	"    N)__name__
__module____qualname____doc__commentr4    r5   r3   r   r      s3        ==GW" W" W" W" W"r5   r   c                       e Zd ZdZdZdZdS )SExtractorDatar    z\s*#N)r6   r7   r8   
start_line	delimiterr:   r;   r5   r3   r=   r=   o   s        JIGGGr5   r=   c                   J     e Zd ZdZdZdZdZeZe	Z
ej        Z fdZd Z x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.

    
sextractorFzSExtractor format tablec                 l    t                                          |          }d|j        v 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__s      r3   rG   zSExtractor.read   s6    
 ggll5!!!!$
r5   c                     t           )N)NotImplementedError)r#   rI   s     r3   writezSExtractor.write   s    !!r5   )r6   r7   r8   r9   _format_name_io_registry_can_write_descriptionr   header_classr=   
data_classr   ContinuationLinesInputterinputter_classrG   rN   __classcell__)rK   s   @r3   rB   rB   u   su         6  L",L#LJ3N	 	 	 	 	" " " " " " "r5   rB   )
r9   r    r   
BaseHeaderr   BaseDatar=   
BaseReaderrB   r;   r5   r3   <module>r[      s     
			      \" \" \" \" \"t \" \" \"~    T]   0" 0" 0" 0" 0" 0" 0" 0" 0" 0"r5   