forked from tammojan/facet-calibration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makecleanmask_10sb_wsclean.py
executable file
·70 lines (48 loc) · 2.28 KB
/
makecleanmask_10sb_wsclean.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
67
68
69
70
#!/usr/bin/python
if __name__ == '__main__':
import os
import numpy
import pyrap.images
import pyfits
import sys
import lofar.bdsm as bdsm
argc=len(sys.argv)
from optparse import OptionParser
parser = OptionParser(usage='%prog [options] <Input image>')
#parser.add_option('--outfile', dest='file_clusters', help='Name of the output skymodel file [default catalogue.clusters.skymodel]', \
# metavar='VAL', default='catalog.clusters.skymodel')
parser.add_option('--threshpix', dest='threshpix', help='Pixel threshold [default: 5]', metavar='VAL', default=5)
parser.add_option('--threshisl', dest='threshisl', help='Island threshold [default: 3]', metavar='VAL', default=3)
parser.add_option('--atrous_do', dest='atrous_do', help='Decompose in wavelet scales threshold [default: False]', metavar='VAL', default='False')
parser.add_option('--casaregion',dest='casaregion',help='Casa region file [default: ""]', metavar='VAL', default='')
(o, args) = parser.parse_args()
# convert to boolean
if o.atrous_do == 'False':
o.atrous_do = False
else:
o.atrous_do = True
o.threshisl = 3.0
print 'Changing island threshold to 3 because atrous_do=True'
image_name = args[0]
mask_name = image_name.split('-image.fits')[0] + '.fitsmask'
print '\n\n\n'
print 'Making mask:', mask_name
print '\n\n\n'
os.system('rm -rf ' + mask_name)
# DO THE SOURCE DETECTION
img = bdsm.process_image(image_name, mean_map='zero', rms_box=(60,10), thresh_pix=numpy.float(o.threshpix), \
thresh_isl=numpy.float(o.threshisl), atrous_do=o.atrous_do, \
adaptive_rms_box=False, adaptive_thresh=150, rms_box_bright=(60,10), atrous_jmax=3)
#img.show_fit()
# WRITE THE MASK FITS
img.export_image(img_type='island_mask', img_format='fits', outfile=mask_name)
# convert mask to casapy format
#sys.exit()
#img = pyrap.images.image(mask_name)
#pixels = numpy.copy(img.getdata())
#pixels_mask = 0.*numpy.copy(pixels)
#hdulist = pyfits.open(maskmodel + '.fits')
#pixels_gs = hdulist[0].data
#idx = numpy.where(pixels_gs > 0.0)
#pixels_mask[idx] = 1.0
#img.putdata(pixels_mask)