Skip to content

Commit

Permalink
Improve logging with images with bad headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
erykoff committed Dec 7, 2023
1 parent 4345504 commit ebd75d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 8 additions & 4 deletions python/lsst/cp/pipe/ptc/cpExtractPtcTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,14 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
# containing flat exposures and their IDs.
matchType = self.config.matchExposuresType
if matchType == 'TIME':
inputs['inputExp'] = arrangeFlatsByExpTime(inputs['inputExp'], inputs['inputDims'])
inputs['inputExp'] = arrangeFlatsByExpTime(inputs['inputExp'], inputs['inputDims'], log=self.log)
elif matchType == 'FLUX':
inputs['inputExp'] = arrangeFlatsByExpFlux(inputs['inputExp'], inputs['inputDims'],
self.config.matchExposuresByFluxKeyword)
inputs['inputExp'] = arrangeFlatsByExpFlux(
inputs['inputExp'],
inputs['inputDims'],
self.config.matchExposuresByFluxKeyword,
log=self.log,
)
else:
inputs['inputExp'] = arrangeFlatsByExpId(inputs['inputExp'], inputs['inputDims'])

Expand Down Expand Up @@ -470,7 +474,7 @@ def run(self, inputExp, inputDims, taskMetadata, inputPhotodiodeData=None):
for expTime in inputExp:
exposures = inputExp[expTime]
if not np.isfinite(expTime):
self.log.warning("Illegal/missing %s found (%f). Dropping exposure %d",
self.log.warning("Illegal/missing %s found (%s). Dropping exposure %d",
self.config.matchExposuresType, expTime, exposures[0][1])
continue
elif len(exposures) == 1:
Expand Down
12 changes: 10 additions & 2 deletions python/lsst/cp/pipe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def funcAstier(pars, x):
return 0.5/(a00*gain*gain)*(np.exp(2*a00*x*gain)-1) + noise/(gain*gain) # C_00


def arrangeFlatsByExpTime(exposureList, exposureIdList):
def arrangeFlatsByExpTime(exposureList, exposureIdList, log=None):
"""Arrange exposures by exposure time.
Parameters
Expand All @@ -457,6 +457,8 @@ def arrangeFlatsByExpTime(exposureList, exposureIdList):
Input list of exposure references.
exposureIdList : `list` [`int`]
List of exposure ids as obtained by dataId[`exposure`].
log : `lsst.utils.logging.LsstLogAdapter`, optional
Log object.
Returns
------
Expand All @@ -470,13 +472,15 @@ def arrangeFlatsByExpTime(exposureList, exposureIdList):
assert len(exposureList) == len(exposureIdList), "Different lengths for exp. list and exp. ID lists"
for expRef, expId in zip(exposureList, exposureIdList):
expTime = expRef.get(component='visitInfo').exposureTime
if not np.isfinite(expTime) and log is not None:
log.warning("Exposure %d has non-finite exposure time.", expId)
listAtExpTime = flatsAtExpTime.setdefault(expTime, [])
listAtExpTime.append((expRef, expId))

return flatsAtExpTime


def arrangeFlatsByExpFlux(exposureList, exposureIdList, fluxKeyword):
def arrangeFlatsByExpFlux(exposureList, exposureIdList, fluxKeyword, log=None):
"""Arrange exposures by exposure flux.
Parameters
Expand All @@ -487,6 +491,8 @@ def arrangeFlatsByExpFlux(exposureList, exposureIdList, fluxKeyword):
List of exposure ids as obtained by dataId[`exposure`].
fluxKeyword : `str`
Header keyword that contains the flux per exposure.
log : `lsst.utils.logging.LsstLogAdapter`, optional
Log object.
Returns
-------
Expand All @@ -507,6 +513,8 @@ def arrangeFlatsByExpFlux(exposureList, exposureIdList, fluxKeyword):
# be caught and rejected when pairing exposures.
expFlux = None
if expFlux is None:
if log is not None:
log.warning("Exposure %d does not have valid header keyword %s.", expId, fluxKeyword)
expFlux = np.nan
listAtExpFlux = flatsAtExpFlux.setdefault(expFlux, [])
listAtExpFlux.append((expRef, expId))
Expand Down

0 comments on commit ebd75d3

Please sign in to comment.