-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_crlb.py
216 lines (163 loc) · 9.08 KB
/
test_crlb.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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import numpy
from matplotlib import pyplot
from matplotlib import colors
from scipy.constants import c
from cramer_rao_bound import telescope_bounds
from cramer_rao_bound import small_matrix
from cramer_rao_bound import large_matrix
from cramer_rao_bound import sky_model_matrix_populator
from cramer_rao_bound import absolute_calibration_crlb
from src.util import redundant_baseline_finder
from src.util import hexagonal_array
from src.plottools import colorbar
from src.radiotelescope import RadioTelescope
from src.radiotelescope import AntennaPositions
from src.radiotelescope import BaselineTable
from src.skymodel import sky_moment_returner
from src.covariance import sky_covariance
def test_plot():
path = "data/MWA_Compact_Coordinates.txt"
print("")
print("Redundant Calibration Errors")
mwa_hexes_antennas, mwa_hexes_redundant = telescope_bounds(path, bound_type="redundant",
position_precision= 1e-1)
print("")
print("Sky Model")
mwa_hexes_antennas, mwa_hexes_sky = telescope_bounds(path, bound_type="sky")
pyplot.show()
# pyplot.semilogy(mwa_hexes_antennas, mwa_hexes_redundant[0], marker="+", label="Relative")
# pyplot.semilogy(mwa_hexes_antennas, mwa_hexes_redundant[1], marker="x", label="Absolute")
# pyplot.semilogy(mwa_hexes_antennas, mwa_hexes_sky, marker="*", label="Sky")
# pyplot.legend()
# pyplot.show()
return
def test_fim_approximation(nu = 150e6, position_precision = 1e-2):
path = "data/MWA_Compact_Coordinates.txt"
telescope = RadioTelescope(load=True, path=path)
sky_based_model = numpy.sqrt(sky_moment_returner(n_order=2, s_low=1, s_high=10))
redundant_baselines = redundant_baseline_finder(telescope.baseline_table, group_minimum=1)
# pyplot.plot(redundant_baselines.antenna_id1, redundant_baselines.group_indices, "ro")
# pyplot.plot(redundant_baselines.antenna_id2, redundant_baselines.group_indices, "ro")
# pyplot.show()
antenna_baseline_matrix, red_tiles = sky_model_matrix_populator(redundant_baselines)
jacobian_matrix = antenna_baseline_matrix[:, :len(red_tiles)] * sky_based_model
uv_scales = numpy.array([0, position_precision / c * nu])
non_redundant_covariance = sky_covariance(nu=nu, u=uv_scales, v=uv_scales, mode='baseline')
ideal_covariance = sky_covariance(nu, u=redundant_baselines.u(nu), v=redundant_baselines.v(nu),
mode='baseline')
dense_crlb, dense_fim = small_matrix(jacobian_matrix, non_redundant_covariance, ideal_covariance)
sparse_crlb, sparse_fim = large_matrix(redundant_baselines,jacobian_matrix, non_redundant_covariance)
# numpy.save("dense", dense_crlb)
numpy.save("sparse", sparse_crlb)
fig, axes = pyplot.subplots(2, 3, figsize = (15, 10))
norm = colors.Normalize()
denseplot = axes[0, 0].imshow(dense_crlb, norm = norm, interpolation = 'none')
sparseplot = axes[0, 1].imshow(sparse_crlb, norm = norm, interpolation = 'none')
norm = colors.Normalize()
diffplot = axes[0, 2].imshow(sparse_crlb - dense_crlb, norm = norm, interpolation = 'none')
colorbar(denseplot)
colorbar(sparseplot)
colorbar(diffplot)
norm = colors.Normalize()
dense_fimplot = axes[1, 0].imshow(dense_fim, norm = norm, interpolation = 'none')
sparse_fimplot = axes[1, 1].imshow(sparse_fim, norm = norm, interpolation = 'none')
norm = colors.Normalize()
diff_fimplot = axes[1, 2].imshow(sparse_fim - dense_fim, norm = norm, interpolation = 'none')
colorbar(dense_fimplot)
colorbar(sparse_fimplot)
colorbar(diff_fimplot)
axes[0, 0].set_title("Dense CRLB")
axes[0, 1].set_title("Sparse CRLB")
axes[0, 2].set_title("Sparse - Dense")
axes[1, 0].set_title("Dense FIM")
axes[1, 1].set_title("Sparse FIM")
axes[1, 2].set_title("Sparse - Dense")
axes[0, 0].set_ylabel("Antenna Index")
axes[1, 0].set_ylabel("Antenna Index")
axes[1, 0].set_xlabel("Antenna Index")
axes[1, 1].set_xlabel("Antenna Index")
axes[1, 2] .set_xlabel("Antenna Index")
pyplot.show()
return
def test_absolute_calibration():
path = "data/MWA_Hexes_Coordinates.txt"
telescope = RadioTelescope(load=True, path=path)
baseline_table = redundant_baseline_finder(telescope.baseline_table, group_minimum=1)
absolute_calibration_crlb(baseline_table)
position_precision = 1e-2
nu = 150e6
sky_based_model = numpy.sqrt(sky_moment_returner(n_order=2, s_low=1, s_high=10))
jacobian_vector = numpy.zeros(baseline_table.number_of_baselines) + sky_based_model
uv_scales = numpy.array([0, position_precision / c * nu])
non_redundant_block = sky_covariance(nu=nu, u=uv_scales, v=uv_scales, mode='baseline')
ideal_covariance = sky_covariance(nu=nu, u=baseline_table.u_coordinates,
v=baseline_table.v_coordinates, mode='baseline')
small_crlb = small_matrix(jacobian_vector, non_redundant_block, ideal_covariance)
large_crlb = large_matrix(baseline_table, jacobian_vector, non_redundant_block)
print(f"small crlb {small_crlb}")
print(f"large crlb {large_crlb}")
return
def test_compare_old_new_results():
# new_path = "/data/rjoseph/Hybrid_Calibration/theoretical_calculations/general_hex/"
new_path = "/data/rjoseph/Hybrid_Calibration/theoretical_calculations/new_general_hex_including_covariances/"
old_red_crlb = numpy.loadtxt("TESTING_redundant_crlb.txt")
old_sky_crlb = numpy.loadtxt("TESTING_skymodel_crlb.txt")
new_red_crlb = numpy.loadtxt(new_path + "redundant_crlb.txt")
new_sky_crlb = numpy.loadtxt(new_path + "skymodel_crlb.txt")
fig, axes = pyplot.subplots(1, 2, figsize=(10, 5))
axes[0].plot(old_red_crlb[0, :], numpy.sqrt(old_red_crlb[1, :] + old_red_crlb[2, :]), color = "C0", label="Total")
axes[0].plot(old_red_crlb[0, :], numpy.sqrt(old_red_crlb[1, :]), color = "C1", label="Relative")
axes[0].plot(old_red_crlb[0, :], numpy.sqrt(old_red_crlb[2, :]), color = "C2", label="Absolute")
axes[0].plot(old_red_crlb[0, :], numpy.sqrt(old_red_crlb[3, :]), color ="k", label="Thermal")
axes[0].plot(new_red_crlb[0, :], numpy.sqrt(new_red_crlb[1, :] + new_red_crlb[2, :]), color = "C0", linestyle= "--")
axes[0].plot(new_red_crlb[0, :], numpy.sqrt(new_red_crlb[1, :]), color = "C1", linestyle = "--")
axes[0].plot(new_red_crlb[0, :], numpy.sqrt(new_red_crlb[2, :]), color = "C2",linestyle = "--")
axes[0].plot(new_red_crlb[0, :], numpy.sqrt(new_red_crlb[3, :]), color ="k",linestyle = "--")
axes[0].set_ylabel("Gain Variance")
axes[0].set_yscale('log')
axes[1].semilogy(old_sky_crlb[0, :], numpy.sqrt(old_sky_crlb[1, :]), color = "C0", label="Sky Calibration")
axes[1].semilogy(old_sky_crlb[0, :], numpy.sqrt(old_sky_crlb[2, :]), color ="k", label="Thermal")
axes[1].semilogy(new_sky_crlb[0, :], numpy.sqrt(new_sky_crlb[1, :]), color = "C0", linestyle= "--")
axes[1].semilogy(new_sky_crlb[0, :], numpy.sqrt(new_sky_crlb[2, :]), color ="k", linestyle= "--")
axes[0].set_xlabel("Number of Antennas")
axes[1].set_xlabel("Number of Antennas")
axes[0].set_ylim([1e-4, 1])
axes[1].set_ylim([1e-4, 1])
axes[0].legend()
axes[1].legend()
pyplot.show()
return
def test_group_single_fim(nu = 150e6, position_precision = 1e-2):
telescope = RadioTelescope(load=False)
antenna_positions = hexagonal_array(4)
telescope.antenna_positions = AntennaPositions(load=False)
telescope.antenna_positions.antenna_ids = numpy.arange(0, antenna_positions.shape[0], 1)
telescope.antenna_positions.x_coordinates = antenna_positions[:, 0]
telescope.antenna_positions.y_coordinates = antenna_positions[:, 1]
telescope.antenna_positions.z_coordinates = antenna_positions[:, 2]
telescope.baseline_table = BaselineTable(position_table=telescope.antenna_positions)
redundant_baselines = redundant_baseline_finder(telescope.baseline_table, group_minimum=3)
sky_based_model = numpy.sqrt(sky_moment_returner(n_order=2, s_low=1, s_high=10))
antenna_baseline_matrix, red_tiles = sky_model_matrix_populator(redundant_baselines)
uv_scales = numpy.zeros(2)
non_redundant_covariance = sky_covariance(nu=nu, u=uv_scales, v=uv_scales, mode='baseline')
print(numpy.linalg.cond(non_redundant_covariance))
print(numpy.linalg.pinv(non_redundant_covariance))
print(1/non_redundant_covariance[0, 0])
non_redundant_covariance += numpy.diag(numpy.zeros(len(uv_scales)) + 9)
print(numpy.linalg.cond(non_redundant_covariance))
print(numpy.linalg.pinv(non_redundant_covariance))
print(1 / non_redundant_covariance[0, 0])
uv_scales = numpy.array([0, 1e-2/c*nu])
non_redundant_covariance = sky_covariance(nu=nu, u=uv_scales, v=uv_scales, mode='baseline')
non_redundant_covariance += numpy.diag(numpy.zeros(len(uv_scales)) + 9)
print(numpy.linalg.cond(non_redundant_covariance))
print(numpy.linalg.pinv(non_redundant_covariance))
print(1 / non_redundant_covariance[0, 0])
return
if __name__ == "__main__":
# test_plot()
# test_fim_approximation()
# test_absolute_calibration()
# test_compare_old_new_results()
test_group_single_fim()