220 r"""Run single frame measurement over an exposure and source catalog.
224 measCat : `lsst.afw.table.SourceCatalog`
225 Catalog to be filled with the results of measurement. Must contain
226 all the `lsst.afw.table.SourceRecord`\ s to be measured (with
227 `lsst.afw.detection.Footprint`\ s attached), and have a schema
228 that is a superset of ``self.schema``.
229 exposure : `lsst.afw.image.ExposureF`
230 Image containing the pixel data to be measured together with
231 associated PSF, WCS, etc.
232 noiseImage : `lsst.afw.image.ImageF`, optional
233 Can be used to specify the a predictable noise replacement field
234 for testing purposes.
235 exposureId : `int`, optional
236 Unique exposure identifier used to calculate the random number
237 generator seed during noise replacement.
238 beginOrder : `float`, optional
239 Start execution order (inclusive): measurements with
240 ``executionOrder < beginOrder`` are not executed. `None` for no
242 endOrder : `float`, optional
243 Final execution order (exclusive): measurements with
244 ``executionOrder >= endOrder`` are not executed. `None` for no
246 footprints : `dict` {`int`: `lsst.afw.detection.Footprint`}, optional
247 List of footprints to use for noise replacement. If this is not
248 supplied then the footprints from the measCat are used.
250 assert measCat.getSchema().contains(self.
schema)
251 if footprints
is None:
260 if self.config.doReplaceWithNoise:
261 noiseReplacer =
NoiseReplacer(self.config.noiseReplacer, exposure, footprints,
262 noiseImage=noiseImage, log=self.log, exposureId=exposureId)
263 algMetadata = measCat.getMetadata()
264 if algMetadata
is not None:
266 algMetadata.addString(self.
NOISE_SOURCE, self.config.noiseReplacer.noiseSource)
267 algMetadata.addDouble(self.
NOISE_OFFSET, self.config.noiseReplacer.noiseOffset)
268 if exposureId
is not None:
273 self.
runPlugins(noiseReplacer, measCat, exposure, beginOrder, endOrder)
275 def runPlugins(self, noiseReplacer, measCat, exposure, beginOrder=None, endOrder=None):
276 r"""Call the configured measument plugins on an image.
280 noiseReplacer : `NoiseReplacer`
281 Used to fill sources not being measured with noise.
282 measCat : `lsst.afw.table.SourceCatalog`
283 Catalog to be filled with the results of measurement. Must contain
284 all the `lsst.afw.table.SourceRecord`\ s to be measured (with
285 `lsst.afw.detection.Footprint`\ s attached), and have a schema
286 that is a superset of ``self.schema``.
287 exposure : `lsst.afw.image.ExposureF`
288 Image containing the pixel data to be measured together with
289 associated PSF, WCS, etc.
290 beginOrder : `float`, optional
291 Start execution order (inclusive): measurements with
292 ``executionOrder < beginOrder`` are not executed. `None` for no
294 endOrder : `float`, optional
295 Final execution order (exclusive): measurements with
296 ``executionOrder >= endOrder`` are not executed. `None` for no
301 measParentCat = measCat.getChildren(0)
303 nMeasCat = len(measCat)
304 nMeasParentCat = len(measParentCat)
305 self.log.info(
"Measuring %d source%s (%d parent%s, %d child%s) ",
306 nMeasCat, (
"" if nMeasCat == 1
else "s"),
307 nMeasParentCat, (
"" if nMeasParentCat == 1
else "s"),
308 nMeasCat - nMeasParentCat, (
"" if nMeasCat - nMeasParentCat == 1
else "ren"))
311 periodicLog = PeriodicLogger(self.log)
313 childrenIter = measCat.getChildren([measParentRecord.getId()
for measParentRecord
in measParentCat])
314 for parentIdx, (measParentRecord, measChildCat)
in enumerate(zip(measParentCat, childrenIter)):
319 for measChildRecord
in measChildCat:
320 noiseReplacer.insertSource(measChildRecord.getId())
321 self.
callMeasure(measChildRecord, exposure, beginOrder=beginOrder, endOrder=endOrder)
324 self.
blendPlugin.cpp.measureChildPixels(exposure.getMaskedImage(), measChildRecord)
326 noiseReplacer.removeSource(measChildRecord.getId())
329 noiseReplacer.insertSource(measParentRecord.getId())
330 self.
callMeasure(measParentRecord, exposure, beginOrder=beginOrder, endOrder=endOrder)
333 self.
blendPlugin.cpp.measureChildPixels(exposure.getMaskedImage(), measParentRecord)
336 self.
callMeasureN(measParentCat[parentIdx:parentIdx+1], exposure,
337 beginOrder=beginOrder, endOrder=endOrder)
338 self.
callMeasureN(measChildCat, exposure, beginOrder=beginOrder, endOrder=endOrder)
339 noiseReplacer.removeSource(measParentRecord.getId())
341 periodicLog.log(
"Measurement complete for %d parents (and their children) out of %d",
342 parentIdx + 1, nMeasParentCat)
349 for sourceIndex, source
in enumerate(measCat):
353 periodicLog.log(
"Undeblended measurement complete for %d sources out of %d",
354 sourceIndex + 1, nMeasCat)
359 for source
in measCat:
360 self.
blendPlugin.cpp.measureParentPixels(exposure.getMaskedImage(), source)