Skip to content

Commit

Permalink
Change output from Struct to BackgroundList
Browse files Browse the repository at this point in the history
Code is now functional, in that it accepts images and returns
difference image background models as "psfMatchedWarpBackground_diff"
(name likely to be altered later).  Uses a fit to a blank image for
that corresponding to the reference image.
  • Loading branch information
aemerywatkins committed Jul 15, 2024
1 parent 3984671 commit 8dfbe5e
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions python/lsst/pipe/tasks/matchBackgrounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class MatchBackgroundsConnections(PipelineTaskConnections,
# This needs to be the models of each differential BG in warped coords
backgroundInfoList = cT.Output(
doc="List of differential backgrounds, w/goodness of fit params",
name="calexpBackground_diff", # This needs to change
dimensions=("visit", "detector",),
name="psfMatchedWarpBackground_diff", # This needs to change
dimensions=("tract", "patch", "skymap", "visit"),
storageClass="Background",
multiple=True,
)
Expand Down Expand Up @@ -280,16 +280,35 @@ def run(self, psfMatchedWarps):

self.log.info("Matching %d Exposures", numExp)

# Creating a null BackgroundList object by fitting a blank image
statsFlag = getattr(afwMath, self.config.gridStatistic)
self.sctrl.setNumSigmaClip(self.config.numSigmaClip)
self.sctrl.setNumIter(self.config.numIter)

# TODO: refactor below to construct blank bg model
im = refExposure.getMaskedImage()
blankIm = im.Factory(im, True) # Don't do this
blankIm.image.array *= 0

width = blankIm.getWidth()
height = blankIm.getHeight()
nx = width // self.config.binSize
if width % self.config.binSize != 0:
nx += 1
ny = height // self.config.binSize
if height % self.config.binSize != 0:
ny += 1

bctrl = afwMath.BackgroundControl(nx, ny, self.sctrl, statsFlag)
bctrl.setUndersampleStyle(self.config.undersampleStyle)

bkgd = afwMath.makeBackground(blankIm, bctrl)


backgroundInfoList = []

Check failure on line 308 in python/lsst/pipe/tasks/matchBackgrounds.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E303

too many blank lines (2)
for ind, exp in enumerate(psfMatchedWarps):
if ind in refIndSet:
backgroundInfoStruct = pipeBase.Struct(
isReference=True,
backgroundModel=None,
fitRMS=0.0,
matchedMSE=None,
diffImVar=None,
)
backgroundInfoStruct = afwMath.BackgroundList(bkgd,)
else:
self.log.info("Matching background of %s to %s", exp.dataId, refMatchedWarp.dataId)
toMatchExposure = exp.get()
Expand All @@ -307,13 +326,7 @@ def run(self, psfMatchedWarps):
backgroundInfoStruct.isReference = False
except Exception as e:

Check failure on line 327 in python/lsst/pipe/tasks/matchBackgrounds.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

F841

local variable 'e' is assigned to but never used
# self.log.warning("Failed to fit background %s: %s", toMatchRef.dataId, e)
backgroundInfoStruct = pipeBase.Struct(
isReference=False,
backgroundModel=None,
fitRMS=None,
matchedMSE=None,
diffImVar=None,
)
backgroundInfoStruct = afwMath.BackgroundList(bkgd,)

backgroundInfoList.append(backgroundInfoStruct)

Expand Down Expand Up @@ -545,11 +558,14 @@ def matchBackgrounds(self, refExposure, sciExposure):

outBkgd = approx if self.config.usePolynomial else bkgd

return pipeBase.Struct(
backgroundModel=outBkgd,
fitRMS=rms,
matchedMSE=mse,
diffImVar=meanVar)
# Type `Background` can't use a struct. Should fitRMS &c. be added to
# a log instead of output?
# return pipeBase.Struct(
# backgroundModel=afwMath.BackgroundList(outBkgd),
# fitRMS=rms,
# matchedMSE=mse,
# diffImVar=meanVar)
return afwMath.BackgroundList(outBkgd,)

def _fluxScale(self, exposure):
"""Scales image to nJy flux using photometric calibration.
Expand Down

0 comments on commit 8dfbe5e

Please sign in to comment.