219 r"""Run single frame measurement over an exposure and source catalog.
223 measCat : `lsst.afw.table.SourceCatalog`
224 Catalog to be filled with the results of measurement. Must contain
225 all the `lsst.afw.table.SourceRecord`\ s to be measured (with
226 `lsst.afw.detection.Footprint`\ s attached), and have a schema
227 that is a superset of ``self.schema``.
228 exposure : `lsst.afw.image.ExposureF`
229 Image containing the pixel data to be measured together with
230 associated PSF, WCS, etc.
231 noiseImage : `lsst.afw.image.ImageF`, optional
232 Can be used to specify the a predictable noise replacement field
233 for testing purposes.
234 exposureId : `int`, optional
235 Unique exposure identifier used to calculate the random number
236 generator seed during noise replacement.
237 beginOrder : `float`, optional
238 Start execution order (inclusive): measurements with
239 ``executionOrder < beginOrder`` are not executed. `None` for no
241 endOrder : `float`, optional
242 Final execution order (exclusive): measurements with
243 ``executionOrder >= endOrder`` are not executed. `None` for no
245 footprints : `dict` {`int`: `lsst.afw.detection.Footprint`}, optional
246 List of footprints to use for noise replacement. If this is not
247 supplied then the footprints from the measCat are used.
249 assert measCat.getSchema().contains(self.
schema)
250 if footprints
is None:
259 if self.config.doReplaceWithNoise:
260 noiseReplacer =
NoiseReplacer(self.config.noiseReplacer, exposure, footprints,
261 noiseImage=noiseImage, log=self.log, exposureId=exposureId)
262 algMetadata = measCat.getMetadata()
263 if algMetadata
is not None:
267 if exposureId
is not None:
272 self.
runPlugins(noiseReplacer, measCat, exposure, beginOrder, endOrder)
274 def runPlugins(self, noiseReplacer, measCat, exposure, beginOrder=None, endOrder=None):
275 r"""Call the configured measument plugins on an image.
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
293 endOrder : `float`, optional
294 Final execution order (exclusive): measurements with
295 ``executionOrder >= endOrder`` are not executed. `None` for no
300 measParentCat = measCat.getChildren(0)
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"))
310 periodicLog = PeriodicLogger(self.log)
312 childrenIter = measCat.getChildren([measParentRecord.getId()
for measParentRecord
in measParentCat])
313 for parentIdx, (measParentRecord, measChildCat)
in enumerate(
zip(measParentCat, childrenIter)):
318 for measChildRecord
in measChildCat:
319 noiseReplacer.insertSource(measChildRecord.getId())
320 self.
callMeasure(measChildRecord, exposure, beginOrder=beginOrder, endOrder=endOrder)
323 self.
blendPlugin.cpp.measureChildPixels(exposure.getMaskedImage(), measChildRecord)
325 noiseReplacer.removeSource(measChildRecord.getId())
328 noiseReplacer.insertSource(measParentRecord.getId())
329 self.
callMeasure(measParentRecord, exposure, beginOrder=beginOrder, endOrder=endOrder)
332 self.
blendPlugin.cpp.measureChildPixels(exposure.getMaskedImage(), measParentRecord)
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())
340 periodicLog.log(
"Measurement complete for %d parents (and their children) out of %d",
341 parentIdx + 1, nMeasParentCat)
348 for sourceIndex, source
in enumerate(measCat):
352 periodicLog.log(
"Undeblended measurement complete for %d sources out of %d",
353 sourceIndex + 1, nMeasCat)
358 for source
in measCat:
359 self.
blendPlugin.cpp.measureParentPixels(exposure.getMaskedImage(), source)