Skip to content

Commit

Permalink
Raise is ptcDatset or overscan image are None
Browse files Browse the repository at this point in the history
  • Loading branch information
plazas committed Apr 22, 2021
1 parent eb12741 commit 2e411b9
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -2110,13 +2110,28 @@ def updateVariance(self, ampExposure, amp, overscanImage=None, ptcDataset=None):
Image of overscan, required only for empirical read noise.
ptcDataset : `lsst.ip.isr.PhotonTransferCurveDataset`, optional
PTC dataset containing the gains and read noise.
Raises
------
RuntimeError
Raised is either ``usePtcGains`` of ``usePtcReadNoise``
are ``True``, but there is not ptcDataset provided.
Raised if ```doEmpiricalReadNoise`` is ``True`` but
``overscanImage`` is ``None``.
See also
--------
lsst.ip.isr.isrFunctions.updateVariance
"""
maskPlanes = [self.config.saturatedMaskName, self.config.suspectMaskName]
if self.config.usePtcGains and ptcDataset is not None:
gain = ptcDataset.gain[amp.getName()]
if self.config.usePtcGains:
if ptcDataset is None:
raise RuntimeError("No ptcDataset provided to use PTC gains.")
else:
gain = ptcDataset.gain[amp.getName()]
self.log.info("Using gain from Photon Transfer Curve.")
else:
gain = amp.getGain()

Expand All @@ -2130,16 +2145,19 @@ def updateVariance(self, ampExposure, amp, overscanImage=None, ptcDataset=None):
gain = patchedGain

if self.config.doEmpiricalReadNoise and overscanImage is None:
self.log.info("Overscan is none for EmpiricalReadNoise.")
raise RuntimeError("Overscan is none for EmpiricalReadNoise.")

if self.config.doEmpiricalReadNoise and overscanImage is not None:
stats = afwMath.StatisticsControl()
stats.setAndMask(overscanImage.mask.getPlaneBitMask(maskPlanes))
readNoise = afwMath.makeStatistics(overscanImage, afwMath.STDEVCLIP, stats).getValue()
self.log.info("Calculated empirical read noise for amp %s: %f.",
amp.getName(), readNoise)
elif self.config.usePtcReadNoise and ptcDataset is not None:
readNoise = ptcDataset.noise[amp.getName()]
elif self.config.usePtcReadNoise:
if ptcDataset is None:
raise RuntimeError("No ptcDataset provided to use PTC readnoise.")
else:
readNoise = ptcDataset.noise[amp.getName()]
self.log.info("Using read noise from Photon Transfer Curve.")
else:
readNoise = amp.getReadNoise()
Expand Down

0 comments on commit 2e411b9

Please sign in to comment.