Skip to content

Commit

Permalink
Add PTC to linearity and BFK header provenance
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Broughton committed Feb 5, 2024
1 parent 6acd924 commit ce3a1cf
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
24 changes: 23 additions & 1 deletion python/lsst/cp/pipe/linearity.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
from lsstDebug import getDebugFrame
from lsst.ip.isr import (Linearizer, IsrProvenance)

from .utils import funcPolynomial, irlsFit, AstierSplineLinearityFitter
from .utils import (funcPolynomial, irlsFit, AstierSplineLinearityFitter,
extractCalibDate)


def ptcLookup(datasetType, registry, quantumDataId, collections):
Expand Down Expand Up @@ -265,7 +266,28 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
# Use the dimensions to set calib/provenance information.
inputs['inputDims'] = dict(inputRefs.inputPtc.dataId.required)

# Add calibration provenance info to header.
kwargs = dict()
reference = getattr(inputRefs, "inputPtc", None)

if reference is not None and hasattr(reference, "run"):
runKey = "PTC_RUN"
runValue = reference.run
idKey = "PTC_UUID"
idValue = str(reference.id)
dateKey = "PTC_DATE"
calib = inputs.get("inputPtc", None)
dateValue = extractCalibDate(calib)

kwargs[runKey] = runValue
kwargs[idKey] = idValue
kwargs[dateKey] = dateValue

self.log.info("Using " + str(reference.run))

outputs = self.run(**inputs)
outputs.outputLinearizer.updateMetadata(setDate=False, **kwargs)

butlerQC.put(outputs, outputRefs)

def run(self, inputPtc, dummy, camera, inputDims,
Expand Down
23 changes: 22 additions & 1 deletion python/lsst/cp/pipe/makeBrighterFatterKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import lsst.pipe.base.connectionTypes as cT

from lsst.ip.isr import (BrighterFatterKernel)
from .utils import (funcPolynomial, irlsFit)
from .utils import (funcPolynomial, irlsFit, extractCalibDate)


class BrighterFatterKernelSolveConnections(pipeBase.PipelineTaskConnections,
Expand Down Expand Up @@ -175,7 +175,28 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
# Use the dimensions to set calib/provenance information.
inputs['inputDims'] = dict(inputRefs.inputPtc.dataId.required)

# Add calibration provenance info to header.
kwargs = dict()
reference = getattr(inputRefs, "inputPtc", None)

if reference is not None and hasattr(reference, "run"):
runKey = "PTC_RUN"
runValue = reference.run
idKey = "PTC_UUID"
idValue = str(reference.id)
dateKey = "PTC_DATE"
calib = inputs.get("inputPtc", None)
dateValue = extractCalibDate(calib)

kwargs[runKey] = runValue
kwargs[idKey] = idValue
kwargs[dateKey] = dateValue

self.log.info("Using " + str(reference.run))

outputs = self.run(**inputs)
outputs.outputBFK.updateMetadata(setDate=False, **kwargs)

butlerQC.put(outputs, outputRefs)

def run(self, inputPtc, dummy, camera, inputDims):
Expand Down
25 changes: 25 additions & 0 deletions python/lsst/cp/pipe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,31 @@ def arrangeFlatsByExpId(exposureList, exposureIdList):
return flatsAtExpId


def extractCalibDate(calib):
"""Extract common calibration metadata values that will be written to
output header.
Parameters
----------
calib : `lsst.afw.image.Exposure` or `lsst.ip.isr.IsrCalib`
Calibration to pull date information from.
Returns
-------
dateString : `str`
Calibration creation date string to add to header.
"""
if hasattr(calib, "getMetadata"):
if 'CALIB_CREATION_DATE' in calib.getMetadata():
return " ".join((calib.getMetadata().get("CALIB_CREATION_DATE", "Unknown"),
calib.getMetadata().get("CALIB_CREATION_TIME", "Unknown")))
else:
return " ".join((calib.getMetadata().get("CALIB_CREATE_DATE", "Unknown"),
calib.getMetadata().get("CALIB_CREATE_TIME", "Unknown")))
else:
return "Unknown Unknown"


class CovFastFourierTransform:
"""A class to compute (via FFT) the nearby pixels correlation function.
Expand Down

0 comments on commit ce3a1cf

Please sign in to comment.