22 from astropy.time
import Time
26 from lsst.daf.butler
import DatasetType
30 """Create a way to bless existing calibration products.
32 The inputs are assumed to have been constructed via cp_pipe, and
33 already exist in the butler.
37 butler : `lsst.daf.butler.Butler`
38 Butler repository to use.
39 inputCollection : `str`
40 Data collection to pull calibrations from.
41 outputCollection : `str`
42 Data collection to store final calibrations.
44 Additional arguments forwarded to `lsst.pipe.base.Task.__init__`.
46 _DefaultName =
'CertifyCalibration'
47 ConfigClass = pexConfig.Config
49 def __init__(self, *, butler, inputCollection, outputCollection,
60 def findInputs(self, datasetTypeName, inputDatasetTypeName=None):
61 """Find and prepare inputs for blessing.
65 datasetTypeName : `str`
66 Dataset that will be blessed.
67 inputDatasetTypeName : `str`, optional
68 Dataset name for the input datasets. Default to
69 datasetTypeName + "Proposal".
74 Raised if no input datasets found or if the calibration
75 label exists and is not empty.
77 if inputDatasetTypeName
is None:
78 inputDatasetTypeName = datasetTypeName +
"Proposal"
87 raise RuntimeError(f
"No inputs found for dataset {inputDatasetTypeName} "
88 f
"in {self.inputCollection}")
100 """Add blessed inputs to the output collection.
104 datasetTypeName : `str`
105 Dataset type these calibrations will be registered for.
110 self.
butler.collection =
None
114 except Exception
as e:
115 print(f
"Could not registerDatasetType {datasetTypeName}. Failure {e}?")
117 with self.
butler.transaction():
119 self.
butler.put(data, datasetTypeName, dataId=newId,
124 """Ensure registry can handle this dataset type.
128 datasetTypeName : `str`
129 Name of the dataset that will be registered.
130 dataId : `lsst.daf.butler.dataId`
131 Data ID providing the list of dimensions for the new
134 storageClassMap = {
'crosstalk':
'CrosstalkCalib'}
135 storageClass = storageClassMap.get(datasetTypeName,
'ExposureF')
137 dimensionArray = set(list(dataId.keys()) + [
"calibration_label"])
138 datasetType = DatasetType(datasetTypeName,
141 universe=self.
butler.registry.dimensions)
142 self.
butler.registry.registerDatasetType(datasetType)
145 beginDate="1970-01-01", endDate="2038-12-31"):
147 """Method to allow tasks to add calibration_label for master calibrations.
151 name : `str`, optional
152 A unique string for the calibration_label key.
153 instrument : `str`, optional
154 Instrument this calibration is for.
155 beginDate : `str`, optional
156 An ISO 8601 date string for the beginning of the valid date range.
157 endDate : `str`, optional
158 An ISO 8601 date string for the end of the valid date range.
163 Raised if the instrument or calibration_label name are not set.
167 if instrument
is None:
169 if name
is None and instrument
is None:
170 raise RuntimeError(
"Instrument and calibration_label name not set.")
173 existingValues = self.
registry.queryDataIds([
'calibration_label'],
175 calibration_label=name)
176 existingValues = [a
for a
in existingValues]
177 print(f
"Found {len(existingValues)} Entries for {self.calibrationLabel}")
179 self.
butler.registry.insertDimensionData(
183 "instrument": instrument,
184 "datetime_begin": Time(datetime.datetime.fromisoformat(beginDate), scale=
'utc'),
185 "datetime_end": Time(datetime.datetime.fromisoformat(endDate), scale=
'utc'),