-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgain2matlabcube.py
More file actions
executable file
·58 lines (46 loc) · 1.97 KB
/
gain2matlabcube.py
File metadata and controls
executable file
·58 lines (46 loc) · 1.97 KB
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
#!/usr/bin/env python
from pyrap.tables import table
import argparse
import numpy as np
import cmath
import scipy.io
import sys
def gain2matlab(msname='test1.MS', gainfilename='bbsgain.mat', instrumentname='instrument'):
parmdb=msname+'/'+instrumentname
antenna=msname+'/ANTENNA'
valstable=table(parmdb,ack=False)
namestable=table(parmdb+"::NAMES",ack=False)
antennatable=table(antenna,ack=False)
vals=valstable.col('VALUES')
names=namestable.col('NAME')
antennas=antennatable.col('NAME')
antennamap={};
for i in range(antennas.nrows()):
antennamap[antennas[i]]=i
ntimes=vals[0].shape[0]
nch=vals[0].shape[1]
print "NTimes:",ntimes,", nch:",nch
g = np.zeros((len(antennamap)*2,2,ntimes,nch),dtype=np.complex)
for ch in range(nch):
for timeslot in range(ntimes):
for i in range(vals.nrows()):
(bla, xcor, ycor, reim, ant) = names[i].split(':')
antnr=antennamap[ant]
(xcor,ycor)=(int(xcor),int(ycor))
if reim=="Real":
val=vals[i][timeslot][ch]
elif reim=="Imag":
val=vals[i][timeslot][ch]*(1.j)
elif reim=="Phase":
val=cmath.rect(1,vals[i][timeslot][ch])
#print antnr, xcor, ycor, antnr*2+xcor, ycor, val
g[antnr*2+ycor][xcor][timeslot][ch]+=val.conjugate()
scipy.io.savemat(gainfilename, dict(gcube=g), oned_as='row')
print "Stored gains from", msname, "/",instrumentname,"as",gainfilename
if __name__ == '__main__':
parser = argparse.ArgumentParser(description = "Extract gains from an instrument file, save in matlab format")
parser.add_argument("msname", help="Name of the MS that contains data, model data and instrument table")
parser.add_argument("-i", "--instrumentname", help="Name of instrument table", default="instrument")
parser.add_argument("-o", "--output", help="Save output in this output file", default="bbsgain.mat")
args = parser.parse_args()
gain2matlab(msname=args.msname,gainfilename=args.output,instrumentname=args.instrumentname)