28from lsst.ip.diffim.utils
import evaluateMaskFraction
29from lsst.meas.algorithms import SkyObjectsTask, SourceDetectionTask, SetPrimaryFlagsTask, MaskStreaksTask
30from lsst.meas.base import ForcedMeasurementTask, ApplyApCorrTask, DetectorVisitIdGeneratorConfig
33import lsst.meas.extensions.shapeHSM
38from lsst.utils.timer
import timeMethod
40from .
import DipoleFitTask
42__all__ = [
"DetectAndMeasureConfig",
"DetectAndMeasureTask",
43 "DetectAndMeasureScoreConfig",
"DetectAndMeasureScoreTask"]
47 dimensions=(
"instrument",
"visit",
"detector"),
48 defaultTemplates={
"coaddName":
"deep",
51 science = pipeBase.connectionTypes.Input(
52 doc=
"Input science exposure.",
53 dimensions=(
"instrument",
"visit",
"detector"),
54 storageClass=
"ExposureF",
55 name=
"{fakesType}calexp"
57 matchedTemplate = pipeBase.connectionTypes.Input(
58 doc=
"Warped and PSF-matched template used to create the difference image.",
59 dimensions=(
"instrument",
"visit",
"detector"),
60 storageClass=
"ExposureF",
61 name=
"{fakesType}{coaddName}Diff_matchedExp",
63 difference = pipeBase.connectionTypes.Input(
64 doc=
"Result of subtracting template from science.",
65 dimensions=(
"instrument",
"visit",
"detector"),
66 storageClass=
"ExposureF",
67 name=
"{fakesType}{coaddName}Diff_differenceTempExp",
69 outputSchema = pipeBase.connectionTypes.InitOutput(
70 doc=
"Schema (as an example catalog) for output DIASource catalog.",
71 storageClass=
"SourceCatalog",
72 name=
"{fakesType}{coaddName}Diff_diaSrc_schema",
74 diaSources = pipeBase.connectionTypes.Output(
75 doc=
"Detected diaSources on the difference image.",
76 dimensions=(
"instrument",
"visit",
"detector"),
77 storageClass=
"SourceCatalog",
78 name=
"{fakesType}{coaddName}Diff_diaSrc",
80 subtractedMeasuredExposure = pipeBase.connectionTypes.Output(
81 doc=
"Difference image with detection mask plane filled in.",
82 dimensions=(
"instrument",
"visit",
"detector"),
83 storageClass=
"ExposureF",
84 name=
"{fakesType}{coaddName}Diff_differenceExp",
86 maskedStreaks = pipeBase.connectionTypes.Output(
87 doc=
'Catalog of streak fit parameters for the difference image.',
88 storageClass=
"ArrowNumpyDict",
89 dimensions=(
"instrument",
"visit",
"detector"),
90 name=
"{fakesType}{coaddName}Diff_streaks",
93 def __init__(self, *, config):
94 super().__init__(config=config)
95 if not (self.config.writeStreakInfo
and self.config.doMaskStreaks):
96 self.outputs.remove(
"maskedStreaks")
99class DetectAndMeasureConfig(pipeBase.PipelineTaskConfig,
100 pipelineConnections=DetectAndMeasureConnections):
101 """Config for DetectAndMeasureTask
103 doMerge = pexConfig.Field(
106 doc=
"Merge positive and negative diaSources with grow radius "
107 "set by growFootprint"
109 doForcedMeasurement = pexConfig.Field(
112 doc=
"Force photometer diaSource locations on PVI?")
113 doAddMetrics = pexConfig.Field(
116 doc=
"Add columns to the source table to hold analysis metrics?"
118 detection = pexConfig.ConfigurableField(
119 target=SourceDetectionTask,
120 doc=
"Final source detection for diaSource measurement",
122 deblend = pexConfig.ConfigurableField(
124 doc=
"Task to split blended sources into their components."
126 measurement = pexConfig.ConfigurableField(
127 target=DipoleFitTask,
128 doc=
"Task to measure sources on the difference image.",
133 doc=
"Run subtask to apply aperture corrections"
136 target=ApplyApCorrTask,
137 doc=
"Task to apply aperture corrections"
139 forcedMeasurement = pexConfig.ConfigurableField(
140 target=ForcedMeasurementTask,
141 doc=
"Task to force photometer science image at diaSource locations.",
143 growFootprint = pexConfig.Field(
146 doc=
"Grow positive and negative footprints by this many pixels before merging"
148 diaSourceMatchRadius = pexConfig.Field(
151 doc=
"Match radius (in arcseconds) for DiaSource to Source association"
153 doSkySources = pexConfig.Field(
156 doc=
"Generate sky sources?",
158 skySources = pexConfig.ConfigurableField(
159 target=SkyObjectsTask,
160 doc=
"Generate sky sources",
162 doMaskStreaks = pexConfig.Field(
165 doc=
"Turn on streak masking",
167 maskStreaks = pexConfig.ConfigurableField(
168 target=MaskStreaksTask,
169 doc=
"Subtask for masking streaks. Only used if doMaskStreaks is True. "
170 "Adds a mask plane to an exposure, with the mask plane name set by streakMaskName.",
172 writeStreakInfo = pexConfig.Field(
175 doc=
"Record the parameters of any detected streaks. For LSST, this should be turned off except for "
178 setPrimaryFlags = pexConfig.ConfigurableField(
179 target=SetPrimaryFlagsTask,
180 doc=
"Task to add isPrimary and deblending-related flags to the catalog."
184 doc=
"Sources with any of these flags set are removed before writing the output catalog.",
185 default=(
"base_PixelFlags_flag_offimage",
186 "base_PixelFlags_flag_interpolatedCenterAll",
187 "base_PixelFlags_flag_badCenterAll",
188 "base_PixelFlags_flag_edgeCenterAll",
189 "base_PixelFlags_flag_saturatedCenterAll",
192 idGenerator = DetectorVisitIdGeneratorConfig.make_field()
194 def setDefaults(self):
196 self.detection.thresholdPolarity =
"both"
197 self.detection.thresholdValue = 5.0
198 self.detection.reEstimateBackground =
False
199 self.detection.thresholdType =
"pixel_stdev"
200 self.detection.excludeMaskPlanes = [
"EDGE",
"SAT",
"BAD",
"INTRP"]
202 self.measurement.plugins.names |= [
"ext_trailedSources_Naive",
203 "base_LocalPhotoCalib",
205 "ext_shapeHSM_HsmSourceMoments",
206 "ext_shapeHSM_HsmPsfMoments",
208 self.measurement.slots.psfShape =
"ext_shapeHSM_HsmPsfMoments"
209 self.measurement.slots.shape =
"ext_shapeHSM_HsmSourceMoments"
210 self.measurement.plugins[
"base_SdssCentroid"].maxDistToPeak = 5.0
211 self.forcedMeasurement.plugins = [
"base_TransformedCentroid",
"base_PsfFlux"]
212 self.forcedMeasurement.copyColumns = {
213 "id":
"objectId",
"parent":
"parentObjectId",
"coord_ra":
"coord_ra",
"coord_dec":
"coord_dec"}
214 self.forcedMeasurement.slots.centroid =
"base_TransformedCentroid"
215 self.forcedMeasurement.slots.shape =
None
218 self.measurement.plugins[
"base_PixelFlags"].masksFpAnywhere = [
219 "STREAK",
"INJECTED",
"INJECTED_TEMPLATE"]
220 self.measurement.plugins[
"base_PixelFlags"].masksFpCenter = [
221 "STREAK",
"INJECTED",
"INJECTED_TEMPLATE"]
222 self.skySources.avoidMask = [
"DETECTED",
"DETECTED_NEGATIVE",
"BAD",
"NO_DATA",
"EDGE"]
225class DetectAndMeasureTask(lsst.pipe.base.PipelineTask):
226 """Detect and measure sources on a difference image.
228 ConfigClass = DetectAndMeasureConfig
229 _DefaultName =
"detectAndMeasure"
231 def __init__(self, **kwargs):
232 super().__init__(**kwargs)
233 self.schema = afwTable.SourceTable.makeMinimalSchema()
235 afwTable.CoordKey.addErrorFields(self.schema)
238 self.makeSubtask(
"detection", schema=self.schema)
239 self.makeSubtask(
"deblend", schema=self.schema)
240 self.makeSubtask(
"setPrimaryFlags", schema=self.schema, isSingleFrame=
True)
241 self.makeSubtask(
"measurement", schema=self.schema,
242 algMetadata=self.algMetadata)
243 if self.config.doApCorr:
244 self.makeSubtask(
"applyApCorr", schema=self.measurement.schema)
245 if self.config.doForcedMeasurement:
246 self.schema.addField(
247 "ip_diffim_forced_PsfFlux_instFlux",
"D",
248 "Forced PSF flux measured on the direct image.",
250 self.schema.addField(
251 "ip_diffim_forced_PsfFlux_instFluxErr",
"D",
252 "Forced PSF flux error measured on the direct image.",
254 self.schema.addField(
255 "ip_diffim_forced_PsfFlux_area",
"F",
256 "Forced PSF flux effective area of PSF.",
258 self.schema.addField(
259 "ip_diffim_forced_PsfFlux_flag",
"Flag",
260 "Forced PSF flux general failure flag.")
261 self.schema.addField(
262 "ip_diffim_forced_PsfFlux_flag_noGoodPixels",
"Flag",
263 "Forced PSF flux not enough non-rejected pixels in data to attempt the fit.")
264 self.schema.addField(
265 "ip_diffim_forced_PsfFlux_flag_edge",
"Flag",
266 "Forced PSF flux object was too close to the edge of the image to use the full PSF model.")
267 self.makeSubtask(
"forcedMeasurement", refSchema=self.schema)
269 self.schema.addField(
"refMatchId",
"L",
"unique id of reference catalog match")
270 self.schema.addField(
"srcMatchId",
"L",
"unique id of source match")
271 if self.config.doSkySources:
272 self.makeSubtask(
"skySources", schema=self.schema)
273 if self.config.doMaskStreaks:
274 self.makeSubtask(
"maskStreaks")
277 for flag
in self.config.badSourceFlags:
278 if flag
not in self.schema:
279 raise pipeBase.InvalidQuantumError(
"Field %s not in schema" % flag)
283 self.outputSchema.getTable().setMetadata(self.algMetadata)
285 def runQuantum(self, butlerQC: pipeBase.QuantumContext,
286 inputRefs: pipeBase.InputQuantizedConnection,
287 outputRefs: pipeBase.OutputQuantizedConnection):
288 inputs = butlerQC.get(inputRefs)
289 idGenerator = self.config.idGenerator.apply(butlerQC.quantum.dataId)
290 idFactory = idGenerator.make_table_id_factory()
291 outputs = self.run(**inputs, idFactory=idFactory)
292 butlerQC.put(outputs, outputRefs)
295 def run(self, science, matchedTemplate, difference,
297 """Detect and measure sources on a difference image.
299 The difference image will be convolved with a gaussian approximation of
300 the PSF to form a maximum likelihood image for detection.
301 Close positive and negative detections will optionally be merged into
303 Sky sources, or forced detections in background regions, will optionally
304 be added, and the configured measurement algorithm will be run on all
309 science : `lsst.afw.image.ExposureF`
310 Science exposure that the template was subtracted from.
311 matchedTemplate : `lsst.afw.image.ExposureF`
312 Warped and PSF-matched template that was used produce the
314 difference : `lsst.afw.image.ExposureF`
315 Result of subtracting template from the science image.
316 idFactory : `lsst.afw.table.IdFactory`, optional
317 Generator object used to assign ids to detected sources in the
318 difference image. Ids from this generator are not set until after
319 deblending and merging positive/negative peaks.
323 measurementResults : `lsst.pipe.base.Struct`
325 ``subtractedMeasuredExposure`` : `lsst.afw.image.ExposureF`
326 Subtracted exposure with detection mask applied.
327 ``diaSources`` : `lsst.afw.table.SourceCatalog`
328 The catalog of detected sources.
330 if idFactory
is None:
334 mask = difference.mask
335 clearMaskPlanes = [
"DETECTED",
"DETECTED_NEGATIVE",
"NOT_DEBLENDED",
"STREAK"]
336 for mp
in clearMaskPlanes:
337 if mp
not in mask.getMaskPlaneDict():
338 mask.addMaskPlane(mp)
339 mask &= ~mask.getPlaneBitMask(clearMaskPlanes)
344 table = afwTable.SourceTable.make(self.schema)
345 results = self.detection.run(
351 sources, positives, negatives = self._deblend(difference,
355 return self.processResults(science, matchedTemplate, difference, sources, idFactory,
356 positiveFootprints=positives,
357 negativeFootprints=negatives)
359 def processResults(self, science, matchedTemplate, difference, sources, idFactory,
360 positiveFootprints=None, negativeFootprints=None,):
361 """Measure and process the results of source detection.
365 science : `lsst.afw.image.ExposureF`
366 Science exposure that the template was subtracted from.
367 matchedTemplate : `lsst.afw.image.ExposureF`
368 Warped and PSF-matched template that was used produce the
370 difference : `lsst.afw.image.ExposureF`
371 Result of subtracting template from the science image.
372 sources : `lsst.afw.table.SourceCatalog`
373 Detected sources on the difference exposure.
374 idFactory : `lsst.afw.table.IdFactory`
375 Generator object used to assign ids to detected sources in the
377 positiveFootprints : `lsst.afw.detection.FootprintSet`, optional
378 Positive polarity footprints.
379 negativeFootprints : `lsst.afw.detection.FootprintSet`, optional
380 Negative polarity footprints.
384 measurementResults : `lsst.pipe.base.Struct`
386 ``subtractedMeasuredExposure`` : `lsst.afw.image.ExposureF`
387 Subtracted exposure with detection mask applied.
388 ``diaSources`` : `lsst.afw.table.SourceCatalog`
389 The catalog of detected sources.
391 self.metadata.add(
"nUnmergedDiaSources", len(sources))
392 if self.config.doMerge:
393 fpSet = positiveFootprints
394 fpSet.merge(negativeFootprints, self.config.growFootprint,
395 self.config.growFootprint,
False)
397 fpSet.makeSources(initialDiaSources)
398 self.log.info(
"Merging detections into %d sources", len(initialDiaSources))
400 initialDiaSources = sources
404 for source
in initialDiaSources:
407 initialDiaSources.getTable().setIdFactory(idFactory)
408 initialDiaSources.setMetadata(self.algMetadata)
410 self.metadata.add(
"nMergedDiaSources", len(initialDiaSources))
412 if self.config.doMaskStreaks:
413 streakInfo = self._runStreakMasking(difference.maskedImage)
415 if self.config.doSkySources:
416 self.addSkySources(initialDiaSources, difference.mask, difference.info.id)
418 if not initialDiaSources.isContiguous():
419 initialDiaSources = initialDiaSources.copy(deep=
True)
421 self.measureDiaSources(initialDiaSources, science, difference, matchedTemplate)
422 diaSources = self._removeBadSources(initialDiaSources)
424 if self.config.doForcedMeasurement:
425 self.measureForcedSources(diaSources, science, difference.getWcs())
427 self.calculateMetrics(difference)
429 measurementResults = pipeBase.Struct(
430 subtractedMeasuredExposure=difference,
431 diaSources=diaSources,
433 if self.config.doMaskStreaks
and self.config.writeStreakInfo:
434 measurementResults.mergeItems(streakInfo,
'maskedStreaks')
436 return measurementResults
438 def _deblend(self, difference, positiveFootprints, negativeFootprints):
439 """Deblend the positive and negative footprints and return a catalog
440 containing just the children, and the deblended footprints.
444 difference : `lsst.afw.image.Exposure`
445 Result of subtracting template from the science image.
446 positiveFootprints, negativeFootprints : `lsst.afw.detection.FootprintSet`
447 Positive and negative polarity footprints measured on
448 ``difference`` to be deblended separately.
452 sources : `lsst.afw.table.SourceCatalog`
453 Positive and negative deblended children.
454 positives, negatives : `lsst.afw.detection.FootprintSet`
455 Deblended positive and negative polarity footprints measured on
458 def makeFootprints(sources):
459 footprints = afwDetection.FootprintSet(difference.getBBox())
460 footprints.setFootprints([src.getFootprint()
for src
in sources])
464 """Deblend a positive or negative footprint set,
465 and return the deblended children.
468 footprints.makeSources(sources)
469 self.deblend.run(exposure=difference, sources=sources)
470 self.setPrimaryFlags.run(sources)
471 children = sources[
"detect_isDeblendedSource"] == 1
472 sources = sources[children].copy(deep=
True)
474 sources[
'parent'] = 0
475 return sources.copy(deep=
True)
477 positives =
deblend(positiveFootprints)
478 negatives =
deblend(negativeFootprints)
481 sources.reserve(len(positives) + len(negatives))
482 sources.extend(positives, deep=
True)
483 sources.extend(negatives, deep=
True)
484 return sources, makeFootprints(positives), makeFootprints(negatives)
486 def _removeBadSources(self, diaSources):
487 """Remove unphysical diaSources from the catalog.
491 diaSources : `lsst.afw.table.SourceCatalog`
492 The catalog of detected sources.
496 diaSources : `lsst.afw.table.SourceCatalog`
497 The updated catalog of detected sources, with any source that has a
498 flag in ``config.badSourceFlags`` set removed.
500 selector = np.ones(len(diaSources), dtype=bool)
501 for flag
in self.config.badSourceFlags:
502 flags = diaSources[flag]
503 nBad = np.count_nonzero(flags)
505 self.log.debug(
"Found %d unphysical sources with flag %s.", nBad, flag)
507 nBadTotal = np.count_nonzero(~selector)
508 self.metadata.add(
"nRemovedBadFlaggedSources", nBadTotal)
509 self.log.info(
"Removed %d unphysical sources.", nBadTotal)
510 return diaSources[selector].copy(deep=
True)
512 def addSkySources(self, diaSources, mask, seed,
514 """Add sources in empty regions of the difference image
515 for measuring the background.
519 diaSources : `lsst.afw.table.SourceCatalog`
520 The catalog of detected sources.
521 mask : `lsst.afw.image.Mask`
522 Mask plane for determining regions where Sky sources can be added.
524 Seed value to initialize the random number generator.
527 subtask = self.skySources
528 skySourceFootprints = subtask.run(mask=mask, seed=seed, catalog=diaSources)
529 self.metadata.add(f
"n_{subtask.getName()}", len(skySourceFootprints))
531 def measureDiaSources(self, diaSources, science, difference, matchedTemplate):
532 """Use (matched) template and science image to constrain dipole fitting.
536 diaSources : `lsst.afw.table.SourceCatalog`
537 The catalog of detected sources.
538 science : `lsst.afw.image.ExposureF`
539 Science exposure that the template was subtracted from.
540 difference : `lsst.afw.image.ExposureF`
541 Result of subtracting template from the science image.
542 matchedTemplate : `lsst.afw.image.ExposureF`
543 Warped and PSF-matched template that was used produce the
547 for mp
in self.config.measurement.plugins[
"base_PixelFlags"].masksFpAnywhere:
548 difference.mask.addMaskPlane(mp)
551 self.measurement.run(diaSources, difference, science, matchedTemplate)
552 if self.config.doApCorr:
553 apCorrMap = difference.getInfo().getApCorrMap()
554 if apCorrMap
is None:
555 self.log.warning(
"Difference image does not have valid aperture correction; skipping.")
557 self.applyApCorr.run(
562 def measureForcedSources(self, diaSources, science, wcs):
563 """Perform forced measurement of the diaSources on the science image.
567 diaSources : `lsst.afw.table.SourceCatalog`
568 The catalog of detected sources.
569 science : `lsst.afw.image.ExposureF`
570 Science exposure that the template was subtracted from.
571 wcs : `lsst.afw.geom.SkyWcs`
572 Coordinate system definition (wcs) for the exposure.
576 forcedSources = self.forcedMeasurement.generateMeasCat(science, diaSources, wcs)
577 self.forcedMeasurement.run(forcedSources, science, diaSources, wcs)
579 mapper.addMapping(forcedSources.schema.find(
"base_PsfFlux_instFlux")[0],
580 "ip_diffim_forced_PsfFlux_instFlux",
True)
581 mapper.addMapping(forcedSources.schema.find(
"base_PsfFlux_instFluxErr")[0],
582 "ip_diffim_forced_PsfFlux_instFluxErr",
True)
583 mapper.addMapping(forcedSources.schema.find(
"base_PsfFlux_area")[0],
584 "ip_diffim_forced_PsfFlux_area",
True)
585 mapper.addMapping(forcedSources.schema.find(
"base_PsfFlux_flag")[0],
586 "ip_diffim_forced_PsfFlux_flag",
True)
587 mapper.addMapping(forcedSources.schema.find(
"base_PsfFlux_flag_noGoodPixels")[0],
588 "ip_diffim_forced_PsfFlux_flag_noGoodPixels",
True)
589 mapper.addMapping(forcedSources.schema.find(
"base_PsfFlux_flag_edge")[0],
590 "ip_diffim_forced_PsfFlux_flag_edge",
True)
591 for diaSource, forcedSource
in zip(diaSources, forcedSources):
592 diaSource.assign(forcedSource, mapper)
594 def calculateMetrics(self, difference):
595 """Add difference image QA metrics to the Task metadata.
597 This may be used to produce corresponding metrics (see
598 lsst.analysis.tools.tasks.diffimTaskDetectorVisitMetricAnalysis).
602 difference : `lsst.afw.image.Exposure`
603 The target difference image to calculate metrics for.
605 mask = difference.mask
606 badPix = (mask.array & mask.getPlaneBitMask(self.config.detection.excludeMaskPlanes)) > 0
607 self.metadata.add(
"nGoodPixels", np.sum(~badPix))
608 self.metadata.add(
"nBadPixels", np.sum(badPix))
609 detPosPix = (mask.array & mask.getPlaneBitMask(
"DETECTED")) > 0
610 detNegPix = (mask.array & mask.getPlaneBitMask(
"DETECTED_NEGATIVE")) > 0
611 self.metadata.add(
"nPixelsDetectedPositive", np.sum(detPosPix))
612 self.metadata.add(
"nPixelsDetectedNegative", np.sum(detNegPix))
615 self.metadata.add(
"nBadPixelsDetectedPositive", np.sum(detPosPix))
616 self.metadata.add(
"nBadPixelsDetectedNegative", np.sum(detNegPix))
618 metricsMaskPlanes = list(mask.getMaskPlaneDict().keys())
619 for maskPlane
in metricsMaskPlanes:
621 self.metadata.add(
"%s_mask_fraction"%maskPlane.lower(), evaluateMaskFraction(mask, maskPlane))
622 except InvalidParameterError:
623 self.metadata.add(
"%s_mask_fraction"%maskPlane.lower(), -1)
624 self.log.info(
"Unable to calculate metrics for mask plane %s: not in image"%maskPlane)
626 def _runStreakMasking(self, maskedImage):
627 """Do streak masking and optionally save the resulting streak
628 fit parameters in a catalog.
632 maskedImage: `lsst.afw.image.maskedImage`
633 The image in which to search for streaks. Must have a detection
638 streakInfo: `lsst.pipe.base.Struct`
639 ``rho`` : `np.ndarray`
640 Angle of detected streak.
641 ``theta`` : `np.ndarray`
642 Distance from center of detected streak.
643 ``sigma`` : `np.ndarray`
644 Width of streak profile.
646 streaks = self.maskStreaks.run(maskedImage)
647 if self.config.writeStreakInfo:
648 rhos = np.array([line.rho
for line
in streaks.lines])
649 thetas = np.array([line.theta
for line
in streaks.lines])
650 sigmas = np.array([line.sigma
for line
in streaks.lines])
651 streakInfo = {
'rho': rhos,
'theta': thetas,
'sigma': sigmas}
653 streakInfo = {
'rho': np.array([]),
'theta': np.array([]),
'sigma': np.array([])}
654 return pipeBase.Struct(maskedStreaks=streakInfo)
658 scoreExposure = pipeBase.connectionTypes.Input(
659 doc=
"Maximum likelihood image for detection.",
660 dimensions=(
"instrument",
"visit",
"detector"),
661 storageClass=
"ExposureF",
662 name=
"{fakesType}{coaddName}Diff_scoreExp",
666class DetectAndMeasureScoreConfig(DetectAndMeasureConfig,
667 pipelineConnections=DetectAndMeasureScoreConnections):
671class DetectAndMeasureScoreTask(DetectAndMeasureTask):
672 """Detect DIA sources using a score image,
673 and measure the detections on the difference image.
675 Source detection is run on the supplied score, or maximum likelihood,
676 image. Note that no additional convolution will be done in this case.
677 Close positive and negative detections will optionally be merged into
679 Sky sources, or forced detections in background regions, will optionally
680 be added, and the configured measurement algorithm will be run on all
683 ConfigClass = DetectAndMeasureScoreConfig
684 _DefaultName =
"detectAndMeasureScore"
687 def run(self, science, matchedTemplate, difference, scoreExposure,
689 """Detect and measure sources on a score image.
693 science : `lsst.afw.image.ExposureF`
694 Science exposure that the template was subtracted from.
695 matchedTemplate : `lsst.afw.image.ExposureF`
696 Warped and PSF-matched template that was used produce the
698 difference : `lsst.afw.image.ExposureF`
699 Result of subtracting template from the science image.
700 scoreExposure : `lsst.afw.image.ExposureF`
701 Score or maximum likelihood difference image
702 idFactory : `lsst.afw.table.IdFactory`, optional
703 Generator object used to assign ids to detected sources in the
704 difference image. Ids from this generator are not set until after
705 deblending and merging positive/negative peaks.
709 measurementResults : `lsst.pipe.base.Struct`
711 ``subtractedMeasuredExposure`` : `lsst.afw.image.ExposureF`
712 Subtracted exposure with detection mask applied.
713 ``diaSources`` : `lsst.afw.table.SourceCatalog`
714 The catalog of detected sources.
716 if idFactory
is None:
720 mask = scoreExposure.mask
721 mask &= ~(mask.getPlaneBitMask(
"DETECTED") | mask.getPlaneBitMask(
"DETECTED_NEGATIVE"))
726 table = afwTable.SourceTable.make(self.schema)
727 results = self.detection.run(
729 exposure=scoreExposure,
733 difference.mask.assign(scoreExposure.mask, scoreExposure.getBBox())
735 sources, positives, negatives = self._deblend(difference,
739 return self.processResults(science, matchedTemplate, difference, sources, idFactory,
740 positiveFootprints=positives, negativeFootprints=negatives)
A mapping between the keys of two Schemas, used to copy data between them.
Class for storing ordered metadata with comments.
run(self, coaddExposures, bbox, wcs, dataIds, physical_filter)