ó
šßÈ[c           @   s  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 m Z e j d	 ƒ Z d
 j ƒ  Z d j ƒ  Z d e j f d „  ƒ  YZ d d „ Z d d „ Z d „  Z d d „ Z d S(   iÿÿÿÿNi   (   t   fitsi   (   t   filli   (   t   zip(   t   AstropyDeprecationWarningt   fitsdiffs»  
Compare two FITS image files and report the differences in header keywords and
data.

    fitsdiff [options] filename1 filename2

where filename1 filename2 are the two files to be compared.  They may also be
wild cards, in such cases, they must be enclosed by double or single quotes, or
they may be directory names.  If both are directory names, all files in each of
the directories will be included; if only one is a directory name, then the
directory name will be prefixed to the file name(s) specified by the other
argument.  for example::

    fitsdiff "*.fits" "/machine/data1"

will compare all FITS files in the current directory to the corresponding files
in the directory /machine/data1.
s'  
If the two files are identical within the specified conditions, it will report
"No difference is found." If the value(s) of -c and -k takes the form
'@filename', list is in the text file 'filename', and each line in that text
file contains one keyword.

Example
-------

    fitsdiff -k filename,filtnam1 -n 5 -r 1.e-6 test1.fits test2

This command will compare files test1.fits and test2.fits, report maximum of 5
different pixels values per extension, only report data values larger than
1.e-6 relative to each other, and will neglect the different values of keywords
FILENAME and FILTNAM1 (or their very existence).

fitsdiff command-line arguments can also be set using the environment variable
FITSDIFF_SETTINGS.  If the FITSDIFF_SETTINGS environment variable is present,
each argument present will override the corresponding argument on the
command-line unless the --exact option is specified.  The FITSDIFF_SETTINGS
environment variable exists to make it easier to change the
behavior of fitsdiff on a global level, such as in a set of regression tests.
t   HelpFormatterc           B   s   e  Z d  „  Z RS(   c         C   s   d j  t | |  j ƒ ƒ S(   Ns   
{}
(   t   formatR   t   width(   t   selft   epilog(    (    s?   lib/python2.7/site-packages/astropy/io/fits/scripts/fitsdiff.pyt   format_epilogA   s    (   t   __name__t
   __module__R
   (    (    (    s?   lib/python2.7/site-packages/astropy/io/fits/scripts/fitsdiff.pyR   @   s   c         C   sç  d „  } t  j d t d t d t ƒ  ƒ } | j d d d d d	 d
 ƒ| j d d d d d d d d d d d	 d ƒ| j d d d d d d  d d d d d	 d ƒ| j d d d d d d d  d d d d d	 d  ƒ| j d! d" d# d d d d  d d$ d d d	 d% ƒ| j d& d' d d( d d) d t d	 d* ƒ| j d+ d d( d d, d t d	 d- ƒ| j d. d d d d/ d t d	 d0 ƒ| j d1 d2 d d3 d	 d4 ƒt  j	 | d5 ƒ } | j d6 d7 d d8 d8 | d9 d: d d; d g  d d< d d= d	 d> ƒ| j d? d@ d d8 d8 | d9 d: d d; d g  d dA d d= d	 dB ƒ| j
 | ƒ t  j	 | dC ƒ } | j dD dE d d8 d8 | d9 d: d d; d g  d dF d dG d	 dH ƒ| j
 | ƒ | j |  ƒ \ } } t | ƒ dI k rÝ| j dJ t j dK | j j ƒ ƒ n  | | f S(L   Nc         S   s!  t  | j |  j g  ƒ | rå | d d k rå | d } t j j | ƒ se t j d j | | ƒ ƒ d  SyH g  t	 | d ƒ j
 ƒ  D] } | j ƒ  ^ q~ } t  | j |  j | ƒ Wqt k
 rá } t j d j | | | ƒ ƒ ~ qXn8 t  | j |  j g  | j d ƒ D] } | j ƒ  ^ qƒ d  S(   Ni    t   @i   s   {} argument {} does not existt   rs4   reading {} for {} failed: {}; ignoring this argumentt   ,(   t   setattrt   valuest   destt   ost   patht   existst   logt   warningR   t   opent	   readlinest   stript   IOErrort   split(   t   optiont   optt   valuet   parsert   vR   t   exc(    (    s?   lib/python2.7/site-packages/astropy/io/fits/scripts/fitsdiff.pyt
   store_listG   s    
.
t   usageR	   t	   formatters   -qs   --quiett   actiont
   store_truet   helps0   Produce no output and just return a status code.s   -ns   --num-diffst   typet   intt   defaulti
   R   t   numdiffst   metavart   INTEGERsi   Max number of data differences (image pixel or table element) to report per extension (default %default).s   -ds   --difference-tolerancet   floatt	   tolerancet   NUMBERsq   DEPRECATED. Alias for "--relative-tolerance". Deprecated, provided for backward compatibility (default %default).s   -rs   --rtols   --relative-tolerancet   rtolsÓ   The relative tolerance for comparison of two numbers, specifically two floating point numbers.  This applies to data in both images and tables, and to floating point keyword values in headers (default %default).s   -as   --atols   --absolute-tolerancet   atolsÓ   The absolute tolerance for comparison of two numbers, specifically two floating point numbers.  This applies to data in both images and tables, and to floating point keyword values in headers (default %default).s   -bs   --no-ignore-blankst   store_falset   ignore_blankssÿ   Don't ignore trailing blanks (whitespace) in string values.  Otherwise trailing blanks both in header keywords/values and in table column values) are not treated as significant i.e., without this option 'ABCDEF   ' and 'ABCDEF' are considered equivalent. s   --no-ignore-blank-cardst   ignore_blank_cardss¬   Don't ignore entirely blank cards in headers.  Normally fitsdiff does not consider blank cards when comparing headers, but this will ensure that even blank cards match up. s   --exactt   exact_comparisonssO   Report ALL differences, overriding command-line options and FITSDIFF_SETTINGS. s   -os   --output-filet   FILEsE   Output results to this file; otherwise results are printed to stdout.s   Header Comparison Optionss   -ks   --ignore-keywordst   callbackt   nargsi   t   strt   ignore_keywordst   KEYWORDSsÓ   Comma-separated list of keywords not to be compared.  Keywords may contain wildcard patterns.  To exclude all keywords, use "*"; make sure to have double or single quotes around the asterisk on the command-line.s   -cs   --ignore-commentst   ignore_commentssw   Comma-separated list of keywords whose comments will not be compared.  Wildcards may be used as with --ignore-keywords.s   Table Comparison Optionss   -fs   --ignore-fieldst   ignore_fieldst   COLUMNSsƒ   Comma-separated list of fields (i.e. columns) not to be compared.  All columns may be excluded using "*" as with --ignore-keywords.i   s   
sH   fitsdiff requires two arguments; see `fitsdiff --help` for more details.(   t   optparset   OptionParsert   USAGEt   EPILOGR   t
   add_optiont   Nonet   Truet   Falset   OptionGroupt   add_option_groupt
   parse_argst   lent   errort   textwrapR   R%   R   (   t   argvR#   R    t   groupt   optionst   args(    (    s?   lib/python2.7/site-packages/astropy/io/fits/scripts/fitsdiff.pyt   handle_optionsE   s|    	c         C   sØ   t  j t j ƒ t j t j ƒ } | j t j d ƒ ƒ | j t j	 ƒ t  j
 | ƒ |  d  k	 rs t j |  ƒ } n> t j ƒ  } d t j f d „  ƒ  Y} | j | d t j ƒ ƒ | j t j d ƒ ƒ t  j
 | ƒ d  S(   Ns   %(levelname)s: %(message)st   LevelFilterc           B   s)   e  Z d  Z d e j d „ Z d „  Z RS(   s/   Log only messages matching the specified level.t    c         S   s    t  j j |  | ƒ | |  _ d  S(   N(   t   loggingt   Filtert   __init__t   level(   R   t   nameRY   (    (    s?   lib/python2.7/site-packages/astropy/io/fits/scripts/fitsdiff.pyRX   Ñ   s    c         S   s   | j  |  j k S(   N(   t   levelnoRY   (   R   t   rec(    (    s?   lib/python2.7/site-packages/astropy/io/fits/scripts/fitsdiff.pyt   filterÕ   s    (   R   R   t   __doc__RV   t   NOTSETRX   R]   (    (    (    s?   lib/python2.7/site-packages/astropy/io/fits/scripts/fitsdiff.pyRT   Î   s   RY   s   %(message)s(   R   t   setLevelRV   t   INFOt   StreamHandlert   syst   stderrt   setFormattert	   Formattert   WARNINGt
   addHandlerRF   t   FileHandlerRW   t	   addFilter(   t   outfilet   error_handlert   output_handlerRT   (    (    s?   lib/python2.7/site-packages/astropy/io/fits/scripts/fitsdiff.pyt   setup_loggingÂ   s    c         C   sç  t  j j |  d ƒ r3 t  j j |  d ƒ r3 |  g Sd  d  g } d  d  g } x©t |  ƒ D]›\ } } t j | ƒ r@g  t j | ƒ D] } t  j j | ƒ ^ qƒ } | sÇ t j	 d | ƒ t
 j d ƒ n  t t | Œ  ƒ \ } } t t | ƒ ƒ d k rt j	 d | ƒ t
 j d ƒ n  t | ƒ j ƒ  | | <t | ƒ | | <n™ t  j j | ƒ rx| | | <t t  j | ƒ ƒ | | <na t  j j | ƒ r¼t  j j | ƒ | | <t  j j | ƒ g | | <n t j	 d | ƒ t
 j d ƒ t  j j | | ƒ | | <qX Wt | d ƒ t | d ƒ @} xŒ d d	 g D]~ \ }	 }
 t | |	 ƒ t | ƒ k r"t  j j |  |	 ƒ r"x< t t | |	 ƒ | ƒ D] } t j d | | |
 ƒ q|Wq"q"Wg  | D]8 } t  j j | d | ƒ t  j j | d | ƒ f ^ q«S(
   Ni    i   s,   Wildcard pattern %r did not match any files.i   s4   Wildcard pattern %r should match only one directory.sf   %r is not an existing file, directory, or wildcard pattern; see `fitsdiff --help` for more usage help.s   %r has no match in %r(   i    i   (   i   i    (   R   R   t   isfileRF   t	   enumeratet   globt	   has_magicR   R   RM   Rc   t   exitt   listR   RL   t   sett   popt   sortedt   isdirt   listdirt   dirnamet   basenamet   abspathR   t   join(   t   pathst   dirnamest	   filelistst   iR   t   ft   filest   dirst	   filematcht   at   bt   extra(    (    s?   lib/python2.7/site-packages/astropy/io/fits/scripts/fitsdiff.pyt   match_filesà   sF    ,.	
3!"c   
      C   sq  |  p t  j d }  d t j k r< t j d j ƒ  |  }  n  t |  ƒ \ } }  | j d  k	 r| t j	 d t
 ƒ | j | _ n  | j d  k r— d | _ n  | j d  k r² d | _ n  | j rý g  | _ g  | _ g  | _ d | _ d | _ t | _ t | _ n  | j st | j ƒ n  t |  ƒ } t } | j r:d  } n- | j r^t | j d ƒ } t } n	 t  j } g  } z© x‘ | D]‰ \ } } t j j | | d | j d | j d | j d	 | j d
 | j d | j d | j d | j ƒ} | j d | ƒ | j  | j! ƒ qwWt" t# | ƒ ƒ SWd  | r,| j$ ƒ  n  x= t% j& D]2 }	 t' |	 t( j) ƒ r[|	 j$ ƒ  n  t% j* |	 ƒ q6WXd  S(   Ni   t   FITSDIFF_SETTINGSs‘   "-d" ("--difference-tolerance") was deprecated in version 2.0 and will be removed in a future version. Use "-r" ("--relative-tolerance") instead.g        t   wR<   R>   R?   R,   R2   R3   R5   R6   t   fileobj(+   Rc   RO   R   t   environR   RS   R0   RF   t   warningst   warnR   R2   R3   R7   R<   R>   R?   RH   R5   R6   t   quietRn   t   output_fileR‰   R   RG   t   stdoutR    t   difft   FITSDiffR,   t   reportt   appendt	   identicalR*   t   allt   closeR   t   handlerst
   isinstanceRV   Ri   t   removeHandler(
   RR   t   optsRƒ   t
   close_filet   out_fileR—   R†   R‡   R“   t   handler(    (    s?   lib/python2.7/site-packages/astropy/io/fits/scripts/fitsdiff.pyt   main  sj    																						(   Rq   RV   RA   R   Rc   RN   RŽ   RU   R    t   utilR   t   extern.six.movesR   t   utils.exceptionsR   t	   getLoggerR   R   RC   RD   t   TitledHelpFormatterR   RF   RS   Rn   R‰   R¡   (    (    (    s?   lib/python2.7/site-packages/astropy/io/fits/scripts/fitsdiff.pyt   <module>   s$   }	0