Skip to content

Commit

Permalink
IsrTask: check for non-finite darktime
Browse files Browse the repository at this point in the history
Scaling by a non-finite darktime can destroy the image.
This is important because the darktime defaults to NAN
unless set explicitly by the obs package.
  • Loading branch information
PaulPrice committed Jan 16, 2017
1 parent cf69c82 commit 2ed0dcf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
10 changes: 8 additions & 2 deletions python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,17 @@ def darkCorrection(self, exposure, darkExposure):
\param[in,out] exposure exposure to process
\param[in] darkExposure dark exposure of same size as exposure
"""
expScale = exposure.getInfo().getVisitInfo().getDarkTime()
if math.isnan(expScale):
raise RuntimeError("Exposure darktime is NAN")
darkScale = darkExposure.getInfo().getVisitInfo().getDarkTime()
if math.isnan(darkScale):
raise RuntimeError("Dark calib darktime is NAN")
isr.darkCorrection(
maskedImage=exposure.getMaskedImage(),
darkMaskedImage=darkExposure.getMaskedImage(),
expScale=exposure.getInfo().getVisitInfo().getExposureTime(),
darkScale=darkExposure.getInfo().getVisitInfo().getExposureTime(),
expScale=expScale,
darkScale=darkScale,
)

def doLinearize(self, detector):
Expand Down
41 changes: 41 additions & 0 deletions tests/testBiasAndDarkCorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,47 @@ def testDark2(self):
def testDark3(self):
self.doDark(scaling=3.7)

def testDarkWithDarktime(self):
darkTime = 128.0
nan = float("NAN")

exp = afwImage.ExposureF(1, 1)
exp.getMaskedImage().getImage().set(1.0)
exp.getMaskedImage().getMask().set(0)
exp.getMaskedImage().getVariance().set(1.0)

dark = afwImage.ExposureF(1, 1)
dark.getMaskedImage().getImage().set(1.0/darkTime)
dark.getMaskedImage().getMask().set(0)
dark.getMaskedImage().getVariance().set(0.0)
dark.getInfo().setVisitInfo(afwImage.makeVisitInfo())

task = ipIsr.IsrTask()

# No darktime set in at least one of the inputs
exp.getInfo().setVisitInfo(afwImage.makeVisitInfo(darkTime=nan))
dark.getInfo().setVisitInfo(afwImage.makeVisitInfo(darkTime=nan))
with self.assertRaises(RuntimeError):
task.darkCorrection(exp, dark)
exp.getInfo().setVisitInfo(afwImage.makeVisitInfo(darkTime=nan))
dark.getInfo().setVisitInfo(afwImage.makeVisitInfo(darkTime=1.0))
with self.assertRaises(RuntimeError):
task.darkCorrection(exp, dark)
exp.getInfo().setVisitInfo(afwImage.makeVisitInfo(darkTime=1.0))
dark.getInfo().setVisitInfo(afwImage.makeVisitInfo(darkTime=nan))
with self.assertRaises(RuntimeError):
task.darkCorrection(exp, dark)

# With darktime set
exp.getInfo().setVisitInfo(afwImage.makeVisitInfo(darkTime=darkTime))
dark.getInfo().setVisitInfo(afwImage.makeVisitInfo(darkTime=1.0))
task.darkCorrection(exp, dark)

self.assertEqual(exp.getMaskedImage().getImage().get(0, 0), 0.0)
self.assertEqual(exp.getMaskedImage().getMask().get(0, 0), 0)
self.assertEqual(exp.getMaskedImage().getVariance().get(0, 0), 1.0)
self.assertEqual(exp.getInfo().getVisitInfo().getDarkTime(), darkTime) # Hasn't been modified


class MemoryTester(lsst.utils.tests.MemoryTestCase):
pass
Expand Down

0 comments on commit 2ed0dcf

Please sign in to comment.