@@ -209,22 +209,32 @@ def map_visibilities(self, u, v, V, weights, frequencies=None, geometry=None):
209
209
Vs = Vi [start :end ]
210
210
211
211
X = self ._get_mapping_coefficients (qs , ks , us , vs )
212
- #print("X shape", X.shape)
213
- X_CT = X .conj ().T
214
- #print("X_CT shape", X_CT.shape)
215
- #print("w shape", np.diag(ws**(-1)).shape)
216
- wXT = np .matmul (X_CT , np .diag (ws ** (- 1 )))
217
- #print("wXT shape", wXT.shape)
218
- #print("V shape", Vs.shape)
219
- Ms [i ] += np .matmul (wXT , X )
220
- js [i ] += np .matmul (wXT , 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" )
221
217
222
218
start = end
223
219
end = min (Ndata , end + Nstep )
224
-
225
- from scipy .linalg import issymmetric
226
- print (Ms [0 ].dtype )
227
- print (issymmetric (Ms [0 ]), "that M is a Symmetric Matrix" )
220
+
221
+ print ("M type" , Ms [0 ].dtype )
222
+ print ("j type" , js [0 ].dtype )
223
+ 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 ))
224
+ print ("M real-> " , " max: " , np .max (Ms [0 ].real ), ", min: " , np .min (Ms [0 ].real ) , ", mean: " , np .mean (Ms [0 ].real ) ,", median: " , np .median (Ms [0 ].real ), ", std: " , np .std (Ms [0 ].real ))
225
+ tol = 1e-10
226
+ print ("with tol: " , tol , ", M is symmetric?" , np .allclose (Ms [0 ].real , Ms [0 ].T .real , atol = tol ))
227
+ # Ms[0] = np.abs(Ms[0])
228
+ # from scipy.linalg import issymmetric
229
+ # print(issymmetric(Ms[0]), "that M is a Symmetric Matrix")
230
+
231
+
232
+
233
+ import matplotlib .pyplot as plt
234
+ plt .matshow (Ms [0 ].real , cmap = "magma" , vmax = np .max (Ms [0 ].real ), vmin = np .mean (Ms [0 ].real ))
235
+ plt .colorbar ()
236
+ plt .title ("M matrix, real part" )
237
+ plt .show ()
228
238
#import sys
229
239
#sys.exit()
230
240
@@ -483,7 +493,6 @@ def interpolate(self, f, r, space='Real'):
483
493
484
494
def _get_mapping_coefficients (self , qs , ks , u , v , geometry = None , inverse = False ):
485
495
"""Get :math:`H(q)`, such that :math:`V(q) = H(q) I_\n u`"""
486
- """
487
496
if self ._vis_model == 'opt_thick' :
488
497
# Optically thick & geometrically thin
489
498
if geometry is None :
@@ -497,16 +506,14 @@ def _get_mapping_coefficients(self, qs, ks, u, v, geometry=None, inverse=False):
497
506
scale = np .exp (- np .outer (ks * ks , self ._H2 ))
498
507
else :
499
508
raise ValueError ("model not supported. Should never occur." )
500
- """
501
509
if inverse :
502
- # scale = np.atleast_1d(1/scale).reshape(1,-1)
503
- # qs = qs / rad_to_arcsec
510
+ scale = np .atleast_1d (1 / scale ).reshape (1 ,- 1 )
511
+ qs = qs / rad_to_arcsec
504
512
direction = 'backward'
505
513
else :
506
514
direction = 'forward'
507
515
508
- #H = self._DHT.coefficients(qs, direction=direction) * scale
509
- H = self ._DFT .coefficients (u , v , direction = direction ) #* scale
516
+ H = self ._DFT .coefficients (u , v , direction = direction )* scale
510
517
511
518
return H
512
519
@@ -751,6 +758,7 @@ def __init__(self, DHT, M, j, p=None, scale=None, guess=None,
751
758
S_real_inv = np .linalg .inv (S_real )
752
759
print ("--- %s minutes to calculate S_real_inv---" % (time .time ()/ 60 - start_time / 60 ))
753
760
self ._Sinv = S_real_inv
761
+ print (self ._Sinv .dtype , " Sinv dtype" )
754
762
start_time = time .time ()
755
763
self ._fit ()
756
764
print ("--- %s minutes to fit---" % (time .time ()/ 60 - start_time / 60 ))
@@ -781,8 +789,16 @@ def calculate_S_real(self, u, v, l, m, c):
781
789
S_fspace = self .true_squared_exponential_kernel (u , v , l , m , c )
782
790
print ("--- %s minutes to calculate S---" % (time .time ()/ 60 - start_time / 60 ))
783
791
start_time = time .time ()
784
- S_real = np .matmul (self .Ykm , np .matmul (S_fspace , self .Ykm_f ))
792
+ S_real = np .matmul (self .Ykm , np .matmul (S_fspace , self .Ykm_f ), dtype = "complex64" )
785
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
+
786
802
return S_real
787
803
788
804
def calculate_mu_cholesky (self , Dinv ):
@@ -798,8 +814,8 @@ def calculate_mu_cholesky(self, Dinv):
798
814
return mu
799
815
800
816
def calculate_mu_gc (self , Dinv ):
801
- from scipy .sparse .linalg import bicg , bicgstab , gmres
802
- method = "BiConjugate Gradient Stabilized Method"
817
+ from scipy .sparse .linalg import cg , bicg , bicgstab , gmres
818
+ method = "BiConjugate Gradient Method"
803
819
#from scipy.sparse import csr_matrix, issparse
804
820
#is_sparse = issparse(Dinv)
805
821
#print("Is Dinv sparse?: ", is_sparse)
0 commit comments