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 4aff330
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 16 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,18 @@ 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 +846,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 +870,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
2 changes: 2 additions & 0 deletions tests/test_ptc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def get(self, component=None):
return self.exp.getVisitInfo()
elif component == 'detector':
return self.exp.getDetector()
elif component == 'metadata':
return self.exp.getMetadata()
else:
return self.exp

Expand Down

0 comments on commit 4aff330

Please sign in to comment.