-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyhselect.py
executable file
·61 lines (47 loc) · 1.44 KB
/
pyhselect.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
60
61
#!/usr/bin/env python
import os,sys
import pyfits
from pyraf import iraf
from optparse import OptionParser
def pyhselect(img, hdrlist, lst):
#<--- count number of lines in the list and backup the orignal file --->
# open image list
if lst:
try :
fimg=open(img)
except IOError:
print >> sys.stderr, 'cannot open %s' % img
return 1
# open header list
try :
fhdr=open(hdrlist)
except IOError:
print >> sys.stderr, 'cannot open %s' % hdrlist
return 1
# read header list
hdr = '$I'
for line in fhdr:
if not line.startswith('#'):
param = line.split()
hdr = hdr + ',' + param[0]
fhdr.close()
if lst:
for line in fimg:
if not line.startswith('#'):
im_file = line[:-1]
iraf.hselect(im_file,hdr,expr='yes')
fimg.close()
else:
#print hdr
iraf.hselect(img,hdr,expr='yes')
return 0
if __name__=="__main__":
usage = "usage: %prog image header_list [options]"
parser = OptionParser(usage)
parser.add_option("--list", dest="lst", action="store_true", default=False,
help="input list instead of image (default=False)")
(options, args) = parser.parse_args()
if len(args) != 2:
parser.print_help()
sys.exit()
pyhselect(args[0],args[1],lst=options.lst)