Skip to content

Commit

Permalink
Bin difference image
Browse files Browse the repository at this point in the history
  • Loading branch information
plazas committed Oct 7, 2021
1 parent 88fff79 commit 8c2b2de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions pipelines/measurePhotonTransferCurve.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ tasks:
ptcFitType: FULLCOVARIANCE
contracts:
- ptcSolve.maximumRangeCovariancesAstier == ptcExtract.maximumRangeCovariancesAstier
- ptcSolve.binSize == ptcExtract.binSize
9 changes: 4 additions & 5 deletions python/lsst/cp/pipe/ptc/cpExtractPtcTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,6 @@ def measureMeanVarCov(self, exposure1, exposure2, region=None, covAstierRealSpac
im1Area = exposure1.maskedImage
im2Area = exposure2.maskedImage

if self.config.binSize > 1:
im1Area = afwMath.binImage(im1Area, self.config.binSize)
im2Area = afwMath.binImage(im2Area, self.config.binSize)

im1MaskVal = exposure1.getMask().getPlaneBitMask(self.config.maskNameList)
im1StatsCtrl = afwMath.StatisticsControl(self.config.nSigmaClipPtc,
self.config.nIterSigmaClipPtc,
Expand Down Expand Up @@ -464,6 +460,9 @@ def measureMeanVarCov(self, exposure1, exposure2, region=None, covAstierRealSpac
diffIm -= temp
diffIm /= mu

if self.config.binSize > 1:
diffIm = afwMath.binImage(diffIm, self.config.binSize)

diffImMaskVal = diffIm.getMask().getPlaneBitMask(self.config.maskNameList)
diffImStatsCtrl = afwMath.StatisticsControl(self.config.nSigmaClipPtc,
self.config.nIterSigmaClipPtc,
Expand All @@ -489,7 +488,7 @@ def measureMeanVarCov(self, exposure1, exposure2, region=None, covAstierRealSpac
# calculations below.
w = unmasked*wDiff

if np.sum(w) < self.config.minNumberGoodPixelsForCovariance:
if np.sum(w) < self.config.minNumberGoodPixelsForCovariance/(self.config.binSize**2):
self.log.warn(f"Number of good points for covariance calculation ({np.sum(w)}) is less "
f"(than threshold {self.config.minNumberGoodPixelsForCovariance})")
return np.nan, np.nan, None
Expand Down
12 changes: 10 additions & 2 deletions python/lsst/cp/pipe/ptc/cpSolvePtcTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ class PhotonTransferCurveSolveConfig(pipeBase.PipelineTaskConfig,
doc="Use bootstrap for the PTC fit parameters and errors?.",
default=False,
)
binSize = pexConfig.Field(
dtype=int,
doc="Bin the image by this factor in both dimensions.",
default=1,
)


class PhotonTransferCurveSolveTask(pipeBase.PipelineTask,
Expand Down Expand Up @@ -595,8 +600,11 @@ def errFunc(p, x, y):
parsIniPtc = [-1e-9, 1.0, 10.] # a00, gain, noisei^2
# lowers and uppers obtained from BOT data studies by
# C. Lage (UC Davis, 11/2020).
bounds = self._boundsForAstier(parsIniPtc, lowers=[-1e-4, 0.5, -2000],
uppers=[1e-4, 2.5, 2000])
if self.config.binSize > 1:
bounds = self._boundsForAstier(parsIniPtc)
else:
bounds = self._boundsForAstier(parsIniPtc, lowers=[-1e-4, 0.5, -2000],
uppers=[1e-4, 2.5, 2000])
if ptcFitType == 'POLYNOMIAL':
ptcFunc = funcPolynomial
parsIniPtc = self._initialParsForPolynomial(self.config.polynomialFitDegree + 1)
Expand Down

0 comments on commit 8c2b2de

Please sign in to comment.