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-35316: Add 'detector' information (and any other missing info) to PTC dataset metadata #139

Merged
merged 5 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions python/lsst/cp/pipe/ptc/cpExtractPtcTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ def run(self, inputExp, inputDims, taskMetadata):
# and assemble the measurements in the datasets
# in an addecuate manner for fitting a PTC
# model.
partialPtcDataset.updateMetadata(setDate=True, detector=detector)
partialPtcDatasetList[datasetIndex] = partialPtcDataset

if nAmpsNan == len(ampNames):
Expand Down
23 changes: 13 additions & 10 deletions python/lsst/cp/pipe/ptc/cpSolvePtcTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
Output data refs to persist.
"""
inputs = butlerQC.get(inputRefs)
outputs = self.run(inputCovariances=inputs['inputCovariances'], camera=inputs['camera'])
detId = inputRefs.inputCovariances[0].dataId['detector']
outputs = self.run(inputCovariances=inputs['inputCovariances'], camera=inputs['camera'], detId=detId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this need to pass inputExpList? It didn't previously it seems, but doesn't that mean that it's always None?

Copy link
Contributor

Choose a reason for hiding this comment

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

Was it only being used to find a detector before, and now that's being handled by the dimension information in runQuantum, so it isn't needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it was used before (except for that one check, but then it was always None), so I removed it.

butlerQC.put(outputs, outputRefs)

def run(self, inputCovariances, camera=None, inputExpList=None):
def run(self, inputCovariances, camera=None, detId=0):
"""Fit measured covariances to different models.

Parameters
Expand All @@ -199,9 +200,10 @@ def run(self, inputCovariances, camera=None, inputExpList=None):
List of lsst.ip.isr.PhotonTransferCurveDataset datasets.
camera : `lsst.afw.cameraGeom.Camera`, optional
Input camera.
inputExpList : `list` [`~lsst.afw.image.ExposureF`], optional
List of exposures.

detId : `int`
Detector ID to locate the detector in the camera and
populate the `lsst.ip.isr.PhotonTransferCurveDataset`
metadata.
Returns
-------
results : `lsst.pipe.base.Struct`
Expand All @@ -213,8 +215,9 @@ def run(self, inputCovariances, camera=None, inputExpList=None):
"""
# Assemble individual PTC datasets into a single PTC dataset.
ampNames = np.unique(inputCovariances[0].ampNames)
datasetPtc = PhotonTransferCurveDataset(ampNames, self.config.ptcFitType,
self.config.maximumRangeCovariancesAstier)
datasetPtc = PhotonTransferCurveDataset(ampNames=ampNames,
ptcFitType=self.config.ptcFitType,
covMatrixSide=self.config.maximumRangeCovariancesAstier)
for partialPtcDataset in inputCovariances:
# Ignore dummy datasets
if partialPtcDataset.ptcFitType == 'DUMMY':
Expand Down Expand Up @@ -281,9 +284,9 @@ def run(self, inputCovariances, camera=None, inputExpList=None):
# approximation (Eq. 16). Fill up
# PhotonTransferCurveDataset object.
datasetPtc = self.fitMeasurementsToModel(datasetPtc)
if inputExpList is not None:
# It should be a list of exposures, to get the detector.
detector = inputExpList[0].getDetector()

if camera:
detector = camera[detId]
else:
detector = None
datasetPtc.updateMetadata(setDate=True, camera=camera, detector=detector)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ptc.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def test_covAstier(self):

resultsExtract = extractTask.run(inputExp=expDict, inputDims=expIds,
taskMetadata=[self.metadataContents])
resultsSolve = solveTask.run(resultsExtract.outputCovariances)
resultsSolve = solveTask.run(resultsExtract.outputCovariances,
camera=FakeCamera([self.flatExp1.getDetector()]))

for amp in self.ampNames:
self.assertAlmostEqual(resultsSolve.outputPtcDataset.gain[amp], inputGain, places=2)
Expand Down