Skip to content

Commit

Permalink
Fix handling of bad dipole fits
Browse files Browse the repository at this point in the history
This was a bug in what measureDipoles() expected for a bad fit vs. what
fitDipole() returned, plus not calling fail() for that condition.
There's not an explicit unittest of this kind of failure, but I've
confirmed it fixes the problem in ap_verify cosmos.
parejkoj committed Mar 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent eb961e4 commit 736037b
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions python/lsst/ip/diffim/dipoleFitTask.py
Original file line number Diff line number Diff line change
@@ -860,13 +860,7 @@ def fitDipole(self, source, tol=1e-7, rel_weight=0.1,

fitParams = fitResult.best_values
if fitParams['flux'] <= 1.: # usually around 0.1 -- the minimum flux allowed -- i.e. bad fit.
out = Struct(posCentroidX=np.nan, posCentroidY=np.nan,
negCentroidX=np.nan, negCentroidY=np.nan,
posFlux=np.nan, negFlux=np.nan, posFluxErr=np.nan, negFluxErr=np.nan,
centroidX=np.nan, centroidY=np.nan, orientation=np.nan,
signalToNoise=np.nan, chi2=np.nan, redChi2=np.nan,
nData=np.nan)
return out, fitResult
return None, fitResult

centroid = ((fitParams['xcenPos'] + fitParams['xcenNeg']) / 2.,
(fitParams['ycenPos'] + fitParams['ycenNeg']) / 2.)
@@ -1127,13 +1121,11 @@ def measureDipoles(self, measRecord, exposure, posExp=None, negExp=None):
errorMessage = f"Exception in dipole fit. {e.__class__.__name__}: {e}"
self.fail(measRecord, measBase.MeasurementError(errorMessage, self.FAILURE_FIT))

if result is None:
return

self.log.debug("Dipole fit result: %d %s", measRecord.getId(), str(result))

if result.posFlux <= 1.: # usually around 0.1 -- the minimum flux allowed -- i.e. bad fit.
self.fail(measRecord, measBase.MeasurementError('dipole fit failure', self.FAILURE_FIT))
if result is None:
self.fail(measRecord, measBase.MeasurementError("bad dipole fit", self.FAILURE_FIT))
return

# add chi2, coord/flux uncertainties (TBD), dipole classification
# Add the relevant values to the measRecord

0 comments on commit 736037b

Please sign in to comment.