Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion python/lsst/ip/diffim/subtractImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,14 @@ def _calculateMagLim(self, exposure, nsigma=5.0, fallbackPsfSize=None):
"""
if exposure.photoCalib is None:
return np.nan
# Set maglim to nan upfront in case on an unexpected RuntimeError
maglim = np.nan
try:
psf = exposure.getPsf()
psf_shape = psf.computeShape(psf.getAveragePosition())
except (lsst.pex.exceptions.InvalidParameterError, afwDetection.InvalidPsfError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any exception that is not in this list will raise an error in the finally step, since maglim won't be defined. I think this would be a good place to use except Exception as e to catch any exception, and print the error message in the log. Alternately, you could define maglim = np.nan before the try block to guarantee that it is defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks - I like the idea to just set it to nan upfront so we at least wind up with something.

except (lsst.pex.exceptions.InvalidParameterError,
afwDetection.InvalidPsfError,
lsst.pex.exceptions.RangeError):
if fallbackPsfSize is not None:
self.log.info("Unable to evaluate PSF, using fallback FWHM %f", fallbackPsfSize)
psf_area = np.pi*(fallbackPsfSize/2)**2
Expand Down