-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaper.py
executable file
·45 lines (40 loc) · 1.4 KB
/
taper.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
#!/usr/bin/env python
import sys
import fileinput
import math
from cStringIO import StringIO
from pyrap.measures import measures
EPOCH = 'J2000'
def gaussian_cutoff(limit, fwhm, ra, dec):
limit = float(limit)
fwhm = float(fwhm)
dm = measures()
centre = dm.direction(EPOCH, ra, dec)
constant = -4 * math.log(2) / float(fwhm)**2
def flux_limit(ra, dec):
target = dm.direction(EPOCH, ra, dec)
distance = dm.separation(centre, target).get_value()
return limit * (1 - math.exp(constant * distance**2))
return flux_limit
def parse_skymodel(calculate_limit):
output = StringIO()
for line in fileinput.input("-"):
if "format" in line:
output.write(line)
continue
ra = line.split(',')[2]
dec = line.split(',')[3]
flux = float(line.split(',')[4])
limiting_flux = calculate_limit(ra, dec)
if flux > limiting_flux:
output.write(line)
return output.getvalue()
if __name__ == "__main__":
try:
calculate_limit = gaussian_cutoff(*sys.argv[1:5])
print parse_skymodel(calculate_limit)
except Exception, e:
print "taper.py -- Applies Gaussian taper to skymodel\n"
print "Usage: taper.py <flux_limit> <fwhm> <ra> <dec> < [input] > [output]"
print "Reads input sky model from stdin, outputs to stdout.\n"
print >>sys.stderr, "Error: %s" % (str(e),)