forked from tammojan/facet-calibration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fitsandregion2image.py
50 lines (37 loc) · 1.11 KB
/
fitsandregion2image.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
import os
import sys
import numpy
el=len(sys.argv)
#print sys.argv[:]
inputim = sys.argv[el-3]
imageout = sys.argv[el-2]
region = sys.argv[el-1]
print 'inputim', inputim
print 'imageout', imageout
print 'region', region
# don't importfits here to work round CASA bug
# conversion is done in calling code instead
#importfits(fitsimage=inputim,imagename=imageout,whichrep=0,\
# whichhdu=-1,zeroblanks=True,overwrite=True,defaultaxes=False,\
# defaultaxesvalues=[],beam=[])
if region != 'None':
print 'We have a region file', region
ia.open(imageout)
myRGN = rg.fromtextfile(filename=region, shape=ia.shape(), csys=ia.coordsys().torecord())
im.regiontoimagemask(mask=imageout, region=myRGN)
ia.close()
# avoid cleaning the edges of the image
edge = 25
tb.open(imageout, nomodify=False)
data = numpy.copy(tb.getcol('map'))
print numpy.shape(data)
sh = numpy.shape(data)
print sh
# mask edges
data[0:sh[0],0:edge,0,0,0] = 0
data[0:edge,0:sh[1],0,0,0] = 0
data[0:sh[0],sh[1]-edge:sh[1],0,0,0] = 0
data[sh[0]-edge:sh[0],0:sh[1],0,0,0] = 0
tb.putcol('map', data)
tb.flush()
tb.close()