Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ingestCalibs: add sky calib #105

Merged
merged 2 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions python/lsst/pipe/tasks/ingestCalibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def getCalibType(self, filename):
obstype = "dark"
elif "fringe" in obstype:
obstype = "fringe"
elif "sky" in obstype:
obstype = "sky"
return obstype

def getDestination(self, butler, info, filename):
Expand All @@ -64,7 +66,7 @@ def getDestination(self, butler, info, filename):

class CalibsRegisterConfig(RegisterConfig):
"""Configuration for the CalibsRegisterTask"""
tables = ListField(dtype=str, default=["bias", "dark", "flat", "fringe"], doc="Names of tables")
tables = ListField(dtype=str, default=["bias", "dark", "flat", "fringe", "sky"], doc="Names of tables")
calibDate = Field(dtype=str, default="calibDate", doc="Name of column for calibration date")
validStart = Field(dtype=str, default="validStart", doc="Name of column for validity start")
validEnd = Field(dtype=str, default="validEnd", doc="Name of column for validity stop")
Expand Down Expand Up @@ -188,7 +190,7 @@ def __init__(self, *args, **kwargs):
self.add_argument("--create", action="store_true", help="Create new registry?")
self.add_argument("--validity", type=int, required=True, help="Calibration validity period (days)")
self.add_argument("--calibType", type=str, default=None,
choices=[None, "bias", "dark", "flat", "fringe", "defect"],
choices=[None, "bias", "dark", "flat", "fringe", "sky", "defect"],
help="Type of the calibration data to be ingested;" +
" if omitted, the type is determined from" +
" the file header information")
Expand Down
27 changes: 27 additions & 0 deletions python/lsst/pipe/tasks/makeCoaddTempExp.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class MakeCoaddTempExpConfig(CoaddBaseTask.ConfigClass):
dtype=bool,
default=False,
)
doApplySkyCorr = pexConfig.Field(dtype=bool, default=False, doc="Apply sky correction?")

def validate(self):
CoaddBaseTask.ConfigClass.validate(self)
Expand Down Expand Up @@ -366,6 +367,10 @@ def createTempExp(self, calexpRefList, skyInfo, visitId=0):
except Exception as e:
self.log.warn("Calexp %s not found; skipping it: %s", calExpRef.dataId, e)
continue

if self.config.doApplySkyCorr:
self.applySkyCorr(calExpRef, calExp)

try:
warpedAndMatched = self.warpAndPsfMatch.run(calExp, modelPsf=modelPsf,
wcs=skyInfo.wcs, maxBBox=skyInfo.bbox,
Expand Down Expand Up @@ -439,3 +444,25 @@ def getWarpTypeList(self):
if self.config.makePsfMatched:
warpTypeList.append("psfMatched")
return warpTypeList

def applySkyCorr(self, dataRef, calexp):
"""Apply correction to the sky background level

Sky corrections can be generated with the 'skyCorrection.py'
executable in pipe_drivers. Because the sky model used by that
code extends over the entire focal plane, this can produce
better sky subtraction.

The calexp is updated in-place.

Parameters
----------
dataRef : `lsst.daf.persistence.ButlerDataRef`
Data reference for calexp.
calexp : `lsst.afw.image.Exposure` or `lsst.afw.image.MaskedImage`
Calibrated exposure.
"""
bg = dataRef.get("skyCorr")
if isinstance(calexp, afwImage.Exposure):
calexp = calexp.getMaskedImage()
calexp -= bg.getImage()