Skip to content

Commit

Permalink
Disallow fitBackground returning None
Browse files Browse the repository at this point in the history
Make SubtractBackground.fitBackground raise RuntimeError
instead of returning None, unlike the getBackground
function it replaces.
  • Loading branch information
r-owen committed May 4, 2016
1 parent 8b5b2fe commit d059332
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/subtractBackgroundExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import lsst.afw.math as afwMath
from lsst.meas.algorithms import SubtractBackgroundTask

def loadData(psfSigma=1.5):
def loadData():
"""Load the data we need to run the example"""
mypath = lsst.utils.getPackageDir('afwdata')
imFile = os.path.join(mypath, "CFHT", "D4", "cal-53535-i-797722_small_1.fits")
Expand Down
15 changes: 8 additions & 7 deletions python/lsst/meas/algorithms/subtractBackground.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ def run(self, exposure, background=None, stats=True, statsKeys=None):
@return an lsst.pipe.base.Struct containing:
- background full background model (initial model with changes), an lsst.afw.math.BackgroundList
@throw RuntimeError if fitBackground returns a background of None
"""
displayBackground = lsstDebug.Info(__name__).displayBackground

Expand All @@ -226,8 +224,6 @@ def run(self, exposure, background=None, stats=True, statsKeys=None):
maskedImage = exposure.getMaskedImage()

fitBg = self.fitBackground(maskedImage)
if not fitBg:
raise RuntimeError("Unable to estimate background for exposure")

maskedImage -= fitBg.getImageF()
background.append(fitBg)
Expand Down Expand Up @@ -266,8 +262,10 @@ def fitBackground(self, maskedImage, nx=0, ny=0, algorithm=None):
@param[in] ny number of y bands; if 0 compute from height and config.binSize
@param[in] algorithm name of interpolation algorithm; if None use self.config.algorithm
@return fit background as an lsst.afw.math.Background, or None if the estimation fails
(unless the code raises an exception)
@return fit background as an lsst.afw.math.Background
@throw RuntimeError if lsst.afw.math.makeBackground returns None,
which is apparently one way it indicates failure
"""
if not nx:
nx = maskedImage.getWidth()//self.config.binSize + 1
Expand Down Expand Up @@ -344,4 +342,7 @@ def fitBackground(self, maskedImage, nx=0, ny=0, algorithm=None):
self.config.weighting)
bctrl.setApproximateControl(actrl)

return afwMath.makeBackground(maskedImage, bctrl)
bg = afwMath.makeBackground(maskedImage, bctrl)
if bg is None:
raise RuntimeError("lsst.afw.math.makeBackground failed to fit a background model")
return bg

0 comments on commit d059332

Please sign in to comment.