@@ -66,7 +66,7 @@ class VisibilityMapping:
66
66
Whether to print notification messages
67
67
"""
68
68
def __init__ (self , DHT , geometry ,
69
- vis_model = 'opt_thick' , scale_height = None , block_data = True ,
69
+ vis_model = 'opt_thick' , geometry_on = True , scale_height = None , block_data = True ,
70
70
block_size = 10 ** 5 , check_qbounds = True , verbose = True ,
71
71
DFT = None ):
72
72
@@ -78,6 +78,7 @@ def __init__(self, DHT, geometry,
78
78
self ._vis_model = vis_model
79
79
self .check_qbounds = check_qbounds
80
80
self ._verbose = verbose
81
+ self .geometry_on = geometry_on
81
82
82
83
self ._chunking = block_data
83
84
self ._chunk_size = block_size
@@ -165,7 +166,8 @@ def map_visibilities(self, u, v, V, weights, frequencies=None, geometry=None):
165
166
logging .info (' Building visibility matrices M and j' )
166
167
167
168
# Deproject the visibilities
168
- #u, v, k, V = self._geometry.apply_correction(u, v, V, use3D=True)
169
+ if self .geometry_on :
170
+ u , v , k , V = self ._geometry .apply_correction (u , v , V , use3D = True )
169
171
q = np .hypot (u , v )
170
172
171
173
# Check consistency of the uv points with the model
@@ -179,7 +181,7 @@ def map_visibilities(self, u, v, V, weights, frequencies=None, geometry=None):
179
181
if frequencies is None :
180
182
multi_freq = False
181
183
frequencies = np .ones_like (V )
182
-
184
+ start_time = time . time ()
183
185
channels = np .unique (frequencies )
184
186
Ms = np .zeros ([len (channels ), self .size , self .size ], dtype = 'c8' )
185
187
js = np .zeros ([len (channels ), self .size ], dtype = 'c8' )
@@ -209,15 +211,34 @@ def map_visibilities(self, u, v, V, weights, frequencies=None, geometry=None):
209
211
Vs = Vi [start :end ]
210
212
211
213
X = self ._get_mapping_coefficients (qs , ks , us , vs )
212
- X_CT = self ._get_mapping_coefficients (qs , ks , us , vs , inverse = True )
213
- wXT = np .matmul (X_CT , np .diag (ws )) # this line is the same as below.
214
- #wXT = np.matmul(np.transpose(np.conjugate(X)), np.diag(ws), dtype = "complex64")
215
- Ms [i ] += np .matmul (wXT , X , dtype = "complex128" )
216
- js [i ] += np .matmul (wXT , Vs , dtype = "complex128" )
214
+ wXT = np .matmul (np .transpose (np .conjugate (X )), np .diag (ws ), dtype = "complex128" )
215
+ Ms [i ] += np .matmul (wXT , X , dtype = "complex128" ).real
216
+ js [i ] += np .matmul (wXT , Vs , dtype = "complex128" ).real
217
217
218
218
start = end
219
219
end = min (Ndata , end + Nstep )
220
-
220
+
221
+ import matplotlib .pyplot as plt
222
+
223
+
224
+ N = int (np .sqrt (self ._DFT .size ))
225
+ r"""FRANK 2D: TESTING M
226
+ sparcity = ((np.sum(np.abs(Ms[0]) < 0.5e-17))/N**4)*100
227
+ print("M is sparse? ", sparcity)
228
+ print(Ms[0])
229
+
230
+ plt.imshow(Ms[0].real, cmap="magma", vmax = np.max(Ms[0].real), vmin = np.mean(Ms[0].real))
231
+ plt.colorbar()
232
+ plt.show()
233
+
234
+ M = np.diag(np.diag(Ms[0].real))
235
+ num_zeros = ((np.sum(np.abs(M) == 0.0))/N**4)*100
236
+ print("M is sparse? ", num_zeros)
237
+
238
+ IFT2 = np.linalg.solve(M, js[0]).real
239
+ plt.imshow(IFT2.reshape(N,N).T, cmap="magma")
240
+ plt.colorbar()
241
+
221
242
print("M type", Ms[0].dtype)
222
243
print("j type", js[0].dtype)
223
244
print("M imag-> ", " max: ", np.max(Ms[0].imag), ", min: ", np.min(Ms[0].imag) , ", mean: ", np.mean(Ms[0].imag) ,", median: ", np.median(Ms[0].imag), ", std: ", np.std(Ms[0].imag))
@@ -228,19 +249,22 @@ def map_visibilities(self, u, v, V, weights, frequencies=None, geometry=None):
228
249
# from scipy.linalg import issymmetric
229
250
# print(issymmetric(Ms[0]), "that M is a Symmetric Matrix")
230
251
231
-
232
-
233
252
import matplotlib.pyplot as plt
234
253
plt.matshow(Ms[0].real, cmap="magma", vmax = np.max(Ms[0].real), vmin = np.mean(Ms[0].real))
235
254
plt.colorbar()
236
255
plt.title("M matrix, real part")
237
256
plt.show()
238
257
#import sys
239
258
#sys.exit()
240
-
259
+ """
241
260
242
261
#Ms[0] = np.loadtxt(r'.\..\Notebooks\M_N75.txt', dtype = 'c8')
243
262
#js[0] = np.loadtxt(r'.\..\Notebooks\j_N75.txt', dtype = 'c8')
263
+ print ("--- %s minutes to calculate M and j ---" % (time .time ()/ 60 - start_time / 60 ))
264
+ path = r'/Users/mariajmelladot/Desktop/Frank2D/1_Frank2D_DEV/data/TestingComplexity/'
265
+ np .save (path + 'M_N' + str (N ) , Ms [0 ].real )
266
+ np .save (path + 'j_N' + str (N ) , js [0 ].real )
267
+
244
268
245
269
# Compute likelihood normalization H_0, i.e., the
246
270
# log-likelihood of a source with I=0.
@@ -288,10 +312,10 @@ def check_hash(self, hash, multi_freq=False, geometry=None):
288
312
self ._DFT .Rmax == hash [1 ].Rmax and
289
313
self ._DFT .size == hash [1 ].size and
290
314
self ._DFT .order == hash [1 ].order and
291
- geometry .inc == hash [2 ].inc and
292
- geometry .PA == hash [2 ].PA and
293
- geometry .dRA == hash [2 ].dRA and
294
- geometry .dDec == hash [2 ].dDec and
315
+ # geometry.inc == hash[2].inc and
316
+ # geometry.PA == hash[2].PA and
317
+ # geometry.dRA == hash[2].dRA and
318
+ # geometry.dDec == hash[2].dDec and
295
319
self ._vis_model == hash [3 ]
296
320
)
297
321
@@ -496,8 +520,11 @@ def _get_mapping_coefficients(self, qs, ks, u, v, geometry=None, inverse=False):
496
520
if self ._vis_model == 'opt_thick' :
497
521
# Optically thick & geometrically thin
498
522
if geometry is None :
499
- geometry = self ._geometry
500
- scale = np .cos (geometry .inc * deg_to_rad )
523
+ if not self .geometry_on :
524
+ scale = 1
525
+ else :
526
+ geometry = self ._geometry
527
+ scale = np .cos (geometry .inc * deg_to_rad )
501
528
elif self ._vis_model == 'opt_thin' :
502
529
# Optically thin & geometrically thin
503
530
scale = 1
@@ -746,7 +773,6 @@ def __init__(self, DHT, M, j, p=None, scale=None, guess=None,
746
773
" New GP "
747
774
self .u , self .v = self ._DFT .uv_points
748
775
self .Ykm = self ._DFT .coefficients (direction = "backward" )
749
- self .Ykm_f = self ._DFT .coefficients (direction = "forward" )
750
776
751
777
m , c , l = - 5 , 60 , 1e4
752
778
#m, c, l = 0.23651345032212925, 60.28747193555951, 1.000389e+05
@@ -758,10 +784,29 @@ def __init__(self, DHT, M, j, p=None, scale=None, guess=None,
758
784
S_real_inv = np .linalg .inv (S_real )
759
785
print ("--- %s minutes to calculate S_real_inv---" % (time .time ()/ 60 - start_time / 60 ))
760
786
self ._Sinv = S_real_inv
761
- print (self ._Sinv .dtype , " Sinv dtype" )
762
787
start_time = time .time ()
763
788
self ._fit ()
764
789
print ("--- %s minutes to fit---" % (time .time ()/ 60 - start_time / 60 ))
790
+
791
+ def calculate_S_real (self , u , v , l , m , c ):
792
+ start_time = time .time ()
793
+ S_fspace = self .true_squared_exponential_kernel (u , v , l , m , c )
794
+ print ("--- %s minutes to calculate S---" % (time .time ()/ 60 - start_time / 60 ))
795
+ start_time = time .time ()
796
+ S_real = np .matmul (self .Ykm , np .matmul (S_fspace , self .Ykm .conj ()), dtype = "complex128" ).real
797
+ print ("--- %s minutes to calculate S_real---" % (time .time ()/ 60 - start_time / 60 ))
798
+
799
+ """
800
+ #FRANK 2D: TESTING S_real
801
+ print(" S_real")
802
+ import matplotlib.pyplot as plt
803
+ plt.matshow(S_real, cmap="magma")
804
+ plt.colorbar()
805
+ plt.title("S matrix, real part ")
806
+ plt.show()
807
+ """
808
+
809
+ return S_real
765
810
766
811
def true_squared_exponential_kernel (self , u , v , l , m , c ):
767
812
u1 , u2 = np .meshgrid (u , u )
@@ -784,23 +829,6 @@ def power_spectrum(q, m, c):
784
829
SE_Kernel = np .sqrt (p1 * p2 ) * np .exp (- 0.5 * ((u1 - u2 )** 2 + (v1 - v2 )** 2 )/ l ** 2 )
785
830
return SE_Kernel
786
831
787
- def calculate_S_real (self , u , v , l , m , c ):
788
- start_time = time .time ()
789
- S_fspace = self .true_squared_exponential_kernel (u , v , l , m , c )
790
- print ("--- %s minutes to calculate S---" % (time .time ()/ 60 - start_time / 60 ))
791
- start_time = time .time ()
792
- S_real = np .matmul (self .Ykm , np .matmul (S_fspace , self .Ykm_f ), dtype = "complex64" )
793
- print ("--- %s minutes to calculate S_real---" % (time .time ()/ 60 - start_time / 60 ))
794
-
795
- print (S_real .dtype , " S_real dtype" )
796
- import matplotlib .pyplot as plt
797
- plt .matshow (S_fspace , cmap = "magma" , vmin = 0 , vmax = 1e-3 )
798
- plt .colorbar ()
799
- plt .title ("S real matrix, real part " )
800
- plt .show ()
801
-
802
- return S_real
803
-
804
832
def calculate_mu_cholesky (self , Dinv ):
805
833
print ("calculate mu with cholesky" )
806
834
try :
@@ -889,7 +917,7 @@ def _fit(self):
889
917
890
918
Dinv = self ._M + Sinv
891
919
892
- """
920
+ r """ FRANK 2D: TESTING Dinv
893
921
#import scipy.linalg as sc
894
922
def is_pos_def(x):
895
923
return np.all(np.linalg.eigvals(x) > 0)
0 commit comments