216 def run(self, inputExps, inputScales=None, inputDims=None):
217 """Combine calib exposures for a single detector.
221 inputExps : `list` [`lsst.afw.image.Exposure`]
222 Input list of exposures to combine.
223 inputScales : `dict` [`dict` [`dict` [`float`]]], optional
224 Dictionary of scales, indexed by detector (`int`),
225 amplifier (`int`), and exposure (`int`). Used for
227 inputDims : `list` [`dict`]
228 List of dictionaries of input data dimensions/values.
229 Each list entry should contain:
232 exposure id value (`int`)
234 detector id value (`int`)
238 combinedExp : `lsst.afw.image.Exposure`
239 Final combined exposure generated from the inputs.
244 Raised if no input data is found. Also raised if
245 config.exposureScaling == InputList, and a necessary scale
248 width, height = self.getDimensions(inputExps)
250 afwImage.Mask.getPlaneBitMask(self.config.mask))
251 numExps = len(inputExps)
253 raise RuntimeError(
"No valid input data")
254 if numExps < self.config.maxVisitsToCalcErrorFromInputVariance:
255 stats.setCalcErrorFromInputVariance(
True)
259 detectorList = [exp.getDetector()
for exp
in inputExps]
260 if None in detectorList:
261 self.log.
warn(
"Not all input detectors defined.")
262 detectorIds = [det.getId()
if det
is not None else None for det
in detectorList]
263 detectorSerials = [det.getId()
if det
is not None else None for det
in detectorList]
264 numDetectorIds = len(
set(detectorIds))
265 numDetectorSerials = len(
set(detectorSerials))
266 numDetectors = len(
set([numDetectorIds, numDetectorSerials]))
267 if numDetectors != 1:
268 raise RuntimeError(
"Input data contains multiple detectors.")
270 inputDetector = inputExps[0].getDetector()
273 combined = afwImage.MaskedImageF(width, height)
278 if inputDims
is None:
279 inputDims = [dict()
for i
in inputExps]
281 for index, (exp, dims)
in enumerate(zip(inputExps, inputDims)):
284 self.log.
warn(
"Input %d is None (%s); unable to scale exp.", index, dims)
287 if self.config.exposureScaling ==
"ExposureTime":
288 scale = exp.getInfo().getVisitInfo().getExposureTime()
289 elif self.config.exposureScaling ==
"DarkTime":
290 scale = exp.getInfo().getVisitInfo().getDarkTime()
291 elif self.config.exposureScaling ==
"MeanStats":
292 scale = self.stats.
run(exp)
293 elif self.config.exposureScaling ==
"InputList":
294 visitId = dims.get(
'exposure',
None)
295 detectorId = dims.get(
'detector',
None)
296 if visitId
is None or detectorId
is None:
297 raise RuntimeError(f
"Could not identify scaling for input {index} ({dims})")
298 if detectorId
not in inputScales[
'expScale']:
299 raise RuntimeError(f
"Could not identify a scaling for input {index}"
300 f
" detector {detectorId}")
302 if self.config.scalingLevel ==
"DETECTOR":
303 if visitId
not in inputScales[
'expScale'][detectorId]:
304 raise RuntimeError(f
"Could not identify a scaling for input {index}"
305 f
"detector {detectorId} visit {visitId}")
306 scale = inputScales[
'expScale'][detectorId][visitId]
307 elif self.config.scalingLevel ==
'AMP':
308 scale = [inputScales[
'expScale'][detectorId][amp.getName()][visitId]
309 for amp
in exp.getDetector()]
311 raise RuntimeError(f
"Unknown scaling level: {self.config.scalingLevel}")
312 elif self.config.exposureScaling ==
'Unity':
315 raise RuntimeError(f
"Unknown scaling type: {self.config.exposureScaling}.")
317 expScales.append(scale)
318 self.log.
info(
"Scaling input %d by %s", index, scale)
319 self.applyScale(exp, scale)
321 self.combine(combined, inputExps, stats)
323 self.interpolateNans(combined)
325 if self.config.doVignette:
326 polygon = inputExps[0].
getInfo().getValidPolygon()
328 doSetValue=
True, vignetteValue=0.0)
331 self.combineHeaders(inputExps, combinedExp,
332 calibType=self.config.calibrationType, scales=expScales)
335 combinedExp.setDetector(inputDetector)
338 return pipeBase.Struct(
339 outputData=combinedExp,
Pass parameters to a Statistics object.
std::shared_ptr< Exposure< ImagePixelT, MaskPixelT, VariancePixelT > > makeExposure(MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage, std::shared_ptr< geom::SkyWcs const > wcs=std::shared_ptr< geom::SkyWcs const >())
A function to return an Exposure of the correct type (cf.
def VignetteExposure(exposure, polygon=None, doUpdateMask=True, maskPlane="NO_DATA", doSetValue=False, vignetteValue=0.0, log=None)
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)