Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-25934: MeasurePhotonTransferCurveTask appears to ignore the defect mask #42

Merged
merged 1 commit into from
Jul 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 26 additions & 6 deletions python/lsst/cp/pipe/ptc.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ class MeasurePhotonTransferCurveTaskConfig(pexConfig.Config):
doc="Sigma cut for outlier rejection in PTC.",
default=5.0,
)
maskNameList = pexConfig.ListField(
dtype=str,
doc="Mask list to exclude from statistics calculations.",
default=['DETECTED', 'BAD', 'NO_DATA'],
)
nSigmaClipPtc = pexConfig.Field(
dtype=float,
doc="Sigma cut for afwMath.StatisticsControl()",
Expand Down Expand Up @@ -598,12 +603,21 @@ def measureMeanVarCov(self, exposure1, exposure2, region=None, covAstierRealSpac
im1Area = afwMath.binImage(im1Area, self.config.binSize)
im2Area = afwMath.binImage(im2Area, self.config.binSize)

statsCtrl = afwMath.StatisticsControl()
statsCtrl.setNumSigmaClip(self.config.nSigmaClipPtc)
statsCtrl.setNumIter(self.config.nIterSigmaClipPtc)
im1MaskVal = exposure1.getMask().getPlaneBitMask(self.config.maskNameList)
im1StatsCtrl = afwMath.StatisticsControl(self.config.nSigmaClipPtc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think setting things with the statsCtrl.setXYZ() methods is clearer, but this is perfectly fine as the config options state what they are.

self.config.nIterSigmaClipPtc,
im1MaskVal)
im1StatsCtrl.setAndMask(im1MaskVal)

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

# Clipped mean of images; then average of mean.
mu1 = afwMath.makeStatistics(im1Area, afwMath.MEANCLIP, statsCtrl).getValue()
mu2 = afwMath.makeStatistics(im2Area, afwMath.MEANCLIP, statsCtrl).getValue()
mu1 = afwMath.makeStatistics(im1Area, afwMath.MEANCLIP, im1StatsCtrl).getValue()
mu2 = afwMath.makeStatistics(im2Area, afwMath.MEANCLIP, im2StatsCtrl).getValue()
mu = 0.5*(mu1 + mu2)

# Take difference of pairs
Expand All @@ -615,7 +629,13 @@ def measureMeanVarCov(self, exposure1, exposure2, region=None, covAstierRealSpac
diffIm -= temp
diffIm /= mu

varDiff = 0.5*(afwMath.makeStatistics(diffIm, afwMath.VARIANCECLIP, statsCtrl).getValue())
diffImMaskVal = diffIm.getMask().getPlaneBitMask(self.config.maskNameList)
diffImStatsCtrl = afwMath.StatisticsControl(self.config.nSigmaClipPtc,
self.config.nIterSigmaClipPtc,
diffImMaskVal)
diffImStatsCtrl.setAndMask(diffImMaskVal)

varDiff = 0.5*(afwMath.makeStatistics(diffIm, afwMath.VARIANCECLIP, diffImStatsCtrl).getValue())

# Get the mask and identify good pixels as '1', and the rest as '0'.
w1 = np.where(im1Area.getMask().getArray() == 0, 1, 0)
Expand Down