-
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-30130: Establish a 1-1 correspondence between exposures and input dimensions in cpPtcExtract #89
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 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 |
---|---|---|
|
@@ -66,7 +66,7 @@ class PhotonTransferCurveExtractConfig(pipeBase.PipelineTaskConfig, | |
""" | ||
matchByExposureId = pexConfig.Field( | ||
dtype=bool, | ||
doc="Should exposures by matched by ID rather than exposure time?", | ||
doc="Should exposures be matched by ID rather than exposure time?", | ||
default=False, | ||
) | ||
maximumRangeCovariancesAstier = pexConfig.Field( | ||
|
@@ -201,34 +201,36 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs): | |
Output data refs to persist. | ||
""" | ||
inputs = butlerQC.get(inputRefs) | ||
# Dictionary, keyed by expTime, with flat exposures | ||
if self.config.matchByExposureId: | ||
inputs['inputExp'] = arrangeFlatsByExpId(inputs['inputExp']) | ||
else: | ||
inputs['inputExp'] = arrangeFlatsByExpTime(inputs['inputExp']) | ||
# Ids of input list of exposures | ||
inputs['inputDims'] = [expId.dataId['exposure'] for expId in inputRefs.inputExp] | ||
|
||
# Dictionary, keyed by expTime, with tuples containing flat exposures and their IDs. | ||
if self.config.matchByExposureId: | ||
inputs['inputExp'] = arrangeFlatsByExpId(inputs['inputExp'], inputs['inputDims']) | ||
else: | ||
inputs['inputExp'] = arrangeFlatsByExpTime(inputs['inputExp'], inputs['inputDims']) | ||
|
||
outputs = self.run(**inputs) | ||
butlerQC.put(outputs, outputRefs) | ||
|
||
def run(self, inputExp, inputDims): | ||
def run(self, inputDims, inputExp): | ||
"""Measure covariances from difference of flat pairs | ||
|
||
Parameters | ||
---------- | ||
inputDims : `list` | ||
List of exposure IDs. | ||
|
||
inputExp : `dict` [`float`, | ||
(`~lsst.afw.image.exposure.exposure.ExposureF`, | ||
`~lsst.afw.image.exposure.exposure.ExposureF`, ..., | ||
`~lsst.afw.image.exposure.exposure.ExposureF`)] | ||
Dictionary that groups flat-field exposures that have the same | ||
exposure time (seconds). | ||
|
||
inputDims : `list` | ||
List of exposure IDs. | ||
""" | ||
# inputExp.values() returns a view, which we turn into a list. We then | ||
# access the first exposure to get teh detector. | ||
detector = list(inputExp.values())[0][0].getDetector() | ||
# access the first exposure-ID tuple to get the detector. | ||
detector = list(inputExp.values())[0][0][0].getDetector() | ||
detNum = detector.getId() | ||
amps = detector.getAmplifiers() | ||
ampNames = [amp.getName() for amp in amps] | ||
|
@@ -271,23 +273,23 @@ def run(self, inputExp, inputDims): | |
exposures = inputExp[expTime] | ||
if len(exposures) == 1: | ||
self.log.warn(f"Only one exposure found at expTime {expTime}. Dropping exposure " | ||
f"{exposures[0].getInfo().getVisitInfo().getExposureId()}.") | ||
f"{exposures[0][1]}") | ||
continue | ||
else: | ||
# Only use the first two exposures at expTime | ||
exp1, exp2 = exposures[0], exposures[1] | ||
# Only use the first two exposures at expTime. Each elements is a tuple (exposure, expId) | ||
exp1, expId1 = exposures[0] | ||
exp2, expId2 = exposures[1] | ||
if len(exposures) > 2: | ||
self.log.warn(f"Already found 2 exposures at expTime {expTime}. " | ||
"Ignoring exposures: " | ||
f"{i.getInfo().getVisitInfo().getExposureId() for i in exposures[2:]}") | ||
f"{i[1] for i in exposures[2:]}") | ||
# Mask pixels at the edge of the detector or of each amp | ||
if self.config.numEdgeSuspect > 0: | ||
isrTask.maskEdges(exp1, numEdgePixels=self.config.numEdgeSuspect, | ||
maskPlane="SUSPECT", level=self.config.edgeMaskLevel) | ||
isrTask.maskEdges(exp2, numEdgePixels=self.config.numEdgeSuspect, | ||
maskPlane="SUSPECT", level=self.config.edgeMaskLevel) | ||
expId1 = exp1.getInfo().getVisitInfo().getExposureId() | ||
expId2 = exp2.getInfo().getVisitInfo().getExposureId() | ||
|
||
nAmpsNan = 0 | ||
partialPtcDataset = PhotonTransferCurveDataset(ampNames, '', | ||
self.config.maximumRangeCovariancesAstier) | ||
|
@@ -343,22 +345,12 @@ def run(self, inputExp, inputDims): | |
expIdMask=[expIdMask], covArray=covArray, | ||
covSqrtWeights=covSqrtWeights) | ||
# Use location of exp1 to save PTC dataset from (exp1, exp2) pair. | ||
# expId1 and expId2, as returned by getInfo().getVisitInfo().getExposureId(), | ||
# and the exposure IDs stured in inoutDims, | ||
# may have the zero-padded detector number appended at | ||
# the end (in gen3). A temporary fix is to consider expId//1000 and/or | ||
# inputDims//1000. | ||
# Below, np.where(expId1 == np.array(inputDims)) (and the other analogous | ||
# comparisons) returns a tuple with a single-element array, so [0][0] | ||
# Below, np.where(expId1 == np.array(inputDims)) returns a tuple | ||
# with a single-element array, so [0][0] | ||
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. This logic would also be replaced by simply pulling the exposure values at the same time as the exposures in the loop above. |
||
# is necessary to extract the required index. | ||
try: | ||
datasetIndex = np.where(expId1 == np.array(inputDims))[0][0] | ||
except IndexError: | ||
try: | ||
datasetIndex = np.where(expId1//1000 == np.array(inputDims))[0][0] | ||
except IndexError: | ||
datasetIndex = np.where(expId1//1000 == np.array(inputDims)//1000)[0][0] | ||
datasetIndex = np.where(expId1 == np.array(inputDims))[0][0] | ||
partialPtcDatasetList[datasetIndex] = partialPtcDataset | ||
|
||
if nAmpsNan == len(ampNames): | ||
msg = f"NaN mean in all amps of exposure pair {expId1}, {expId2} of detector {detNum}." | ||
self.log.warn(msg) | ||
|
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.
This switch seems unnecessary now.