Skip to content

Commit

Permalink
Get only the metadata if only the metadata is needed. Docstring update.
Browse files Browse the repository at this point in the history
  • Loading branch information
czwa committed Mar 6, 2023
1 parent 6ff0598 commit 234ec56
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions python/lsst/cp/pipe/ptc/cpExtractPtcTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,16 @@ def run(self, inputExp, inputDims, taskMetadata):
# and a pair of references at that index.
for expRef, expId in expRefs:
# This yields an exposure ref and an exposureId.
exposure = expRef.get()
exposureMetadata = expRef.get(component="metadata")
metadataIndex = inputDims.index(expId)
thisTaskMetadata = taskMetadata[metadataIndex]

for ampName in ampNames:
if ampName not in readNoiseLists:
readNoiseLists[ampName] = [self.getReadNoise(exposure, thisTaskMetadata, ampName)]
readNoiseLists[ampName] = [self.getReadNoise(exposureMetadata, thisTaskMetadata, ampName)]
else:
readNoiseLists[ampName].append(self.getReadNoise(exposure, thisTaskMetadata, ampName))
readNoiseLists[ampName].append(self.getReadNoise(exposureMetadata, thisTaskMetadata, ampName))

readNoiseDict = {ampName: 0.0 for ampName in ampNames}
for ampName in ampNames:
# Take median read noise value
Expand Down Expand Up @@ -843,13 +844,18 @@ def getGainFromFlatPair(self, im1Area, im2Area, imStatsCtrl, mu1, mu2,

return gain

def getReadNoise(self, exposure, taskMetadata, ampName):
def getReadNoise(self, exposureMetadata, taskMetadata, ampName):
"""Gets readout noise for an amp from ISR metadata.
If possible, this attempts to get the now-standard headers
added to the exposure itself. If not found there, the ISR
TaskMetadata is searched. If neither of these has the value,
warn and set the read noise to NaN.
Parameters
----------
exposure : `lsst.afw.image.Exposure`
Exposure to check for read noise first.
exposureMetadata : `lsst.daf.base.PropertySet`
Metadata to check for read noise first.
taskMetadata : `lsst.pipe.base.TaskMetadata`
List of exposures metadata from ISR for this exposure.
ampName : `str`
Expand All @@ -862,9 +868,8 @@ def getReadNoise(self, exposure, taskMetadata, ampName):
"""
# Try from the exposure first.
expectedKey = f"LSST ISR OVERSCAN RESIDUAL SERIAL STDEV {ampName}"
md = exposure.getMetadata()
if expectedKey in md:
return md[expectedKey]
if expectedKey in exposureMetadata:
return exposureMetadata[expectedKey]

# If not, try getting it from the task metadata.
expectedKey = f"RESIDUAL STDEV {ampName}"
Expand Down

0 comments on commit 234ec56

Please sign in to comment.