|
@@
-11,6
+11,7
|
|
11
|
11
|
import time
|
|
12
|
12
|
import matplotlib.pyplot as plt
|
|
13
|
13
|
from scipy.optimize import root
|
|
|
14
|
from scipy.optimize import newton_krylov
|
|
14
|
15
|
from scipy.stats import nanmean
|
|
15
|
16
|
|
|
16
|
17
|
from y_hysell96 import *
|
|
@@
-53,38
+54,28
|
|
53
|
54
|
## Rotation matrix from antenna coord to magnetic coord (East North) -> 45 degrees
|
|
54
|
55
|
theta_rad = np.radians(theta) # trig functions take radians as argument
|
|
55
|
56
|
val1 = float( np.cos(theta_rad) )
|
|
56
|
|
val2 = float( np.sin(theta_rad) )
|
|
57
|
|
val3 = float( -1*np.sin(theta_rad))
|
|
|
57
|
val2 = float( -1*np.sin(theta_rad))
|
|
|
58
|
val3 = float( np.sin(theta_rad) )
|
|
58
|
59
|
val4 = float( np.cos(theta_rad) )
|
|
59
|
60
|
|
|
60
|
61
|
# Rotation matrix from antenna coord to magnetic coord (East North)
|
|
61
|
|
R = np.array( [[val1, val3], [val2, val4]] )
|
|
|
62
|
R = np.array( [[val1, val2], [val3, val4]] )
|
|
62
|
63
|
|
|
63
|
64
|
# Rotate antenna positions to magnetic coord.
|
|
64
|
65
|
AR = np.dot(R.T, antpos)
|
|
65
|
66
|
|
|
66
|
|
plt.plot(AR[0], 0*AR[1], 'yo')
|
|
67
|
|
plt.title("Jicamarca Antenna Positions")
|
|
|
67
|
plt.plot(AR[0], 0*AR[1], 'yo') # antenna positions only considering magnetic East-West component (x, 0)
|
|
|
68
|
plt.title("Jicamarca Antenna Positions")
|
|
68
|
69
|
plt.xlabel("rx")
|
|
69
|
70
|
plt.ylabel("ry")
|
|
70
|
71
|
plt.grid(True)
|
|
71
|
72
|
plt.plot(rx, 0*rx, 'g-')
|
|
72
|
73
|
plt.draw()
|
|
73
|
74
|
|
|
74
|
|
print antpos
|
|
75
|
|
print "\n"
|
|
76
|
|
print AR
|
|
77
|
75
|
|
|
78
|
76
|
# Only take the East component
|
|
79
|
77
|
r = AR[0,:]
|
|
80
|
78
|
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
|
79
|
|
|
89
|
80
|
|
|
90
|
81
|
# Truth model (high and low resolution)
|
|
@@
-123,7
+114,7
|
|
123
|
114
|
fact = np.zeros(shape=(Nt,1))
|
|
124
|
115
|
factr = np.zeros(shape=(Nr,1))
|
|
125
|
116
|
|
|
126
|
|
# Constructing Gaussian model
|
|
|
117
|
# Constructing Gaussian model - brightness function (?)
|
|
127
|
118
|
for i in range(0, a.size):
|
|
128
|
119
|
temp = (-(thetat-mu[i])**2/(sig[i]**2))
|
|
129
|
120
|
tempr = (-(thetar-mu[i])**2/(sig[i]**2))
|
|
@@
-170,11
+161,11
|
|
170
|
161
|
|
|
171
|
162
|
# Plot Gaussian pulse(s)
|
|
172
|
163
|
plt.figure(2)
|
|
173
|
|
plt.plot(thetat, fact, 'r--')
|
|
|
164
|
plt.plot(thetat, fact, 'bo')
|
|
174
|
165
|
plt.plot(thetar, factr, 'ro')
|
|
175
|
|
plt.title("Truth models")
|
|
|
166
|
plt.title("Image and Reconstruction Domain")
|
|
176
|
167
|
plt.ylabel("Amplitude")
|
|
177
|
|
plt.legend(('High res','Low res'), loc='upper right')
|
|
|
168
|
plt.legend(('High res (img domain)','Low res (reconstruction domain)'), loc='upper right')
|
|
178
|
169
|
plt.draw()
|
|
179
|
170
|
|
|
180
|
171
|
|
|
@@
-199,16
+190,67
|
|
199
|
190
|
SNR = 10**(SNRdB/10.0);
|
|
200
|
191
|
|
|
201
|
192
|
for Ni in range(0, NN):
|
|
|
193
|
|
|
|
194
|
# -------------------------------------- Voltages estimation----------------------------------------
|
|
|
195
|
v = np.zeros(shape=(r.size,1), dtype=object); # voltages matrix
|
|
|
196
|
R = np.zeros(shape=(r.size, r.size), dtype='complex128'); # corr matrix
|
|
|
197
|
mu1, sigma1 = 0, 1 # mean and standard deviation
|
|
|
198
|
num = 1
|
|
|
199
|
|
|
|
200
|
for t in range (0, 10):
|
|
|
201
|
num = t+1
|
|
|
202
|
print num
|
|
|
203
|
n1 = np.random.normal(mu1, sigma1, [Nt,1]) # random variable
|
|
|
204
|
n2 = np.random.normal(mu1, sigma1, [Nt,1]) # random variable
|
|
|
205
|
|
|
|
206
|
rho = (n1 + n2*1j)*np.sqrt(fact/2) # rho.size is Nt = 16834
|
|
|
207
|
# fact is size (Nt, 1) -> column vector
|
|
|
208
|
thetat = thetat.reshape(Nt,1) # thetat is now (Nt, 1)
|
|
|
209
|
|
|
|
210
|
for i in range(0, r.size):
|
|
|
211
|
v[i] = sum((rho)*np.exp(-1j*k*((r[i])*np.cos(thetat)))); # v is sum ( (Nt, 1)) = 1 value
|
|
|
212
|
|
|
|
213
|
# Computing correlations
|
|
|
214
|
for i1 in range(0, r.size):
|
|
|
215
|
for i2 in range(0,r.size):
|
|
|
216
|
R[i1,i2] = R[i1,i2] + (v[i1][0]*v[i2][0].conjugate())/ (np.sqrt(np.abs(v[i1][0])**2 * np.abs(v[i2][0])**2));
|
|
|
217
|
|
|
|
218
|
R = R / num
|
|
|
219
|
print "R from voltages"
|
|
|
220
|
print R
|
|
|
221
|
|
|
|
222
|
plt.figure(3);
|
|
|
223
|
plt.pcolor(abs(R));
|
|
|
224
|
plt.colorbar();
|
|
|
225
|
plt.title("Antenna Correlations")
|
|
|
226
|
plt.draw()
|
|
|
227
|
plt.show()
|
|
|
228
|
|
|
|
229
|
#--------------------------------------------------------------------------------------------------
|
|
|
230
|
|
|
202
|
231
|
# Calculate cross-correlation matrix (Fourier components of image)
|
|
203
|
232
|
# This is an inefficient way to do this.
|
|
204
|
|
|
|
|
233
|
|
|
|
234
|
# MATLAB CORR::: R(i1,i2) = fact.' * exp(j*k*(r(i1)-r(i2))*sin(thetat));
|
|
|
235
|
|
|
205
|
236
|
R = np.zeros(shape=(r.size, r.size), dtype=object);
|
|
206
|
|
|
|
|
237
|
|
|
|
238
|
thetat = thetat.reshape(Nt,)
|
|
207
|
239
|
for i1 in range(0, r.size):
|
|
208
|
240
|
for i2 in range(0,r.size):
|
|
209
|
|
R[i1,i2] = np.dot(fact.T, np.exp(1j*k*np.dot((r[i1]-r[i2]),np.sin(thetat))))
|
|
210
|
|
R[i1,i2] = sum(R[i1,i2])
|
|
211
|
|
|
|
|
241
|
R[i1,i2] = sum(np.dot(fact.T, np.exp(1j*k*((r[i1]-r[i2])*np.sin(thetat)))))
|
|
|
242
|
|
|
|
243
|
print "R w/o voltages\n", R
|
|
|
244
|
# plt.figure(3);
|
|
|
245
|
# plt.pcolor(abs(R));
|
|
|
246
|
# plt.colorbar();
|
|
|
247
|
# plt.title("Antenna Correlations")
|
|
|
248
|
# plt.xlabel("Antenna")
|
|
|
249
|
# plt.ylabel("Antenna")
|
|
|
250
|
# plt.draw()
|
|
|
251
|
# plt.show()
|
|
|
252
|
|
|
|
253
|
|
|
212
|
254
|
# Add uncertainty
|
|
213
|
255
|
# This is an ad-hoc way of adding "noise". It models some combination of
|
|
214
|
256
|
# receiver noise and finite integration times. We could use a more
|
|
@@
-225,9
+267,9
|
|
225
|
267
|
|
|
226
|
268
|
Unz = U + nz;
|
|
227
|
269
|
Rnz = np.dot(Unz.T.conj(),Unz); # the noisy version of R
|
|
228
|
|
plt.figure(3);
|
|
229
|
|
plt.pcolor(abs(R));
|
|
230
|
|
plt.colorbar();
|
|
|
270
|
# plt.figure(3);
|
|
|
271
|
# plt.pcolor(abs(R));
|
|
|
272
|
# plt.colorbar();
|
|
231
|
273
|
|
|
232
|
274
|
#-------------------------------------------------------------------------------------------------
|
|
233
|
275
|
# Fourier Inversion
|
|
@@
-236,9
+278,8
|
|
236
|
278
|
|
|
237
|
279
|
for i in range(0, thetar.size):
|
|
238
|
280
|
th = thetar[i];
|
|
239
|
|
w = np.exp(1j*k*np.dot(r,np.sin(th)));
|
|
240
|
|
temp = np.dot(w.T.conj(),U)
|
|
241
|
|
f_fourier[i] = np.dot(temp, w);
|
|
|
281
|
w = np.exp(1j*k*np.dot(r,np.sin(th)));
|
|
|
282
|
f_fourier[i] = np.dot(np.dot(w.T.conj(),U) , w);
|
|
242
|
283
|
|
|
243
|
284
|
f_fourier = f_fourier.real; # get rid of numerical imaginary noise
|
|
244
|
285
|
|
|
@@
-281,7
+322,7
|
|
281
|
322
|
# Build H
|
|
282
|
323
|
for i1 in range(0, r.size):
|
|
283
|
324
|
for i2 in range(i1+1, r.size):
|
|
284
|
|
idx = np.where(np.logical_and((i1==i1v), (i2==i2v)))[0]; # kind of awkward 1->27
|
|
|
325
|
idx = np.where(np.logical_and((i1==i1v), (i2==i2v)))[0]; # kind of awkward (1->27)
|
|
285
|
326
|
idx1 = 2*idx;
|
|
286
|
327
|
idx2 = 2*idx+1;
|
|
287
|
328
|
Hr[idx1,:] = np.cos(k*(r[i1]-r[i2])*np.sin(thetar)).T.conj();
|
|
@@
-308,7
+349,8
|
|
308
|
349
|
|
|
309
|
350
|
tic_maxEnt = time.time(); # start time maxEnt
|
|
310
|
351
|
|
|
311
|
|
lambda1 = root(myfun,lambda0, method='krylov', tol=1e-14);
|
|
|
352
|
lambda1 = root(myfun,lambda0, method='krylov', tol=1e-14); # krylov
|
|
|
353
|
# lambda1 = newton_krylov(myfun,lambda0, method='lgmres', x_tol=1e-14)
|
|
312
|
354
|
|
|
313
|
355
|
toc_maxEnt = time.time()
|
|
314
|
356
|
elapsed_time_maxent = toc_maxEnt - tic_maxEnt;
|
|
@@
-319,11
+361,11
|
|
319
|
361
|
f_maxent = modelf(lambda1, Hr, F);
|
|
320
|
362
|
|
|
321
|
363
|
#------ what is this needed for?-------
|
|
322
|
|
ystar = myfun(lambda1);
|
|
323
|
|
Lambda = np.sqrt(sum(lambda1**2*sigma**2)/(4*G));
|
|
324
|
|
ep = np.multiply(-lambda1,sigma**2)/ (2*Lambda);
|
|
325
|
|
es = np.dot(Hr, f_maxent) - gnz;
|
|
326
|
|
chi2 = np.sum((es/sigma)**2);
|
|
|
364
|
# ystar = myfun(lambda1);
|
|
|
365
|
# Lambda = np.sqrt(sum(lambda1**2*sigma**2)/(4*G));
|
|
|
366
|
# ep = np.multiply(-lambda1,sigma**2)/ (2*Lambda);
|
|
|
367
|
# es = np.dot(Hr, f_maxent) - gnz;
|
|
|
368
|
# chi2 = np.sum((es/sigma)**2);
|
|
327
|
369
|
#--------------------------------------
|
|
328
|
370
|
|
|
329
|
371
|
|
|
@@
-354,12
+396,13
|
|
354
|
396
|
print "Psi ", Psi.shape
|
|
355
|
397
|
print "s ", s.shape
|
|
356
|
398
|
print "f_CS ", f_cs.shape
|
|
|
399
|
|
|
357
|
400
|
|
|
358
|
|
# Plot
|
|
359
|
|
plt.figure(4)
|
|
360
|
|
plt.plot(thetar,f_cs,'r.-');
|
|
361
|
|
plt.plot(thetat,fact,'k-');
|
|
362
|
|
plt.title('Reconstruction with Compressed Sensing')
|
|
|
401
|
# # Plot
|
|
|
402
|
# plt.figure(4)
|
|
|
403
|
# plt.plot(thetar,f_cs,'r.-');
|
|
|
404
|
# plt.plot(thetat,fact,'k-');
|
|
|
405
|
# plt.title('Reconstruction with Compressed Sensing')
|
|
363
|
406
|
|
|
364
|
407
|
|
|
365
|
408
|
#-------------------------------------------------------------------------------------------------
|
|
@@
-396,7
+439,6
|
|
396
|
439
|
# Calculate centered correlation
|
|
397
|
440
|
f0 = factr - np.mean(factr);
|
|
398
|
441
|
f1 = f_fourier - np.mean(f_fourier);
|
|
399
|
|
|
|
400
|
442
|
corrc_fourier = np.dot(f0.T.conj(),f1) / (np.linalg.norm(f0)*np.linalg.norm(f1));
|
|
401
|
443
|
f1 = f_capon - np.mean(f_capon);
|
|
402
|
444
|
corrc_capon = np.dot(f0.T.conj(),f1) / (np.linalg.norm(f0)*np.linalg.norm(f1));
|
|
@@
-499,11
+541,14
|
|
499
|
541
|
ave = np.zeros(shape=(4))
|
|
500
|
542
|
|
|
501
|
543
|
print metric
|
|
502
|
|
|
|
503
|
|
ave[0] = nanmean(metric[0,:,:]); # Fourier
|
|
504
|
|
ave[1] = nanmean(metric[1,:,:]); # Capon
|
|
505
|
|
ave[2] = nanmean(metric[2,:,:]); # MaxEnt
|
|
506
|
|
ave[3] = nanmean(metric[3,:,:]); # Compressed Sensing
|
|
|
544
|
print metric.shape
|
|
|
545
|
|
|
|
546
|
ave[0] = nanmean(metric[0,0,:]); # Fourier
|
|
|
547
|
ave[1] = nanmean(metric[1,0,:]); # Capon
|
|
|
548
|
ave[2] = nanmean(metric[2,0,:]); # MaxEnt
|
|
|
549
|
ave[3] = nanmean(metric[3,0,:]); # Compressed Sensing
|
|
|
550
|
|
|
|
551
|
print ave
|
|
507
|
552
|
|
|
508
|
553
|
# Plot based on chosen metric
|
|
509
|
554
|
plt.figure(6);
|