Skip to content

Commit 64486eb

Browse files
authored
Merge pull request #59 from lsst-ts/tickets/DM-53756
Add logging info from inside scipy.optimize.least_squares.
2 parents 6558ffe + 22f037e commit 64486eb

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

doc/news/DM-53756.doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Add additional logging statements in routines related to Zernike estimation.
1+
Add additional logging statements in routines related to Zernike estimation including output from inside scipy.optimize.least_squares.

python/lsst/ts/wep/estimation/danish.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import numpy as np
2929
from galsim import GalSimFFTSizeError
3030
from scipy.ndimage import binary_erosion
31-
from scipy.optimize import least_squares
31+
from scipy.optimize import OptimizeResult, least_squares
3232

3333
from lsst.ts.wep import Image, ImageMapper, Instrument
3434
from 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

Comments
 (0)