
    HR-e5                        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
  ej        d          Zd                                Z e
d                                d	          Z G d
 de j                  ZddZddZd ZddZdS )    N)__version__)fits)fillfitsdiffaN  
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.

This script is part of the Astropy package. See
https://docs.astropy.org/en/latest/io/fits/usage/scripts.html#fitsdiff
for further documentation.
a'  
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.
P   )widthc                   (     e Zd Zd fd	ZddZ xZS )StoreListActionNc                 b    |t          d           t                      j        |||fi | d S )Nznargs not allowed)
ValueErrorsuper__init__)selfoption_stringsdestnargskwargs	__class__s        @lib/python3.11/site-packages/astropy/io/fits/scripts/fitsdiff.pyr   zStoreListAction.__init__D   sA    0111u???????    c                 v   t          || j        g            |r|d         dk    r|dd          }t          j                            |          s't
                              | j         d| d           d S 	 d t          |                                          D             }t          || j        |           d S # t          $ r@}t
                              d
                    || j        |                     ~Y d }~d S d }~ww xY wt          || j        d |                    d	          D                        d S )
Nr   @   z
 argument z does not existc                 6    g | ]}|                                 S  strip.0vs     r   
<listcomp>z,StoreListAction.__call__.<locals>.<listcomp>S   s     EEE!''))EEEr   z4reading {} for {} failed: {}; ignoring this argumentc                 6    g | ]}|                                 S r   r   r   s     r   r!   z,StoreListAction.__call__.<locals>.<listcomp>]   s     *P*P*P17799*P*P*Pr   ,)setattrr   ospathexistslogwarningopen	readlinesOSErrorformatsplit)r   parser	namespacevaluesoption_stringvalueexcs          r   __call__zStoreListAction.__call__I   sY   	49b)))  	RfQi3&&122JE7>>%(( tyJJEJJJKKK	EET%[[-B-B-D-DEEE	49f55555   JQQty#   
 CCCCCC Ity*P*Pfll3>O>O*P*P*PQQQQQs   6AB9 9
D5C>>DN)__name__
__module____qualname__r   r5   __classcell__)r   s   @r   r
   r
   C   s_        @ @ @ @ @ @
R R R R R R R Rr   r
   c           
      z   t          j        t          t          t           j                  }|                    dddt                      |                    dddd	
           |                    dddd           |                    ddt          dddd           |                    dddt          d ddd           |                    dddt          d d dd!           |                    d"d#d$d%d&d'(           |                    d)d$d*d&d+(           |                    d,dd-d.d/(           |                    d0d1d2d34           |                    d5d6t          g d7d8d9:           |
                    d;          }|                    d<d=t          g d>d?d@:           |                    dAdBt          g dCdDdE:           |
                    dF          }|                    dGdHt          g dIdJdK:           |                    |           }t          |j                  dLk    r|                    dM           |S )NN)descriptionepilogformatter_classz	--versionversionz	%(prog)s )actionr?   
fits_filesfile+z.fits files to process.)metavarr   helpz-qz--quiet
store_truez0Produce no output and just return a status code.)r@   rE   z-nz--num-diffs
   numdiffsINTEGERzlMax number of data differences (image pixel or table element) to report per extension (default %(default)s).)typedefaultr   rD   rE   z-rz--rtolz--relative-tolerancertolNUMBERzThe 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).z-az--atolz--absolute-toleranceatolzThe 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).z-bz--no-ignore-blanksstore_falseignore_blanksTzDon'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. )r@   r   rK   rE   z--no-ignore-blank-cardsignore_blank_cardszDon'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. z--exactexact_comparisonsFzOReport ALL differences, overriding command-line options and FITSDIFF_SETTINGS. z-oz--output-fileFILEzEOutput results to this file; otherwise results are printed to stdout.)rD   rE   z-uz--ignore-hdusignore_hdus	HDU_NAMESz_Comma-separated list of HDU names not to be compared.  HDU names may contain wildcard patterns.)r@   rK   r   rD   rE   zHeader Comparison Optionsz-kz--ignore-keywordsignore_keywordsKEYWORDSzComma-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.z-cz--ignore-commentsignore_commentsCOMMENTSzwComma-separated list of keywords whose comments will not be compared.  Wildcards may be used as with --ignore-keywords.zTable Comparison Optionsz-fz--ignore-fieldsignore_fieldsCOLUMNSzComma-separated list of fields (i.e. columns) not to be compared.  All columns may be excluded using "*" as with --ignore-keywords.   zI
fitsdiff requires two arguments; see `fitsdiff --help` for more details.)argparseArgumentParserDESCRIPTIONEPILOGRawDescriptionHelpFormatteradd_argumentr   intfloatr
   add_argument_group
parse_argslenrA   error)argvr/   groupoptionss       r   handle_optionsrl   `   s]   $ <  F I/H;/H/H     fC6O     ?	     =     0      0           !!;  
 
 
  F  	 	 	 T	     3     %%&ABBE	,     
J     %%&@AAE	!     %%G 7!##X	
 	
 	
 Nr   c                    t                               t          j                   t          j        t
          j                  }|                    t          j        d                     |                    t          j	                   t           
                    |           | t          j        |           }nTt          j                    } G d dt          j                  }|                     |t          j                             |                    t          j        d                     t           
                    |           d S )Nz%(levelname)s: %(message)sc                   .    e Zd ZdZdej        fdZd ZdS )"setup_logging.<locals>.LevelFilterz/Log only messages matching the specified level. c                 T    t           j                            | |           || _        d S r6   )loggingFilterr   level)r   namert   s      r   r   z+setup_logging.<locals>.LevelFilter.__init__%  s%    ''d333"


r   c                 "    |j         | j        k    S r6   )levelnort   )r   recs     r   filterz)setup_logging.<locals>.LevelFilter.filter)  s    {dj00r   N)r7   r8   r9   __doc__rr   NOTSETr   ry   r   r   r   LevelFilterro   "  sD        AA$&gn # # # #1 1 1 1 1r   r|   )rt   z%(message)s)r(   setLevelrr   INFOStreamHandlersysstderrsetFormatter	FormatterWARNING
addHandlerFileHandlerrs   	addFilter)outfileerror_handleroutput_handlerr|   s       r   setup_loggingr     s   LL)#*55Mw01MNNOOO7?+++NN=!!! ,W55 .00	1 	1 	1 	1 	1'. 	1 	1 	1 	  7<!@!@!@AAA 1- @ @AAANN>"""""r   c                   	
 t           j                            | d                   r(t           j                            | d                   r| gS d d g	d d g}t          |           D ]\  }
t	          j        
          rd t	          j        
          D             }|s/t                              d
           t          j	        d           t          t          |           \  }}t          t          |                    dk    r/t                              d
           t          j	        d           t          |                                          	|<   t          |          ||<   nt           j                            
          r6
	|<   
fdt          t          j        
                    D             ||<   nt           j                            
          rFt           j                            
          	|<   t           j                            
          g||<   n/t                              d
           t          j	        d           t           j                            	|                   	|<   t          |d                   t          |d                   z  }d	D ]\  }}t          ||                   t          |          k    rot           j                            | |                   sJt          t          ||                   |z
            D ]$}t                              d
|	|                    %	fd|D             S )Nr   r   c                 L    g | ]!}t           j                            |          "S r   )r%   r&   r.   )r   fs     r   r!   zmatch_files.<locals>.<listcomp>>  s&    ???!RW]]1%%???r   z,Wildcard pattern %r did not match any files.r\   z4Wildcard pattern %r should match only one directory.c                     g | ]A}t           j                            t           j                            |                    ?|BS r   )r%   r&   isfilejoin)r   r   r&   s     r   r!   zmatch_files.<locals>.<listcomp>L  sM       7>>"',,tQ"7"788  r   zf%r is not an existing file, directory, or wildcard pattern; see `fitsdiff --help` for more usage help.)r   r   )r   r   z%r has no match in %rc                     g | ]N}t           j                            d          |          t           j                            d         |          fOS r   )r%   r&   r   )r   r   dirnamess     r   r!   zmatch_files.<locals>.<listcomp>e  sS       IJhqk1	%	%rw||HQK'C'CD  r   )r%   r&   r   	enumerateglob	has_magicr(   rh   r   exitlistziprg   setpopsortedisdirlistdirdirnamebasenameabspathr)   )paths	filelistsifilesdirs	filematchabextrar   r&   s            @@r   match_filesr   4  s   	w~~eAh BGNN58$<$< wd|HtIU##  3  34>$ 	??ty???E 		H$OOOsE{++KD%3t99~~!!		PRVWWWd))--//HQK!%==IaLLW]]4   	HQK   
4 0 011  IaLL
 W^^D!! 		'//$//HQKG,,T223IaLLIIF  
 HQKKKgoohqk22IaL!!C	!$5$55I  I I1y|s9~~--bgmmE!H6M6M-IaL 1 1I =>> I I3UHQKHHHH   NW   r   c                 F   | pt           j        dd          } dt          j        v r't          j        d                                         | z   } t          |           }|j        d|_        |j        d|_        |j        r1g |_	        g |_
        g |_        d|_        d|_        d|_        d|_        |j        st          |j                   t#          |j                  }d}|j        rd }n+|j        rt'          |j        d          }d}nt           j        }g }	 |D ]\  }}t*          j                            |||j        |j	        |j
        |j        |j        |j        |j        |j        |j                  }|                    |           |                    |j                   t;          t=          |                     |r|                                 t@          j!        D ]J}	tE          |	tF          j$                  r|	                                 t@          %                    |	           KS # |r|                                 t@          j!        D ]J}	tE          |	tF          j$                  r|	                                 t@          %                    |	           Kw xY w)	Nr   FITSDIFF_SETTINGSg        FwT)	rT   rV   rX   rZ   rH   rL   rN   rP   rQ   )fileobj)&r   ri   r%   environr.   rl   rL   rN   rR   rV   rX   rZ   rP   rQ   quietr   output_filer   rA   r*   stdoutr   diffFITSDiffrT   rH   reportappend	identicalrc   allcloser(   handlers
isinstancerr   r   removeHandler)
argsoptsr   
close_fileout_filer   r   r   r   handlers
             r   mainr   j  s   38ABB<Dbj((z-.4466=$Dy	y	 (!!		""': (d&'''((EJz 		 (#..

:I' 	- 	-DAq9%% , $ 4 $ 4"0YY"0#'#: &  D KKK)))T^,,,,s9~~%&& 	NN | 	' 	'G'7#677  g&&&&	'	  	NN | 	' 	'G'7#677  g&&&&	's   B+H1 1A/J r6   )r]   r   rr   r%   r   astropyr   
astropy.ior   astropy.io.fits.utilr   	getLoggerr(   r   r_   r`   Actionr
   rl   r   r   r   r   r   r   <module>r      sO      				 



             % % % % % %g
##* 
EGG+ 0 
, 
EGG
1
 
 
8R R R R Rho R R R:s s s sl# # # #<3 3 3lB' B' B' B' B' B'r   