@@ -209,22 +209,32 @@ def map_visibilities(self, u, v, V, weights, frequencies=None, geometry=None):
209209 Vs = Vi [start :end ]
210210
211211 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" )
221217
222218 start = end
223219 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 ()
228238 #import sys
229239 #sys.exit()
230240
@@ -483,7 +493,6 @@ def interpolate(self, f, r, space='Real'):
483493
484494 def _get_mapping_coefficients (self , qs , ks , u , v , geometry = None , inverse = False ):
485495 """Get :math:`H(q)`, such that :math:`V(q) = H(q) I_\n u`"""
486- """
487496 if self ._vis_model == 'opt_thick' :
488497 # Optically thick & geometrically thin
489498 if geometry is None :
@@ -497,16 +506,14 @@ def _get_mapping_coefficients(self, qs, ks, u, v, geometry=None, inverse=False):
497506 scale = np .exp (- np .outer (ks * ks , self ._H2 ))
498507 else :
499508 raise ValueError ("model not supported. Should never occur." )
500- """
501509 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
504512 direction = 'backward'
505513 else :
506514 direction = 'forward'
507515
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
510517
511518 return H
512519
@@ -751,6 +758,7 @@ def __init__(self, DHT, M, j, p=None, scale=None, guess=None,
751758 S_real_inv = np .linalg .inv (S_real )
752759 print ("--- %s minutes to calculate S_real_inv---" % (time .time ()/ 60 - start_time / 60 ))
753760 self ._Sinv = S_real_inv
761+ print (self ._Sinv .dtype , " Sinv dtype" )
754762 start_time = time .time ()
755763 self ._fit ()
756764 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):
781789 S_fspace = self .true_squared_exponential_kernel (u , v , l , m , c )
782790 print ("--- %s minutes to calculate S---" % (time .time ()/ 60 - start_time / 60 ))
783791 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" )
785793 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+
786802 return S_real
787803
788804 def calculate_mu_cholesky (self , Dinv ):
@@ -798,8 +814,8 @@ def calculate_mu_cholesky(self, Dinv):
798814 return mu
799815
800816 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"
803819 #from scipy.sparse import csr_matrix, issparse
804820 #is_sparse = issparse(Dinv)
805821 #print("Is Dinv sparse?: ", is_sparse)
0 commit comments