Skip to content

Commit bf5bf0b

Browse files
committed
use setfconfig(coordsystem) option instead of manually converting to itrf
1 parent c89fdfe commit bf5bf0b

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

simms/casasm.py

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ def get_int_data(tab):
1717
return (x,y,z),dish_diam,station,mount
1818

1919

20+
def wgs84_2xyz(pos_wgs84):
21+
""" convert wgs84 to itrf """
22+
23+
pos_itrf = np.zeros(pos_wgs84.shape)
24+
for i,(x,y,z) in enumerate(pos_wgs84):
25+
p = me.position("wgs84", "%fdeg"%x, "%fdeg"%y, "%fm"%z)
26+
pos_itrf[i] = me.addxvalue( me.measure(p, "itrf"))["value"]
27+
28+
return pos_itrf
29+
30+
2031
def enu2xyz (refpos_wgs84,enu):
2132
""" converts xyz0 + ENU (Nx3 array) into xyz """
2233
refpos = me.measure(refpos_wgs84,'itrf')
@@ -28,8 +39,8 @@ def enu2xyz (refpos_wgs84,enu):
2839
[-math.cos(lon)*math.sin(lat),-math.sin(lon)*math.sin(lat),math.cos(lat)],
2940
[math.cos(lat)*math.cos(lon),math.cos(lat)*math.sin(lon),math.sin(lat)]
3041
])
31-
32-
xyz = xyz0[np.newaxis,:] + enu.dot(xform);
42+
43+
xyz = xyz0[np.newaxis,:] + enu.dot(xform)
3344
return xyz
3445

3546

@@ -80,28 +91,32 @@ def toFloat(val):
8091

8192
obs_pos = None
8293
lon,lat = None,None
83-
if lon_lat:
94+
if lon_lat not in [None,"None"]:
8495
if isinstance(lon_lat,str):
8596
tmp = lon_lat.split(',')
8697
lon,lat = ['%sdeg'%i for i in tmp[:2]]
8798
if len(tmp)>2:
88-
el = tmp[3]+'m'
99+
el = tmp[2]+'m'
89100
else:
90101
el = '0m'
91102
obs_pos = me.position('wgs84',lon,lat,el)
92103
obs_pos = obs_pos or me.observatory(tel)
104+
me.doframe(obs_pos)
93105

94106
sm.open(msname)
95107

96108
if fromknown:
97-
sm.setknownconfig('ATCA6.0A')
109+
sm.setknownconfig(tel)
110+
98111
elif pos:
99112
if pos_type.lower() == 'casa':
100113
tb.open(pos)
101114
(xx,yy,zz),dish_diam,station,mount = get_int_data(tb)
102115
tb.close()
103-
116+
coords = 'itrf'
117+
104118
elif pos_type.lower() == 'ascii':
119+
zz = np.zeros(len(pos))
105120
if noup:
106121
names = ['x','y','dd','station','mount']
107122
ncols = 5
@@ -111,25 +126,35 @@ def toFloat(val):
111126
dtype = ['float']*ncols
112127
dtype[-2:] = ['|S20']*2
113128
pos = np.genfromtxt(pos,names=names,dtype=dtype,usecols=range(ncols))
114-
115-
if coords is 'enu':
116-
if noup:
117-
xyz = np.array([pos['x'],pos['y']]).T
118-
else:
119-
xyz = np.array([pos['x'],pos['y'],pos['z']]).T
120-
xyz = enu2xyz(obs_pos,xyz)
121-
xx,yy,zz = xyz[:,0], xyz[:,1],xyz[:,2]
122-
else:
123-
xx,yy,zz = pos['x'],pos['y'],pos['z']
129+
130+
131+
# if coords in ["enu","wgs84"]:
132+
# if noup:
133+
134+
# zz = np.zeros(len(pos))
135+
# xyz = np.array([pos['x'],pos['y'],zz]).T
136+
#else:
137+
# xyz = np.array([pos['x'],pos['y'],pos['z']]).T
138+
139+
#xyz = wgs84_2xyz(xyz) if coords=="wgs84" else enu2xyz(obs_pos,xyz)
140+
141+
#xx,yy,zz = xyz[:,0], xyz[:,1],xyz[:,2]
142+
#else:
143+
144+
xx,yy,zz = pos['x'], pos['y'], zz if noup else pos['z']
124145

125146
dish_diam,station,mount = pos['dd'],pos['station'],pos['mount']
147+
148+
coord_sys = dict(itrf="global", enu="local", wgs84="longlat")
149+
126150
sm.setconfig(telescopename=tel,
127151
x=xx,
128152
y=yy,
129153
z=zz,
130154
dishdiameter=dish_diam,
131-
mount=mount[0],
132-
coordsystem='global',
155+
mount= list(mount),
156+
coordsystem= coord_sys.get(coords,'global'),
157+
antname = list(station),
133158
referencelocation=obs_pos)
134159

135160
else:

simms/simms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def toList(string,delimiter=',',f0=False):
141141
'scan_length=%(scan_length).4g, dtime="%(dtime)s", freq0=%(freq0)s, dfreq=%(dfreq)s, '\
142142
'nchan=%(nchan)s, stokes="%(stokes)s", start_time=%(start_time)s, setlimits=%(setlimits)s, '\
143143
'elevation_limit=%(elevation_limit)f, shadow_limit=%(shadow_limit)f, '\
144-
'coords="%(coords)s",lon_lat=%(lon_lat)s, noup=%(noup)s, nbands=%(nbands)d, '\
144+
'coords="%(coords)s",lon_lat="%(lon_lat)s", noup=%(noup)s, nbands=%(nbands)d, '\
145145
'direction=%(direction)s, outdir="%(outdir)s",date="%(date)s",fromknown=%(fromknown)s, '\
146146
'feed="%(feed)s"'%locals()
147147
casa_script.write('makems(%s)\nexit'%fmt)
@@ -253,7 +253,7 @@ def main():
253253
add('pos',help='Antenna positions')
254254
add('-t','--type',dest='type',default='casa',choices=['casa','ascii'],
255255
help='position list type : dafault is casa')
256-
add('-cs','--coord-sys',dest='coords',default='itrf',choices=['itrf','enu'],
256+
add('-cs','--coord-sys',dest='coords',default='itrf',choices=['itrf','enu','wgs84'],
257257
help='Only relevent when --type=ascii. Coordinate system of antenna positions.'
258258
' :dafault is itrf')
259259
add('-lle','--lon-lat-elv',dest='lon_lat',

0 commit comments

Comments
 (0)