-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseline_delay_horizon.py
More file actions
197 lines (150 loc) · 7.06 KB
/
baseline_delay_horizon.py
File metadata and controls
197 lines (150 loc) · 7.06 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import numpy as NP
import geometry as GEOM
# import pdb as PDB
def delay_envelope(bl, dircos, units='mks'):
"""
---------------------------------------------------------------------------
Estimates the delay envelope determined by the sky horizon for given
baseline(s) for the phase centers specified by sky positions in direction
cosines.
Inputs:
bl: E, N, and U components of baseline vectors in a Mx3 numpy
array in local ENU coordinates
dircos: Nx3 (direction cosines) numpy array of sky positions
units: 'mks' or 'cgs' units. Default='mks'
Outputs:
delaymatrix: NxMx2 matrix. delaymatrix[:,:,0] contains the maximum delay.
delaymatrix[:,:,1] contains the delay shift. To determine the
minimum delay, use delaymatrix[:,:,1]-delaymatrix[:,:,0]
---------------------------------------------------------------------------
"""
try:
bl
except NameError:
raise NameError('No baseline(s) provided. Aborting delay_envelope().')
try:
dircos
except NameError:
print 'No sky position in direction cosine units provided. Assuming zenith for phase center in delay_envelope().'
dircos = NP.zeros(3).reshape(1,3)
try:
units
except NameError:
print 'No units provided. Assuming MKS units.'
units = 'mks'
if (units != 'mks') and (units != 'cgs'):
print 'Units should be specified to be one of MKS or CGS. Default=MKS'
print 'Proceeding with MKS units.'
units = 'mks'
# Set the speed of light in MKS or CGS units
if units == 'mks': c = 2.99792458e8
elif units == 'cgs': c = 2.99792458e10
if len(bl.shape) == 1: bl = bl.reshape(1,len(bl))
if len(dircos.shape) == 1: dircos = dircos.reshape(1,len(dircos))
blshape = bl.shape
dcshape = dircos.shape
bl = bl[:,:min(blshape[1],dcshape[1])]
dircos = dircos[:,:min(blshape[1],dcshape[1])]
if blshape[1] > min(3,blshape[1],dcshape[1]):
bl = bl[:,:min(3,blshape[1],dcshape[1])]
if dcshape[1] > min(3,blshape[1],dcshape[1]):
dircos = dircos[:,:min(3,blshape[1],dcshape[1])]
blshape = bl.shape
dcshape = dircos.shape
eps = 1.0e-10
if NP.any(NP.sqrt(NP.sum(dircos**2,axis=1)) > 1.0+eps):
raise ValueError('Certain direction cosines exceed unit magnitude. Check inputs.')
elif dcshape[1] == 3:
if NP.any(NP.absolute(NP.sqrt(NP.sum(dircos**2,axis=1)) - 1.0) > eps):
raise ValueError('Magnitude of vector of direction cosines have to equal unity. Check inputs.')
# if NP.any(NP.sqrt(NP.sum(dircos**2,axis=1)) > 1.0+eps)):
# raise ValueError('Magnitude of vector of direction cosines have to equal unity. Check inputs.')
if NP.any(dircos[:,2] < 0.0):
raise ValueError('Direction cosines should lie on the upper hemisphere. Check inputs.')
delaymatrix_max = NP.repeat(NP.sqrt(NP.sum(bl.T**2,axis=0)).reshape(1,blshape[0]), dcshape[0], axis=0)/c
delaymatrix_shift = NP.dot(dircos, bl.T)/c
delaymatrix = NP.dstack((delaymatrix_max, delaymatrix_shift))
return delaymatrix
##########################################################################
def geometric_delay(baselines, skypos, altaz=False, dircos=False, hadec=True,
units='mks', latitude=None):
"""
---------------------------------------------------------------------
Estimates the geometric delays matrix for different baselines from
different sky positions.
Inputs:
baselines: x, y, and z components of baseline vectors in a Mx3 numpy
array
skypos: Nx2 (Alt-Az or HA-Dec) or Nx3 (direction cosines) numpy array
of sky positions
altaz: [Boolean flag, default=False] If True, skypos is in Alt-Az
coordinates system
hadec: [Boolean flag, default=True] If True, skypos is in HA-Dec
coordinates system
dircos: [Boolean flag, default=False] If True, skypos is in direction
cosines coordinates system
units: Units of baselines. Default='mks'. Alternative is 'cgs'.
latitude: Latitude of the observatory. Required if hadec is True.
Outputs:
geometric delays [NxM numpy array] Geometric delay for every combination
of baselines and skypos.
---------------------------------------------------------------------
"""
try:
baselines, skypos
except NameError:
raise NameError('baselines and/or skypos not defined in geometric_delay().')
if (altaz)+(dircos)+(hadec) != 1:
raise ValueError('One and only one of altaz, dircos, hadec must be set to True.')
if hadec and (latitude is None):
raise ValueError('Latitude must be specified when skypos is in HA-Dec format.')
try:
units
except NameError:
print 'No units provided. Assuming MKS units.'
units = 'mks'
if (units != 'mks') and (units != 'cgs'):
print 'Units should be specified to be one of MKS or CGS. Default=MKS'
print 'Proceeding with MKS units.'
units = 'mks'
if not isinstance(baselines, NP.ndarray):
raise TypeError('baselines should be a Nx3 numpy array in geometric_delay().')
if len(baselines.shape) == 1:
baselines = baselines.reshape(1,-1)
if baselines.shape[1] == 1:
baselines = NP.hstack(baselines, NP.zeros((baselines.size,2)))
elif baselines.shape[1] == 2:
baselines = NP.hstack(baselines, NP.zeros((baselines.size,1)))
elif baselines.shape[1] > 3:
baselines = baselines[:,:3]
if altaz or hadec:
if len(skypos.shape) < 2:
if skypos.size != 2:
raise ValueError('Sky position in altitude-azimuth or HA-Dec should consist of 2 elements.')
else:
skypos = skypos.reshape(1,-1)
elif len(skypos.shape) > 2:
raise ValueError('Sky positions should be a Nx2 numpy array if using altitude-azimuth of HA-Dec.')
else:
if skypos.shape[1] != 2:
raise ValueError('Sky positions should be a Nx2 numpy array if using altitude-azimuth of HA-Dec.')
if altaz:
dc = GEOM.altaz2dircos(skypos, 'degrees')
else:
dc = GEOM.altaz2dircos(GEOM.hadec2altaz(skypos, latitude, 'degrees'), 'degrees')
else:
if len(skypos.shape) < 2:
if skypos.size != 3:
raise ValueError('Sky position in direction cosines should consist of 3 elements.')
else:
skypos = skypos.reshape(1,-1)
elif len(skypos.shape) > 2:
raise ValueError('Sky positions should be a Nx3 numpy array if using direction cosines.')
else:
if skypos.shape[1] != 3:
raise ValueError('Sky positions should be a Nx3 numpy array if using direction cosines.')
dc = skypos
# geometric_delays = delay_envelope(baselines, dc, units)[:,:,-1]
geometric_delays = NP.dot(dc, baselines.T)/c
return geometric_delays
##########################################################################