2828import numpy as np
2929from galsim import GalSimFFTSizeError
3030from scipy .ndimage import binary_erosion
31- from scipy .optimize import least_squares
31+ from scipy .optimize import OptimizeResult , least_squares
3232
3333from lsst .ts .wep import Image , ImageMapper , Instrument
3434from lsst .ts .wep .estimation .wfAlgorithm import WfAlgorithm
@@ -277,13 +277,23 @@ def _estimateSingleZk(
277277 # Create the initial guess for the model parameters
278278 x0 = [0.0 , 0.0 , 1.0 ] + [0.0 ] * len (nollIndices )
279279
280+ self .log .info ("Starting least squares optimization." )
281+ opt_result_keys = ["nit" , "nfev" , "cost" ]
282+
283+ def callback (* , intermediate_result : OptimizeResult ) -> None :
284+ self .log .info (
285+ "Iter: %i, Total nfev: %i, Cost: %f" ,
286+ * (intermediate_result [key ] for key in opt_result_keys ),
287+ )
288+
280289 # Use scipy to optimize the parameters
281290 try :
282291 result = least_squares (
283292 model .chi ,
284293 jac = model .jac ,
285294 x0 = x0 ,
286295 args = (img , backgroundStd ** 2 ),
296+ callback = callback ,
287297 ** self .lstsqKwargs ,
288298 )
289299 result = dict (result )
@@ -447,6 +457,14 @@ def _estimatePairZk(
447457 bounds = [list (b ) for b in zip (* bounds )]
448458
449459 self .log .info ("Starting least squares optimization." )
460+ opt_result_keys = ["nit" , "nfev" , "cost" ]
461+
462+ def callback (* , intermediate_result : OptimizeResult ) -> None :
463+ self .log .info (
464+ "Iter: %i, Total nfev: %i, Cost: %f" ,
465+ * (intermediate_result [key ] for key in opt_result_keys ),
466+ )
467+
450468 # Use scipy to optimize the parameters
451469 try :
452470 result = least_squares (
@@ -455,6 +473,7 @@ def _estimatePairZk(
455473 x0 = x0 ,
456474 args = (imgs , skyLevels ),
457475 bounds = bounds ,
476+ callback = callback ,
458477 ** self .lstsqKwargs ,
459478 )
460479 result = dict (result )
0 commit comments