Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Update tests
  • Loading branch information
plazas committed May 24, 2022
1 parent 10b6f64 commit 9a2251d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
17 changes: 7 additions & 10 deletions python/lsst/cp/pipe/ptc/cpExtractPtcTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,6 @@ def getImageAreasMasksStats(self, exposure1, exposure2, region=None):
im1Area = exposure1.maskedImage
im2Area = exposure2.maskedImage

resultsDict['im1Area'] = im1Area
resultsDict['im2Area'] = im2Area

if self.config.binSize > 1:
im1Area = afwMath.binImage(im1Area, self.config.binSize)
im2Area = afwMath.binImage(im2Area, self.config.binSize)
Expand All @@ -668,24 +665,24 @@ def getImageAreasMasksStats(self, exposure1, exposure2, region=None):
im1StatsCtrl.setNanSafe(True)
im1StatsCtrl.setAndMask(im1MaskVal)

resultsDict['im1MaskVal'] = im1MaskVal
resultsDict['im1StatsCtrl'] = im1StatsCtrl

im2MaskVal = exposure2.getMask().getPlaneBitMask(self.config.maskNameList)
im2StatsCtrl = afwMath.StatisticsControl(self.config.nSigmaClipPtc,
self.config.nIterSigmaClipPtc,
im2MaskVal)
im2StatsCtrl.setNanSafe(True)
im2StatsCtrl.setAndMask(im2MaskVal)

resultsDict['im2MaskVal'] = im2MaskVal
resultsDict['im2StatsCtrl'] = im2StatsCtrl

mu1 = afwMath.makeStatistics(im1Area, afwMath.MEANCLIP, im1StatsCtrl).getValue()
mu2 = afwMath.makeStatistics(im2Area, afwMath.MEANCLIP, im2StatsCtrl).getValue()

resultsDict['im1Area'] = im1Area
resultsDict['im1MaskVal'] = im1MaskVal
resultsDict['im1StatsCtrl'] = im1StatsCtrl
resultsDict['im2Area'] = im2Area
resultsDict['im2MaskVal'] = im2MaskVal
resultsDict['im2StatsCtrl'] = im2StatsCtrl
resultsDict['mu1'] = mu1
resultsDict['mu1'] = mu2
resultsDict['mu2'] = mu2

return resultsDict

Expand Down
22 changes: 14 additions & 8 deletions tests/test_ptc.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def setUp(self):
self.metadataContents["isr"] = {}
# Overscan readout noise [in ADU]
for amp in self.ampNames:
self.metadataContents["isr"][f"RESIDUAL STDEV {amp}"] = np.sqrt(self.noiseSq/self.gain)
self.metadataContents["isr"][f"RESIDUAL STDEV {amp}"] = np.sqrt(self.noiseSq)/self.gain

def test_covAstier(self):
"""Test to check getCovariancesAstier
Expand Down Expand Up @@ -147,16 +147,17 @@ def test_covAstier(self):
idCounter = 0
for expTime in self.timeVec:
mockExp1, mockExp2 = makeMockFlats(expTime, gain=inputGain,
readNoiseElectrons=3, expId1=idCounter,
expId2=idCounter+1)
readNoiseElectrons=3,
expId1=idCounter, expId2=idCounter+1)
mockExpRef1 = PretendRef(mockExp1)
mockExpRef2 = PretendRef(mockExp2)
expDict[expTime] = ((mockExpRef1, idCounter), (mockExpRef2, idCounter+1))
expIds.append(idCounter)
expIds.append(idCounter+1)
for ampNumber, ampName in enumerate(self.ampNames):
# cov has (i, j, var, cov, npix)
muDiff, varDiff, covAstier = extractTask.measureMeanVarCov(mockExp1, mockExp2)
imageProps = extractTask.getImageAreasMasksStats(mockExp1, mockExp2)
muDiff, varDiff, covAstier = extractTask.measureMeanVarCov(imageProps)
muStandard.setdefault(ampName, []).append(muDiff)
varStandard.setdefault(ampName, []).append(varDiff)
idCounter += 2
Expand Down Expand Up @@ -302,7 +303,8 @@ def test_ptcFit(self):

def test_meanVarMeasurement(self):
task = self.defaultTaskExtract
mu, varDiff, _ = task.measureMeanVarCov(self.flatExp1, self.flatExp2)
imageProps = task.getImageAreasMasksStats(self.flatExp1, self.flatExp2)
mu, varDiff, _ = task.measureMeanVarCov(imageProps)

self.assertLess(self.flatWidth - np.sqrt(varDiff), 1)
self.assertLess(self.flatMean - mu, 1)
Expand All @@ -312,7 +314,8 @@ def test_meanVarMeasurementWithNans(self):
self.flatExp1.image.array[20:30, :] = np.nan
self.flatExp2.image.array[20:30, :] = np.nan

mu, varDiff, _ = task.measureMeanVarCov(self.flatExp1, self.flatExp2)
imageProps = task.getImageAreasMasksStats(self.flatExp1, self.flatExp2)
mu, varDiff, _ = task.measureMeanVarCov(imageProps)

expectedMu1 = np.nanmean(self.flatExp1.image.array)
expectedMu2 = np.nanmean(self.flatExp2.image.array)
Expand Down Expand Up @@ -343,7 +346,8 @@ def test_meanVarMeasurementAllNan(self):
self.flatExp1.image.array[:, :] = np.nan
self.flatExp2.image.array[:, :] = np.nan

mu, varDiff, covDiff = task.measureMeanVarCov(self.flatExp1, self.flatExp2)
imageProps = task.getImageAreasMasksStats(self.flatExp1, self.flatExp2)
mu, varDiff, covDiff = task.measureMeanVarCov(imageProps)

self.assertTrue(np.isnan(mu))
self.assertTrue(np.isnan(varDiff))
Expand Down Expand Up @@ -416,8 +420,10 @@ def runGetGainFromFlatPair(self, correctionType='NONE'):
idCounter = 0
inputGain = self.gain # 1.5 e/ADU
for expTime in self.timeVec:
# Approximation works better at low flux, e.g., < 10000 ADU
mockExp1, mockExp2 = makeMockFlats(expTime, gain=inputGain,
readNoiseElectrons=np.sqrt(self.noiseSq),
fluxElectrons=100,
expId1=idCounter, expId2=idCounter+1)
mockExpRef1 = PretendRef(mockExp1)
mockExpRef2 = PretendRef(mockExp2)
Expand All @@ -433,7 +439,7 @@ def runGetGainFromFlatPair(self, correctionType='NONE'):
for ampName in self.ampNames:
if exposurePair.gain[ampName] is np.nan:
continue
self.assertAlmostEqual(exposurePair.gain[ampName], inputGain, delta=0.075)
self.assertAlmostEqual(exposurePair.gain[ampName], inputGain, delta=0.16)

def test_getGainFromFlatPair(self):
for gainCorrectionType in ['NONE', 'SIMPLE', 'FULL', ]:
Expand Down

0 comments on commit 9a2251d

Please sign in to comment.