274 def runPlugins(self, noiseReplacer, measCat, exposure, beginOrder=None, endOrder=None):
275 r"""Call the configured measument plugins on an image.
276
277 Parameters
278 ----------
279 noiseReplacer : `NoiseReplacer`
280 Used to fill sources not being measured with noise.
281 measCat : `lsst.afw.table.SourceCatalog`
282 Catalog to be filled with the results of measurement. Must contain
283 all the `lsst.afw.table.SourceRecord`\ s to be measured (with
284 `lsst.afw.detection.Footprint`\ s attached), and have a schema
285 that is a superset of ``self.schema``.
286 exposure : `lsst.afw.image.ExposureF`
287 Image containing the pixel data to be measured together with
288 associated PSF, WCS, etc.
289 beginOrder : `float`, optional
290 Start execution order (inclusive): measurements with
291 ``executionOrder < beginOrder`` are not executed. `None` for no
292 limit.
293 endOrder : `float`, optional
294 Final execution order (exclusive): measurements with
295 ``executionOrder >= endOrder`` are not executed. `None` for no
296 limit.
297 """
298
299
300 measParentCat = measCat.getChildren(0)
301
302 nMeasCat = len(measCat)
303 nMeasParentCat = len(measParentCat)
304 self.log.info("Measuring %d source%s (%d parent%s, %d child%s) ",
305 nMeasCat, ("" if nMeasCat == 1 else "s"),
306 nMeasParentCat, ("" if nMeasParentCat == 1 else "s"),
307 nMeasCat - nMeasParentCat, ("" if nMeasCat - nMeasParentCat == 1 else "ren"))
308
309
310 periodicLog = PeriodicLogger(self.log)
311
312 childrenIter = measCat.getChildren([measParentRecord.getId() for measParentRecord in measParentCat])
313 for parentIdx, (measParentRecord, measChildCat) in enumerate(zip(measParentCat, childrenIter)):
314
315
316
317
318 for measChildRecord in measChildCat:
319 noiseReplacer.insertSource(measChildRecord.getId())
320 self.callMeasure(measChildRecord, exposure, beginOrder=beginOrder, endOrder=endOrder)
321
322 if self.doBlendedness:
323 self.blendPlugin.cpp.measureChildPixels(exposure.getMaskedImage(), measChildRecord)
324
325 noiseReplacer.removeSource(measChildRecord.getId())
326
327
328 noiseReplacer.insertSource(measParentRecord.getId())
329 self.callMeasure(measParentRecord, exposure, beginOrder=beginOrder, endOrder=endOrder)
330
331 if self.doBlendedness:
332 self.blendPlugin.cpp.measureChildPixels(exposure.getMaskedImage(), measParentRecord)
333
334
335 self.callMeasureN(measParentCat[parentIdx:parentIdx+1], exposure,
336 beginOrder=beginOrder, endOrder=endOrder)
337 self.callMeasureN(measChildCat, exposure, beginOrder=beginOrder, endOrder=endOrder)
338 noiseReplacer.removeSource(measParentRecord.getId())
339
340 periodicLog.log("Measurement complete for %d parents (and their children) out of %d",
341 parentIdx + 1, nMeasParentCat)
342
343
344 noiseReplacer.end()
345
346
347 if endOrder is None:
348 for sourceIndex, source in enumerate(measCat):
349 for plugin in self.undeblendedPlugins.iter():
350 self.doMeasurement(plugin, source, exposure)
351
352 periodicLog.log("Undeblended measurement complete for %d sources out of %d",
353 sourceIndex + 1, nMeasCat)
354
355
356
357 if self.doBlendedness:
358 for source in measCat:
359 self.blendPlugin.cpp.measureParentPixels(exposure.getMaskedImage(), source)
360