ó
šßÈ[c           @` s   d  Z  d d l m Z m Z m Z d d l Z d d l m Z d d l m	 Z	 d e j
 f d	 „  ƒ  YZ d
 e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d S(   s¿    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)
i    (   t   absolute_importt   divisiont   print_functionNi   (   t   corei   (   t   ranget   SExtractorHeaderc           B` s   e  Z d  Z d Z d „  Z RS(   s3   Read the header from a file produced by SExtractor.s   ^\s*#\s*\S\D.*c         C` s†  i  } t  j d t  j ƒ } d } x” | D]Œ } | j d ƒ sG | } Pq( | j | ƒ } | r( t | j d ƒ ƒ } | j d ƒ } | j d ƒ }	 | j d ƒ }
 | |	 |
 f | | <q( q( Wt | ƒ } | d k	 rå t	 | j
 ƒ  ƒ } n
 | d } d | | d <| j | d ƒ t	 | ƒ d k r¿d	 } x– | D]‹ } | | d k r²xl t | d | ƒ D]T } | | d	 d
 j | | ƒ } | | d } | | d } | | | f | | <qWWn  | } q-Wn  t | ƒ d  } g  |  _ x& | D] } |  j j | | d	 ƒ qßW|  j st j d ƒ ‚ n  g  |  _ xZ | D]R } t j d | | d	 ƒ } | | d | _ | | d | _ |  j j | ƒ q,Wd S(   sM  
        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

        s\  ^\s* \# \s*             # possible whitespace around #
                                 (?P<colnumber> [0-9]+)\s+   # number of the column in table
                                 (?P<colname> [-\w]+)        # name of the column
                                 (?:\s+(?P<coldescr> \w .+)  # column description, match any character until...
                                 (?:(?<!(\]))$|(?=(?:(?<=\S)\s+\[.+\]))))?  # ...until [non-space][space][unit] or [not-right-bracket][end]
                                 (?:\s*\[(?P<colunit>.+)\])?.* # match units in brackets
                                 t   #t	   colnumbert   colnamet   coldescrt   colunitiÿÿÿÿi   i    s   _{}i   s*   No column names found in SExtractor headert   nameN(   NNN(   t   ret   compilet   VERBOSEt   Nonet
   startswitht   searcht   intt   groupt   sortedt   lent   splitt   appendR   t   formatt   namesR   t   InconsistentTableErrort   colst   Columnt   descriptiont   unit(   t   selft   linest   columnst   re_name_deft   datalinet   linet   matchR   R   R	   R
   t
   colnumberst   n_data_colst   previous_columnt   nt   ct   column_namet   column_descrt   column_unitt   col(    (    s:   lib/python2.7/site-packages/astropy/io/ascii/sextractor.pyt   get_cols   sV    
			(   t   __name__t
   __module__t   __doc__t   commentR/   (    (    (    s:   lib/python2.7/site-packages/astropy/io/ascii/sextractor.pyR      s   t   SExtractorDatac           B` s   e  Z d  Z d Z d Z RS(   i    t    s   \s*#(   R0   R1   t
   start_linet	   delimiterR3   (    (    (    s:   lib/python2.7/site-packages/astropy/io/ascii/sextractor.pyR4   e   s   t
   SExtractorc           B` sG   e  Z d  Z d Z e Z d Z e Z e	 Z
 e j Z d „  Z d „  Z RS(   sª  Read a SExtractor file.
       SExtractor is a package for faint-galaxy photometry.
       Bertin & Arnouts 1996, A&A Supp. 317, 393.
       http://www.astromatic.net/software/sextractor

    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.
    t
   sextractors   SExtractor format tablec         C` s8   t  t |  ƒ j | ƒ } d | j k r4 | j d =n  | S(   s   
        Read input data (file-like object, filename, list of strings, or
        single string) into a Table and return the result.
        t   comments(   t   superR8   t   readt   meta(   R   t   tablet   out(    (    s:   lib/python2.7/site-packages/astropy/io/ascii/sextractor.pyR<   ‹   s    c         C` s
   t  ‚ d  S(   N(   t   NotImplementedError(   R   R>   (    (    s:   lib/python2.7/site-packages/astropy/io/ascii/sextractor.pyt   write–   s    (   R0   R1   R2   t   _format_namet   Falset   _io_registry_can_writet   _descriptionR   t   header_classR4   t
   data_classR   t   ContinuationLinesInputtert   inputter_classR<   RA   (    (    (    s:   lib/python2.7/site-packages/astropy/io/ascii/sextractor.pyR8   k   s   		(   R2   t
   __future__R    R   R   R   t    R   t   extern.six.movesR   t
   BaseHeaderR   t   BaseDataR4   t
   BaseReaderR8   (    (    (    s:   lib/python2.7/site-packages/astropy/io/ascii/sextractor.pyt   <module>   s   S