-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_antpos_to_sim.py
executable file
·76 lines (64 loc) · 2.54 KB
/
add_antpos_to_sim.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/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2018 UPennEoR
# Licensed under the 2-clause BSD License
from __future__ import print_function, division, absolute_import
import aipy
import numpy as np
import scipy.constants as const
import optparse, sys, os
import pyuvdata
o = optparse.OptionParser()
o.set_usage('add_uvws.py [options] *.uv')
o.set_description(__doc__)
aipy.scripting.add_standard_options(o, cal=True)
opts, args = o.parse_args(sys.argv[1:])
print('opts.cal', opts.cal)
#uv_latlonalt = pyuvdata.UVData()
#uv_latlonalt.read_miriad('zen.2458098.60274.xx.HH.uv')
#lat, lon, alt = uv_latlonalt.telescope_location_lat_lon_alt
lat, lon, alt = (-0.5361918109651213, 0.37399448506783717, 1073.000000008382)
for uvfile in args:
uvofile = uvfile+'P'
print(uvfile, '->', uvofile)
if os.path.exists(uvofile):
print(uvofile, 'exists, skipping.')
continue
uvi = aipy.miriad.UV(uvfile)
uvo = aipy.miriad.UV(uvofile, status='new')
#aa = aipy.phs.ArrayLocation(('-30:43:17.5','21:25:41.9'))
#get the positions in the rotated ECEF coordinates
aa = aipy.cal.get_aa(opts.cal,np.array([0.15]))
ENU_antpos = aa.antpos_ideal.T
ECEF_antpos = pyuvdata.ECEF_from_ENU(ENU_antpos, lat, lon, alt)
rotECEF_antpos = pyuvdata.rotECEF_from_ECEF(ECEF_antpos.T, lon) * 10**9 / const.c
#nints = 0
#curtime = None
#format it so unused ants are at 0, 0, 0, as pyuvdata expects
for i in range(len(ENU_antpos[0])):
if (ENU_antpos.T[i]==[-1.,-1.,-1.]).all():
rotECEF_antpos[i] = [0.,0.,0.]
#make sure that there are the appropriate number of antennae in the position file
nants = uvi['nants']
cal_nants = rotECEF_antpos.shape[0]
if nants > cal_nants:
for i in range(nants-cal_nants):
rotECEF_antpos = np.append(rotECEF_antpos, [[0.,0.,0.]], axis=0)
elif nants < cal_nants:
rotECEF_antpos = rotECEF_antpos[:nants]
#flatten coords into a single list, as miriad expects them to be saved
rotECEF_antpos = rotECEF_antpos.T.flatten()
def mfunc(uv, preamble, data, flags):
# global curtime
# global nints
# #print curtime, nints
# uvw, t, (i,j) = preamble
# #print 'uvw',uvw
# del uvw
# uvw = aa.get_baseline(i,j,'z')
# #print 'uvw from aa'
# #print uvw
# preamble = (uvw, t, (i,j))
return preamble, data, flags
uvo.init_from_uv(uvi,override={'antpos':rotECEF_antpos})
uvo.pipe(uvi, mfunc=mfunc, raw=True, append2hist=' '.join(sys.argv)+'\n')