-
Notifications
You must be signed in to change notification settings - Fork 3
/
make_weights.py
66 lines (55 loc) · 1.84 KB
/
make_weights.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
62
63
64
65
66
try:
from astropy.io import fits as pyfits
except ImportError:
import pyfits
import sys,os
from optparse import OptionParser
suffix='.2d.fits'
origsuffix='_beamI.fits'
newsuffix='.weight.fits'
usage="Usage: %prog [options] <images>\n"
parser = OptionParser(usage=usage)
parser.add_option('-t','--threshold',dest='threshold',default=0.05,
type='float',
help='Beam threshold [default=%default]')
parser.add_option('--reduce',dest='reduce',default=False,
action='store_true',
help='Reduce dimensionality of input images?')
(options, args) = parser.parse_args()
for file in args:
root,ext=os.path.splitext(file)
beamfile=root + origsuffix
if not os.path.exists(file):
print 'Cannot find image file %s' % file
sys.exit(0)
if options.reduce:
f=pyfits.open(file)
f[0].data=f[0].data[0,0]
if f[0].header['CRVAL1']<0:
f[0].header['CRVAL1']+=360
f.verify('fix')
newfile=root + suffix
if os.path.exists(newfile):
os.remove(newfile)
f.writeto(newfile)
f.close()
print '%s -> %s' % (file, newfile)
newroot,newext=os.path.splitext(newfile)
else:
newroot, newext=root, ext
weightfile=newroot + newsuffix
if not os.path.exists(beamfile):
print 'Beam file %s does not exist' % beamfile
sys.exit(1)
f=pyfits.open(beamfile)
f[0].data[f[0].data<options.threshold]=0
f[0].data=f[0].data[0,0]**2
if f[0].header['CRVAL1']<0:
f[0].header['CRVAL1']+=360
f[0].header['BMTHRESH']=(options.threshold,'Threshold for primary beam correction')
f.verify('fix')
if os.path.exists(weightfile):
os.remove(weightfile)
f.writeto(weightfile)
f.close()
print '%s -> %s' % (beamfile,weightfile)