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