@@ -183,6 +183,7 @@ def compute_calibrated_model(vis, model_vis, maxiter=30):
183
183
maxiter: max iterations (default 30)
184
184
Returns:
185
185
calibrated: model visibilities, shape [n_st, n_st]
186
+ gains: the antenna grains, shape [n_st]
186
187
residual: amplitude difference between model and actual visibilities, float
187
188
"""
188
189
@@ -199,11 +200,11 @@ def gains_difference(gain_phase, vis, model_vis):
199
200
200
201
result = scipy .optimize .minimize (gains_difference , gain_phase , args = (vis , model_vis ), options = {'maxiter' : maxiter })
201
202
gain_phase = result .x
202
- gains_mat = np .diag ( np . exp (1.j * gain_phase ) )
203
-
203
+ gains = np .exp (1.j * gain_phase )
204
+ gains_mat = np . diag ( gains )
204
205
calibrated = np .conj (gains_mat ) @ model_vis @ gains_mat
205
206
206
- return calibrated , gains_difference (gain_phase , vis , model_vis )
207
+ return calibrated , gains , gains_difference (gain_phase , vis , model_vis )
207
208
208
209
209
210
def compute_pointing_matrix (sources_positions , baselines , frequency ):
@@ -274,27 +275,36 @@ def estimate_model_visibilities(sources_positions, visibilities, baselines, freq
274
275
return model
275
276
276
277
277
- def self_cal (visibilities , expected_sources , baselines , frequency , iterations = 10 ):
278
+ def self_cal (visibilities , expected_sources , baselines , frequency , max_iterations = 10 , tollerance = 1.e-4 ):
278
279
"""
279
280
Compute the gain phase comparing the model and the actual visibilities returning
280
281
the model with the gain phase correction applied.
281
282
282
- TODO introduce a valid stop condition and make the iteration parameters a max_iter parameter
283
283
284
284
Args:
285
285
visibilities: visibilities, shape [n_st, n_st]
286
286
expected_sources: lmn coords of the sources, shape [n_dir, 3]
287
287
baselines: baselines matrix in m, shape [n_st, n_st, 3]
288
288
frequency: frequency
289
- iterations: number of iterations to perform
289
+ max_iterations: maximum number of iterations to perform
290
290
Returns:
291
291
model: the model visibilities with the applied gains, shape [n_st, n_st]
292
+ gains: the antenna gains, shape [n_st]
293
+
292
294
"""
293
295
model = estimate_model_visibilities (expected_sources , visibilities , baselines , frequency )
294
- for i in range (iterations ):
295
- model , residual = compute_calibrated_model (visibilities , model , maxiter = 50 )
296
- logging .debug ('residual after iteration %d: %s' , i , residual )
297
- return model
296
+ model , gains , residual = compute_calibrated_model (visibilities , model , maxiter = 50 )
297
+ for i in range (1 , max_iterations ):
298
+ model , gains , next_residual = compute_calibrated_model (visibilities , model , maxiter = 50 )
299
+ print (i , residual , next_residual )
300
+ if next_residual == 0 :
301
+ break
302
+ elif abs (1 - (residual / next_residual )) >= tollerance :
303
+ residual = next_residual
304
+ else :
305
+ break
306
+
307
+ return model , gains
298
308
299
309
300
310
def simulate_sky_source (lmn_coord : np .array , baselines : np .array , freq : float ):
0 commit comments