This repository has been archived by the owner on Nov 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestFITS.py
60 lines (53 loc) · 1.63 KB
/
testFITS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
This program takes two fits files as arguments and checks for
differences between them. Uses the astropy module to achieve this.
Writes the output to a text file.
"""
import sys
import subprocess
import numpy
import argparse
from astropy.io import fits
sys.path.append("original") # The original cosmics module directory
import cosmics as origCosmics
sys.path.append("optimized") # The optimized cosmics module directory
import cosmics as optCosmics
def parse_args():
'''
parse the command line arguemnts.
'''
parser = argparse.ArgumentParser(
description = 'Takes two FITS files and compares them')
parser.add_argument(
'-file1',
'-f1',
required = True,
help = 'firstFITS file for comparison')
parser.add_argument(
'-file2',
'-f2',
required = True,
help = 'second FITS file for comparison')
args = parser.parse_args()
return args
args=parse_args() #parse input arguments
#check if inputs are of correct format
if args.file1.endswith(".fits") & args.file2.endswith(".fits"):
file1=args.file1
file2=args.file2
else:
print "Unrecognized argument(s). Requires two fits files."
sys.exit(0)
#output filename created based on input filenames
diffFileName="diff"+file1[:-5]+file2[:-5]+".txt"
#open fits files for comparison
fits1=fits.open(file1)
fits2=fits.open(file2)
#use astropy's fits sub-module to find and report differences
fitsDiff=fits.FITSDiff(fits1,fits2,ignore_keywords=['*'])
diffFile=open(diffFileName,'w') #open output file
fitsDiff.report(diffFile,0) #write the report
#close all open files
diffFile.close()
fits1.close()
fits2.close()