forked from tammojan/facet-calibration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makecleanmask_field_wsclean.py
executable file
·76 lines (53 loc) · 2.61 KB
/
makecleanmask_field_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
71
72
73
74
75
76
#!/usr/bin/python
import os
import sys
import lofar.bdsm as bdsm
import logging
def do_makecleanmask_field_wsclean(image_name,threshpix,threshisl,atrousdo,ncores=8):
mask_name = image_name.split('-image')[0] + '.fitsmask'
logging.info('makecleanmask_field_wsclean: Making mask: '+mask_name)
if atrousdo:
threshisl = 3.0
logging.info('Changing island threshold to %.1f because atrous_do=True' % threshisl)
os.system('rm -rf ' + mask_name)
# DO THE SOURCE DETECTION
img = bdsm.process_image(image_name, mean_map='zero',
rms_box=(300,60), thresh_pix=threshpix,
thresh_isl=threshisl,
atrous_do=atrousdo,
adaptive_rms_box=True,
adaptive_thresh=150,
rms_box_bright=(70,10),
atrous_jmax=3,ncores=ncores)
#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)
if __name__ == '__main__':
#reproduce old command line behaviour
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
image_name = args[0]
do_makecleanmask_field_wsclean(image_name,float(o.threshpix),float(o.threshisl),o.atrous_do)