|
@@
-40,12
+40,17
|
|
40
|
## Plot of antenna positions
|
|
40
|
## Plot of antenna positions
|
|
41
|
plt.figure(1)
|
|
41
|
plt.figure(1)
|
|
42
|
plt.plot(rx, ry, 'ro')
|
|
42
|
plt.plot(rx, ry, 'ro')
|
|
|
|
|
43
|
plt.title("Jicamarca Antenna Positions")
|
|
|
|
|
44
|
plt.xlabel("rx")
|
|
|
|
|
45
|
plt.ylabel("ry")
|
|
|
|
|
46
|
plt.grid(True)
|
|
|
|
|
47
|
plt.plot(rx, rx, 'b-')
|
|
43
|
plt.draw()
|
|
48
|
plt.draw()
|
|
44
|
|
|
49
|
|
|
45
|
## Jicamarca is nominally at a 45 degree angle
|
|
50
|
## Jicamarca is nominally at a 45 degree angle
|
|
46
|
theta = 45 - dec;
|
|
51
|
theta = 45 - dec;
|
|
47
|
|
|
52
|
|
|
48
|
## Rotation matrix from antenna coord to magnetic coord (East North)
|
|
53
|
## Rotation matrix from antenna coord to magnetic coord (East North) -> 45 degrees
|
|
49
|
theta_rad = np.radians(theta) # trig functions take radians as argument
|
|
54
|
theta_rad = np.radians(theta) # trig functions take radians as argument
|
|
50
|
val1 = float( np.cos(theta_rad) )
|
|
55
|
val1 = float( np.cos(theta_rad) )
|
|
51
|
val2 = float( np.sin(theta_rad) )
|
|
56
|
val2 = float( np.sin(theta_rad) )
|
|
@@
-58,9
+63,29
|
|
58
|
# Rotate antenna positions to magnetic coord.
|
|
63
|
# Rotate antenna positions to magnetic coord.
|
|
59
|
AR = np.dot(R.T, antpos)
|
|
64
|
AR = np.dot(R.T, antpos)
|
|
60
|
|
|
65
|
|
|
|
|
|
66
|
plt.plot(AR[0], 0*AR[1], 'yo')
|
|
|
|
|
67
|
plt.title("Jicamarca Antenna Positions")
|
|
|
|
|
68
|
plt.xlabel("rx")
|
|
|
|
|
69
|
plt.ylabel("ry")
|
|
|
|
|
70
|
plt.grid(True)
|
|
|
|
|
71
|
plt.plot(rx, 0*rx, 'g-')
|
|
|
|
|
72
|
plt.draw()
|
|
|
|
|
73
|
|
|
|
|
|
74
|
print antpos
|
|
|
|
|
75
|
print "\n"
|
|
|
|
|
76
|
print AR
|
|
|
|
|
77
|
|
|
61
|
# Only take the East component
|
|
78
|
# Only take the East component
|
|
62
|
r = AR[0,:]
|
|
79
|
r = AR[0,:]
|
|
63
|
r.sort()
|
|
80
|
r.sort()
|
|
|
|
|
81
|
|
|
|
|
|
82
|
# ---NEW---
|
|
|
|
|
83
|
r1 = AR[1,:] # longitudes / distances
|
|
|
|
|
84
|
d = 40 # separation of antennas in meters
|
|
|
|
|
85
|
theta_w = 15 # angle between antenna and point of observation in degrees
|
|
|
|
|
86
|
# arg = k*(r + d*np.cos(theta_w)) # this is the exponent argument in the corr integral
|
|
|
|
|
87
|
# --------
|
|
|
|
|
88
|
|
|
64
|
|
|
89
|
|
|
65
|
# Truth model (high and low resolution)
|
|
90
|
# Truth model (high and low resolution)
|
|
66
|
Nt = (1024.0)*(16.0) # number of pixels in truth image: high resolution
|
|
91
|
Nt = (1024.0)*(16.0) # number of pixels in truth image: high resolution
|
|
@@
-89,16
+114,16
|
|
89
|
# b = 0; # background
|
|
114
|
# b = 0; # background
|
|
90
|
|
|
115
|
|
|
91
|
# Single Gaussian
|
|
116
|
# Single Gaussian
|
|
92
|
a = np.array( [3] )
|
|
117
|
a = np.array( [3] ) # amplitude(s)
|
|
93
|
mu = np.array( [-3.0/180*np.pi] )
|
|
118
|
mu = np.array( [-3.0/180*np.pi] ) # center
|
|
94
|
sig = np.array( [2.0/180*np.pi] )
|
|
119
|
sig = np.array( [2.0/180*np.pi] ) # width
|
|
95
|
b = 0
|
|
120
|
b = 0 # background constant
|
|
96
|
|
|
121
|
|
|
97
|
# Empty matrices for factors
|
|
122
|
# Empty matrices for factors
|
|
98
|
fact = np.zeros(shape=(Nt,1))
|
|
123
|
fact = np.zeros(shape=(Nt,1))
|
|
99
|
factr = np.zeros(shape=(Nr,1))
|
|
124
|
factr = np.zeros(shape=(Nr,1))
|
|
100
|
|
|
125
|
|
|
101
|
# DFT Kernels
|
|
126
|
# Constructing Gaussian model
|
|
102
|
for i in range(0, a.size):
|
|
127
|
for i in range(0, a.size):
|
|
103
|
temp = (-(thetat-mu[i])**2/(sig[i]**2))
|
|
128
|
temp = (-(thetat-mu[i])**2/(sig[i]**2))
|
|
104
|
tempr = (-(thetar-mu[i])**2/(sig[i]**2))
|
|
129
|
tempr = (-(thetar-mu[i])**2/(sig[i]**2))
|
|
@@
-106,9
+131,9
|
|
106
|
fact[j] = fact[j] + a[i]*np.exp(temp[j]);
|
|
131
|
fact[j] = fact[j] + a[i]*np.exp(temp[j]);
|
|
107
|
for m in range(0, tempr.size):
|
|
132
|
for m in range(0, tempr.size):
|
|
108
|
factr[m] = factr[m] + a[i]*np.exp(tempr[m]);
|
|
133
|
factr[m] = factr[m] + a[i]*np.exp(tempr[m]);
|
|
109
|
|
|
|
|
|
110
|
fact = fact + b;
|
|
134
|
fact = fact + b;
|
|
111
|
factr = factr + b;
|
|
135
|
factr = factr + b;
|
|
|
|
|
136
|
|
|
112
|
|
|
137
|
|
|
113
|
# #-------------------------------------------------------------------------------------------------
|
|
138
|
# #-------------------------------------------------------------------------------------------------
|
|
114
|
# # Model for f: Square pulse
|
|
139
|
# # Model for f: Square pulse
|
|
@@
-135,8
+160,8
|
|
135
|
# factr = wind1 * (thetar - (mu - sig));
|
|
160
|
# factr = wind1 * (thetar - (mu - sig));
|
|
136
|
# fact = fact + wind2 * (-(theta-(mu+sig)));
|
|
161
|
# fact = fact + wind2 * (-(theta-(mu+sig)));
|
|
137
|
# factr = factr + wind2 * (-(thetar-(mu+sig)));
|
|
162
|
# factr = factr + wind2 * (-(thetar-(mu+sig)));
|
|
138
|
|
|
163
|
#
|
|
139
|
# fact = fact/(sum(fact)[0]*2*thbound/Nt); # normalize to integral(f)==1
|
|
164
|
# fact = np.divide(fact, (np.sum(fact)*2*thbound/Nt)); # normalize to integral(f)==1
|
|
140
|
|
|
165
|
|
|
141
|
|
|
166
|
|
|
142
|
I = sum(fact)[0];
|
|
167
|
I = sum(fact)[0];
|
|
@@
-147,6
+172,9
|
|
147
|
plt.figure(2)
|
|
172
|
plt.figure(2)
|
|
148
|
plt.plot(thetat, fact, 'r--')
|
|
173
|
plt.plot(thetat, fact, 'r--')
|
|
149
|
plt.plot(thetar, factr, 'ro')
|
|
174
|
plt.plot(thetar, factr, 'ro')
|
|
|
|
|
175
|
plt.title("Truth models")
|
|
|
|
|
176
|
plt.ylabel("Amplitude")
|
|
|
|
|
177
|
plt.legend(('High res','Low res'), loc='upper right')
|
|
150
|
plt.draw()
|
|
178
|
plt.draw()
|
|
151
|
|
|
179
|
|
|
152
|
|
|
180
|
|
|
@@
-160,7
+188,7
|
|
160
|
SNRdBvec = np.array([15]); # 15 dB
|
|
188
|
SNRdBvec = np.array([15]); # 15 dB
|
|
161
|
NN = 1; # number of trials at each SNR
|
|
189
|
NN = 1; # number of trials at each SNR
|
|
162
|
|
|
190
|
|
|
163
|
# Statistics simulation (correlation, root mean square)
|
|
191
|
# Statistics simulation (correlation, root mean square error)
|
|
164
|
corr = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial)
|
|
192
|
corr = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial)
|
|
165
|
corrc = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial)
|
|
193
|
corrc = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial)
|
|
166
|
rmse = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial)
|
|
194
|
rmse = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial)
|
|
@@
-190,22
+218,15
|
|
190
|
# positive-semi-definiteness of the matrix.
|
|
218
|
# positive-semi-definiteness of the matrix.
|
|
191
|
|
|
219
|
|
|
192
|
U = linalg.cholesky(R.astype(complex), lower=False); # U'*U = R
|
|
220
|
U = linalg.cholesky(R.astype(complex), lower=False); # U'*U = R
|
|
193
|
|
|
221
|
|
|
194
|
sigma_noise = (np.linalg.norm(U,'fro')/SNR);
|
|
222
|
sigma_noise = (np.linalg.norm(U,'fro')/SNR);
|
|
195
|
|
|
223
|
|
|
196
|
# temp1 = (-2*np.random.rand(U.shape[0], U.shape[1]) + 2)
|
|
224
|
nz = np.multiply((sigma_noise * (np.random.randn(U.shape[0]) + 1j*np.random.randn(U.shape[0]))/np.sqrt(2)), (abs(U) > 0).astype(float));
|
|
197
|
# temp2 = 1j*(-2*np.random.rand(U.shape[0], U.shape[1]) + 2)
|
|
|
|
|
198
|
# temp3 = ((abs(U) > 0).astype(float)) # upper triangle of 1's
|
|
|
|
|
199
|
# temp4 = (sigma_noise * (temp1 + temp2))/np.sqrt(2.0)
|
|
|
|
|
200
|
#
|
|
|
|
|
201
|
# nz = np.multiply(temp4,temp3)
|
|
|
|
|
202
|
|
|
|
|
|
203
|
nz = np.multiply( sigma_noise * (np.random.randn(U.shape[0]) + 1j*np.random.randn(U.shape[0]))/np.sqrt(2) , (abs(U) > 0).astype(float));
|
|
|
|
|
204
|
|
|
225
|
|
|
205
|
Unz = U + nz;
|
|
226
|
Unz = U + nz;
|
|
206
|
Rnz = np.dot(Unz.T.conj(),Unz); # the noisy version of R
|
|
227
|
Rnz = np.dot(Unz.T.conj(),Unz); # the noisy version of R
|
|
207
|
plt.figure(3);
|
|
228
|
plt.figure(3);
|
|
208
|
plt.pcolor(abs(Rnz));
|
|
229
|
plt.pcolor(abs(R));
|
|
209
|
plt.colorbar();
|
|
230
|
plt.colorbar();
|
|
210
|
|
|
231
|
|
|
211
|
#-------------------------------------------------------------------------------------------------
|
|
232
|
#-------------------------------------------------------------------------------------------------
|
|
@@
-260,7
+281,7
|
|
260
|
# Build H
|
|
281
|
# Build H
|
|
261
|
for i1 in range(0, r.size):
|
|
282
|
for i1 in range(0, r.size):
|
|
262
|
for i2 in range(i1+1, r.size):
|
|
283
|
for i2 in range(i1+1, r.size):
|
|
263
|
idx = np.where(np.logical_and((i1==i1v), (i2==i2v)))[0]; # kind of awkward
|
|
284
|
idx = np.where(np.logical_and((i1==i1v), (i2==i2v)))[0]; # kind of awkward 1->27
|
|
264
|
idx1 = 2*idx;
|
|
285
|
idx1 = 2*idx;
|
|
265
|
idx2 = 2*idx+1;
|
|
286
|
idx2 = 2*idx+1;
|
|
266
|
Hr[idx1,:] = np.cos(k*(r[i1]-r[i2])*np.sin(thetar)).T.conj();
|
|
287
|
Hr[idx1,:] = np.cos(k*(r[i1]-r[i2])*np.sin(thetar)).T.conj();
|
|
@@
-296,11
+317,14
|
|
296
|
lambda1 = lambda1.x;
|
|
317
|
lambda1 = lambda1.x;
|
|
297
|
|
|
318
|
|
|
298
|
f_maxent = modelf(lambda1, Hr, F);
|
|
319
|
f_maxent = modelf(lambda1, Hr, F);
|
|
|
|
|
320
|
|
|
|
|
|
321
|
#------ what is this needed for?-------
|
|
299
|
ystar = myfun(lambda1);
|
|
322
|
ystar = myfun(lambda1);
|
|
300
|
Lambda = np.sqrt(sum(lambda1**2*sigma**2)/(4*G));
|
|
323
|
Lambda = np.sqrt(sum(lambda1**2*sigma**2)/(4*G));
|
|
301
|
ep = np.multiply(-lambda1,sigma**2)/ (2*Lambda);
|
|
324
|
ep = np.multiply(-lambda1,sigma**2)/ (2*Lambda);
|
|
302
|
es = np.dot(Hr, f_maxent) - gnz;
|
|
325
|
es = np.dot(Hr, f_maxent) - gnz;
|
|
303
|
chi2 = np.sum((es/sigma)**2);
|
|
326
|
chi2 = np.sum((es/sigma)**2);
|
|
|
|
|
327
|
#--------------------------------------
|
|
304
|
|
|
328
|
|
|
305
|
|
|
329
|
|
|
306
|
#-------------------------------------------------------------------------------------------------
|
|
330
|
#-------------------------------------------------------------------------------------------------
|
|
@@
-326,11
+350,16
|
|
326
|
f_cs = np.dot(Psi,s);
|
|
350
|
f_cs = np.dot(Psi,s);
|
|
327
|
|
|
351
|
|
|
328
|
|
|
352
|
|
|
|
|
|
353
|
print "shapes:"
|
|
|
|
|
354
|
print "Psi ", Psi.shape
|
|
|
|
|
355
|
print "s ", s.shape
|
|
|
|
|
356
|
print "f_CS ", f_cs.shape
|
|
329
|
|
|
357
|
|
|
330
|
# Plot
|
|
358
|
# Plot
|
|
331
|
plt.figure(4)
|
|
359
|
plt.figure(4)
|
|
332
|
plt.plot(thetar,f_cs,'r.-');
|
|
360
|
plt.plot(thetar,f_cs,'r.-');
|
|
333
|
plt.plot(thetat,fact,'k-');
|
|
361
|
plt.plot(thetat,fact,'k-');
|
|
|
|
|
362
|
plt.title('Reconstruction with Compressed Sensing')
|
|
334
|
|
|
363
|
|
|
335
|
|
|
364
|
|
|
336
|
#-------------------------------------------------------------------------------------------------
|
|
365
|
#-------------------------------------------------------------------------------------------------
|
|
@@
-441,7
+470,7
|
|
441
|
print 'Maxent:\t',elapsed_time_maxent, 'sec';
|
|
470
|
print 'Maxent:\t',elapsed_time_maxent, 'sec';
|
|
442
|
print 'CS:\t',elapsed_time_cs, 'sec\n';
|
|
471
|
print 'CS:\t',elapsed_time_cs, 'sec\n';
|
|
443
|
|
|
472
|
|
|
444
|
print (NN*(snri+1) + Ni), '/', (SNRdBvec.size*NN), '\n';
|
|
473
|
print (NN*(snri)+Ni+1), '/', (SNRdBvec.size*NN), '\n';
|
|
445
|
|
|
474
|
|
|
446
|
|
|
475
|
|
|
447
|
#-------------------------------------------------------------------------------------------------
|
|
476
|
#-------------------------------------------------------------------------------------------------
|
|
@@
-469,6
+498,8
|
|
469
|
# Avg ignoring NaNs
|
|
498
|
# Avg ignoring NaNs
|
|
470
|
ave = np.zeros(shape=(4))
|
|
499
|
ave = np.zeros(shape=(4))
|
|
471
|
|
|
500
|
|
|
|
|
|
501
|
print metric
|
|
|
|
|
502
|
|
|
472
|
ave[0] = nanmean(metric[0,:,:]); # Fourier
|
|
503
|
ave[0] = nanmean(metric[0,:,:]); # Fourier
|
|
473
|
ave[1] = nanmean(metric[1,:,:]); # Capon
|
|
504
|
ave[1] = nanmean(metric[1,:,:]); # Capon
|
|
474
|
ave[2] = nanmean(metric[2,:,:]); # MaxEnt
|
|
505
|
ave[2] = nanmean(metric[2,:,:]); # MaxEnt
|