-
Notifications
You must be signed in to change notification settings - Fork 7
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-42163: eo_pipe/cp_verify parity: ptc #228
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
import lsst.afw.math as afwMath | ||
import lsst.pex.config as pexConfig | ||
import lsst.pipe.base as pipeBase | ||
from lsst.geom import (Box2I, Point2I, Extent2I) | ||
from lsst.cp.pipe.utils import (arrangeFlatsByExpTime, arrangeFlatsByExpId, | ||
arrangeFlatsByExpFlux, sigmaClipCorrection, | ||
CovFastFourierTransform) | ||
|
@@ -558,7 +559,11 @@ def run(self, inputExp, inputDims, taskMetadata, inputPhotodiodeData=None): | |
# returned is of the form: | ||
# [(i, j, var (cov[0,0]), cov, npix) for (i,j) in | ||
# {maxLag, maxLag}^2]. | ||
muDiff, varDiff, covAstier = self.measureMeanVarCov(im1Area, im2Area, imStatsCtrl, mu1, mu2) | ||
muDiff, varDiff, covAstier, rowMeanVariance = self.measureMeanVarCov(im1Area, | ||
im2Area, | ||
imStatsCtrl, | ||
mu1, | ||
mu2) | ||
# Estimate the gain from the flat pair | ||
if self.config.doGain: | ||
gain = self.getGainFromFlatPair(im1Area, im2Area, imStatsCtrl, mu1, mu2, | ||
|
@@ -579,8 +584,10 @@ def run(self, inputExp, inputDims, taskMetadata, inputPhotodiodeData=None): | |
# Mask data point at this mean signal level if | ||
# the signal, variance, or covariance calculations | ||
# from `measureMeanVarCov` resulted in NaNs. | ||
if np.isnan(muDiff) or np.isnan(varDiff) or (covAstier is None): | ||
self.log.warning("NaN mean or var, or None cov in amp %s in exposure pair %d, %d of " | ||
if (np.isnan(muDiff) or np.isnan(varDiff) or (covAstier is None) | ||
or (rowMeanVariance is np.nan)): | ||
self.log.warning("NaN mean, var or rowmeanVariance, or None cov in amp %s " | ||
"in exposure pair %d, %d of " | ||
"detector %d.", ampName, expId1, expId2, detNum) | ||
nAmpsNan += 1 | ||
expIdMask = False | ||
|
@@ -664,6 +671,7 @@ def run(self, inputExp, inputDims, taskMetadata, inputPhotodiodeData=None): | |
histVar=histVar, | ||
histChi2Dof=histChi2Dof, | ||
kspValue=kspValue, | ||
rowMeanVariance=rowMeanVariance, | ||
) | ||
|
||
partialPtcDataset.setAuxValuesPartialDataset(auxDict) | ||
|
@@ -789,11 +797,11 @@ def measureMeanVarCov(self, im1Area, im2Area, imStatsCtrl, mu1, mu2): | |
|
||
Returns | ||
------- | ||
mu : `float` or `NaN` | ||
mu : `float` | ||
0.5*(mu1 + mu2), where mu1, and mu2 are the clipped means | ||
of the regions in both exposures. If either mu1 or m2 are | ||
NaN's, the returned value is NaN. | ||
varDiff : `float` or `NaN` | ||
varDiff : `float` | ||
Half of the clipped variance of the difference of the | ||
regions inthe two input exposures. If either mu1 or m2 are | ||
NaN's, the returned value is NaN. | ||
|
@@ -809,12 +817,15 @@ def measureMeanVarCov(self, im1Area, im2Area, imStatsCtrl, mu1, mu2): | |
Covariance at (dx, dy). | ||
nPix : `int` | ||
Number of pixel pairs used to evaluate var and cov. | ||
rowMeanVariance : `float` | ||
Variance of the means of each row in the difference image. | ||
Taken from `github.com/lsst-camera-dh/eo_pipe`. | ||
|
||
If either mu1 or m2 are NaN's, the returned value is NaN. | ||
""" | ||
if np.isnan(mu1) or np.isnan(mu2): | ||
self.log.warning("Mean of amp in image 1 or 2 is NaN: %f, %f.", mu1, mu2) | ||
return np.nan, np.nan, None | ||
return np.nan, np.nan, None, np.nan | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test above (L587) tests for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the test to check for |
||
mu = 0.5*(mu1 + mu2) | ||
|
||
# Take difference of pairs | ||
|
@@ -829,6 +840,20 @@ def measureMeanVarCov(self, im1Area, im2Area, imStatsCtrl, mu1, mu2): | |
if self.config.binSize > 1: | ||
diffIm = afwMath.binImage(diffIm, self.config.binSize) | ||
|
||
# Calculate the variance (in ADU^2) of the means of rows for diffIm. | ||
# Taken from eo_pipe | ||
region = diffIm.getBBox() | ||
rowMeans = [] | ||
for row in range(region.minY, region.maxY): | ||
regionRow = Box2I(Point2I(region.minX, row), | ||
Extent2I(region.width, 1)) | ||
rowMeans.append(afwMath.makeStatistics(diffIm[regionRow], | ||
afwMath.MEAN, | ||
imStatsCtrl).getValue()) | ||
rowMeanVariance = afwMath.makeStatistics( | ||
np.array(rowMeans), afwMath.VARIANCECLIP, | ||
imStatsCtrl).getValue() | ||
|
||
# Variance calculation via afwMath | ||
varDiff = 0.5*(afwMath.makeStatistics(diffIm, afwMath.VARIANCECLIP, imStatsCtrl).getValue()) | ||
|
||
|
@@ -851,7 +876,7 @@ def measureMeanVarCov(self, im1Area, im2Area, imStatsCtrl, mu1, mu2): | |
self.log.warning("Number of good points for covariance calculation (%s) is less " | ||
"(than threshold %s)", np.sum(w), | ||
self.config.minNumberGoodPixelsForCovariance/(self.config.binSize**2)) | ||
return np.nan, np.nan, None | ||
return np.nan, np.nan, None, np.nan | ||
|
||
maxRangeCov = self.config.maximumRangeCovariancesAstier | ||
|
||
|
@@ -870,7 +895,7 @@ def measureMeanVarCov(self, im1Area, im2Area, imStatsCtrl, mu1, mu2): | |
# This is raised if there are not enough pixels. | ||
self.log.warning("Not enough pixels covering the requested covariance range in x/y (%d)", | ||
self.config.maximumRangeCovariancesAstier) | ||
return np.nan, np.nan, None | ||
return np.nan, np.nan, None, np.nan | ||
|
||
# Compare Cov[0,0] and afwMath.VARIANCECLIP covDiffAstier[0] | ||
# is the Cov[0,0] element, [3] is the variance, and there's a | ||
|
@@ -881,7 +906,7 @@ def measureMeanVarCov(self, im1Area, im2Area, imStatsCtrl, mu1, mu2): | |
self.log.warning("Absolute fractional difference between afwMatch.VARIANCECLIP and Cov[0,0] " | ||
"is more than %f%%: %f", thresholdPercentage, fractionalDiff) | ||
|
||
return mu, varDiff, covDiffAstier | ||
return mu, varDiff, covDiffAstier, rowMeanVariance | ||
|
||
def getImageAreasMasksStats(self, exposure1, exposure2, region=None): | ||
"""Get image areas in a region as well as masks and statistic objects. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"rowMeanVariance"? Just for consistency.