24 from lsstDebug
import getDebugFrame
29 from lsst.meas.astrom import AstrometryTask, displayAstrometry, denormalizeMatches
38 CatalogCalculationTask)
41 from .fakes
import BaseFakeSourcesTask
42 from .photoCal
import PhotoCalTask
44 __all__ = [
"CalibrateConfig",
"CalibrateTask"]
50 icSourceSchema = cT.InitInput(
51 doc=
"Schema produced by characterize image task, used to initialize this task",
53 storageClass=
"SourceCatalog",
56 outputSchema = cT.InitOutput(
57 doc=
"Schema after CalibrateTask has been initialized",
59 storageClass=
"SourceCatalog",
63 doc=
"Input image to calibrate",
65 storageClass=
"ExposureF",
66 dimensions=(
"instrument",
"visit",
"detector"),
69 background = cT.Input(
70 doc=
"Backgrounds determined by characterize task",
71 name=
"icExpBackground",
72 storageClass=
"Background",
73 dimensions=(
"instrument",
"visit",
"detector"),
76 icSourceCat = cT.Input(
77 doc=
"Source catalog created by characterize task",
79 storageClass=
"SourceCatalog",
80 dimensions=(
"instrument",
"visit",
"detector"),
83 astromRefCat = cT.PrerequisiteInput(
84 doc=
"Reference catalog to use for astrometry",
86 storageClass=
"SimpleCatalog",
87 dimensions=(
"skypix",),
92 photoRefCat = cT.PrerequisiteInput(
93 doc=
"Reference catalog to use for photometric calibration",
95 storageClass=
"SimpleCatalog",
96 dimensions=(
"skypix",),
101 outputExposure = cT.Output(
102 doc=
"Exposure after running calibration task",
104 storageClass=
"ExposureF",
105 dimensions=(
"instrument",
"visit",
"detector"),
108 outputCat = cT.Output(
109 doc=
"Source catalog produced in calibrate task",
111 storageClass=
"SourceCatalog",
112 dimensions=(
"instrument",
"visit",
"detector"),
115 outputBackground = cT.Output(
116 doc=
"Background models estimated in calibration task",
117 name=
"calexpBackground",
118 storageClass=
"Background",
119 dimensions=(
"instrument",
"visit",
"detector"),
123 doc=
"Source/refObj matches from the astrometry solver",
125 storageClass=
"Catalog",
126 dimensions=(
"instrument",
"visit",
"detector"),
129 matchesDenormalized = cT.Output(
130 doc=
"Denormalized matches from astrometry solver",
132 storageClass=
"Catalog",
133 dimensions=(
"instrument",
"visit",
"detector"),
139 if config.doAstrometry
is False:
140 self.prerequisiteInputs.remove(
"astromRefCat")
141 if config.doPhotoCal
is False:
142 self.prerequisiteInputs.remove(
"photoRefCat")
144 if config.doWriteMatches
is False or config.doAstrometry
is False:
145 self.outputs.remove(
"matches")
146 if config.doWriteMatchesDenormalized
is False or config.doAstrometry
is False:
147 self.outputs.remove(
"matchesDenormalized")
150 class CalibrateConfig(pipeBase.PipelineTaskConfig, pipelineConnections=CalibrateConnections):
151 """Config for CalibrateTask"""
152 doWrite = pexConfig.Field(
155 doc=
"Save calibration results?",
157 doWriteHeavyFootprintsInSources = pexConfig.Field(
160 doc=
"Include HeavyFootprint data in source table? If false then heavy "
161 "footprints are saved as normal footprints, which saves some space"
163 doWriteMatches = pexConfig.Field(
166 doc=
"Write reference matches (ignored if doWrite or doAstrometry false)?",
168 doWriteMatchesDenormalized = pexConfig.Field(
171 doc=(
"Write reference matches in denormalized format? "
172 "This format uses more disk space, but is more convenient to "
173 "read. Ignored if doWriteMatches=False or doWrite=False."),
175 doAstrometry = pexConfig.Field(
178 doc=
"Perform astrometric calibration?",
180 astromRefObjLoader = pexConfig.ConfigurableField(
181 target=LoadIndexedReferenceObjectsTask,
182 doc=
"reference object loader for astrometric calibration",
184 photoRefObjLoader = pexConfig.ConfigurableField(
185 target=LoadIndexedReferenceObjectsTask,
186 doc=
"reference object loader for photometric calibration",
188 astrometry = pexConfig.ConfigurableField(
189 target=AstrometryTask,
190 doc=
"Perform astrometric calibration to refine the WCS",
192 requireAstrometry = pexConfig.Field(
195 doc=(
"Raise an exception if astrometry fails? Ignored if doAstrometry "
198 doPhotoCal = pexConfig.Field(
201 doc=
"Perform phometric calibration?",
203 requirePhotoCal = pexConfig.Field(
206 doc=(
"Raise an exception if photoCal fails? Ignored if doPhotoCal "
209 photoCal = pexConfig.ConfigurableField(
211 doc=
"Perform photometric calibration",
213 icSourceFieldsToCopy = pexConfig.ListField(
215 default=(
"calib_psf_candidate",
"calib_psf_used",
"calib_psf_reserved"),
216 doc=(
"Fields to copy from the icSource catalog to the output catalog "
217 "for matching sources Any missing fields will trigger a "
218 "RuntimeError exception. Ignored if icSourceCat is not provided.")
220 matchRadiusPix = pexConfig.Field(
223 doc=(
"Match radius for matching icSourceCat objects to sourceCat "
226 checkUnitsParseStrict = pexConfig.Field(
227 doc=(
"Strictness of Astropy unit compatibility check, can be 'raise', "
228 "'warn' or 'silent'"),
232 detection = pexConfig.ConfigurableField(
233 target=SourceDetectionTask,
236 doDeblend = pexConfig.Field(
239 doc=
"Run deblender input exposure"
241 deblend = pexConfig.ConfigurableField(
242 target=SourceDeblendTask,
243 doc=
"Split blended sources into their components"
245 doSkySources = pexConfig.Field(
248 doc=
"Generate sky sources?",
250 skySources = pexConfig.ConfigurableField(
251 target=SkyObjectsTask,
252 doc=
"Generate sky sources",
254 measurement = pexConfig.ConfigurableField(
255 target=SingleFrameMeasurementTask,
256 doc=
"Measure sources"
258 setPrimaryFlags = pexConfig.ConfigurableField(
259 target=SetPrimaryFlagsTask,
260 doc=(
"Set flags for primary source classification in single frame "
261 "processing. True if sources are not sky sources and not a parent.")
263 doApCorr = pexConfig.Field(
266 doc=
"Run subtask to apply aperture correction"
268 applyApCorr = pexConfig.ConfigurableField(
269 target=ApplyApCorrTask,
270 doc=
"Subtask to apply aperture corrections"
275 catalogCalculation = pexConfig.ConfigurableField(
276 target=CatalogCalculationTask,
277 doc=
"Subtask to run catalogCalculation plugins on catalog"
279 doInsertFakes = pexConfig.Field(
282 doc=
"Run fake sources injection task"
284 insertFakes = pexConfig.ConfigurableField(
285 target=BaseFakeSourcesTask,
286 doc=
"Injection of fake sources for testing purposes (must be "
289 doWriteExposure = pexConfig.Field(
292 doc=
"Write the calexp? If fakes have been added then we do not want to write out the calexp as a "
293 "normal calexp but as a fakes_calexp."
298 self.
detection.doTempLocalBackground =
False
299 self.
deblend.maxFootprintSize = 2000
300 self.
measurement.plugins.names |= [
"base_LocalPhotoCalib",
"base_LocalWcs"]
305 if astromRefCatGen2
is not None and astromRefCatGen2 != self.connections.astromRefCat:
307 f
"Gen2 ({astromRefCatGen2}) and Gen3 ({self.connections.astromRefCat}) astrometry reference "
308 f
"catalogs are different. These options must be kept in sync until Gen2 is retired."
311 if photoRefCatGen2
is not None and photoRefCatGen2 != self.connections.photoRefCat:
313 f
"Gen2 ({photoRefCatGen2}) and Gen3 ({self.connections.photoRefCat}) photometry reference "
314 f
"catalogs are different. These options must be kept in sync until Gen2 is retired."
326 r"""!Calibrate an exposure: measure sources and perform astrometric and
327 photometric calibration
329 @anchor CalibrateTask_
331 @section pipe_tasks_calibrate_Contents Contents
333 - @ref pipe_tasks_calibrate_Purpose
334 - @ref pipe_tasks_calibrate_Initialize
335 - @ref pipe_tasks_calibrate_IO
336 - @ref pipe_tasks_calibrate_Config
337 - @ref pipe_tasks_calibrate_Metadata
338 - @ref pipe_tasks_calibrate_Debug
341 @section pipe_tasks_calibrate_Purpose Description
343 Given an exposure with a good PSF model and aperture correction map
344 (e.g. as provided by @ref CharacterizeImageTask), perform the following
346 - Run detection and measurement
347 - Run astrometry subtask to fit an improved WCS
348 - Run photoCal subtask to fit the exposure's photometric zero-point
350 @section pipe_tasks_calibrate_Initialize Task initialisation
352 @copydoc \_\_init\_\_
354 @section pipe_tasks_calibrate_IO Invoking the Task
356 If you want this task to unpersist inputs or persist outputs, then call
357 the `runDataRef` method (a wrapper around the `run` method).
359 If you already have the inputs unpersisted and do not want to persist the
360 output then it is more direct to call the `run` method:
362 @section pipe_tasks_calibrate_Config Configuration parameters
364 See @ref CalibrateConfig
366 @section pipe_tasks_calibrate_Metadata Quantities set in exposure Metadata
370 <dt>MAGZERO_RMS <dd>MAGZERO's RMS == sigma reported by photoCal task
371 <dt>MAGZERO_NOBJ <dd>Number of stars used == ngood reported by photoCal
373 <dt>COLORTERM1 <dd>?? (always 0.0)
374 <dt>COLORTERM2 <dd>?? (always 0.0)
375 <dt>COLORTERM3 <dd>?? (always 0.0)
378 @section pipe_tasks_calibrate_Debug Debug variables
380 The @link lsst.pipe.base.cmdLineTask.CmdLineTask command line task@endlink
381 interface supports a flag
382 `--debug` to import `debug.py` from your `$PYTHONPATH`; see @ref baseDebug
383 for more about `debug.py`.
385 CalibrateTask has a debug dictionary containing one key:
388 <dd>frame (an int; <= 0 to not display) in which to display the exposure,
389 sources and matches. See @ref lsst.meas.astrom.displayAstrometry for
390 the meaning of the various symbols.
393 For example, put something like:
397 di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would
398 # call us recursively
399 if name == "lsst.pipe.tasks.calibrate":
406 lsstDebug.Info = DebugInfo
408 into your `debug.py` file and run `calibrateTask.py` with the `--debug`
411 Some subtasks may have their own debug variables; see individual Task
418 ConfigClass = CalibrateConfig
419 _DefaultName =
"calibrate"
420 RunnerClass = pipeBase.ButlerInitializedTaskRunner
422 def __init__(self, butler=None, astromRefObjLoader=None,
423 photoRefObjLoader=None, icSourceSchema=None,
424 initInputs=None, **kwargs):
425 """!Construct a CalibrateTask
427 @param[in] butler The butler is passed to the refObjLoader constructor
428 in case it is needed. Ignored if the refObjLoader argument
429 provides a loader directly.
430 @param[in] astromRefObjLoader An instance of LoadReferenceObjectsTasks
431 that supplies an external reference catalog for astrometric
432 calibration. May be None if the desired loader can be constructed
433 from the butler argument or all steps requiring a reference catalog
435 @param[in] photoRefObjLoader An instance of LoadReferenceObjectsTasks
436 that supplies an external reference catalog for photometric
437 calibration. May be None if the desired loader can be constructed
438 from the butler argument or all steps requiring a reference catalog
440 @param[in] icSourceSchema schema for icSource catalog, or None.
441 Schema values specified in config.icSourceFieldsToCopy will be
442 taken from this schema. If set to None, no values will be
443 propagated from the icSourceCatalog
444 @param[in,out] kwargs other keyword arguments for
445 lsst.pipe.base.CmdLineTask
449 if icSourceSchema
is None and butler
is not None:
451 icSourceSchema = butler.get(
"icSrc_schema", immediate=
True).schema
453 if icSourceSchema
is None and butler
is None and initInputs
is not None:
454 icSourceSchema = initInputs[
'icSourceSchema'].schema
456 if icSourceSchema
is not None:
459 minimumSchema = afwTable.SourceTable.makeMinimalSchema()
460 self.
schemaMapper.addMinimalSchema(minimumSchema,
False)
469 "Source was detected as an icSource"))
470 missingFieldNames = []
471 for fieldName
in self.config.icSourceFieldsToCopy:
473 schemaItem = icSourceSchema.find(fieldName)
475 missingFieldNames.append(fieldName)
480 if missingFieldNames:
481 raise RuntimeError(
"isSourceCat is missing fields {} "
482 "specified in icSourceFieldsToCopy"
483 .
format(missingFieldNames))
490 self.
schema = afwTable.SourceTable.makeMinimalSchema()
491 self.makeSubtask(
'detection', schema=self.
schema)
498 if self.config.doInsertFakes:
499 self.makeSubtask(
"insertFakes")
501 if self.config.doDeblend:
502 self.makeSubtask(
"deblend", schema=self.
schema)
503 if self.config.doSkySources:
504 self.makeSubtask(
"skySources")
505 self.
skySourceKey = self.
schema.addField(
"sky_source", type=
"Flag", doc=
"Sky objects.")
506 self.makeSubtask(
'measurement', schema=self.
schema,
508 self.makeSubtask(
"setPrimaryFlags", schema=self.
schema, isSingleFrame=
True)
509 if self.config.doApCorr:
510 self.makeSubtask(
'applyApCorr', schema=self.
schema)
511 self.makeSubtask(
'catalogCalculation', schema=self.
schema)
513 if self.config.doAstrometry:
514 if astromRefObjLoader
is None and butler
is not None:
515 self.makeSubtask(
'astromRefObjLoader', butler=butler)
516 astromRefObjLoader = self.astromRefObjLoader
517 self.
pixelMargin = astromRefObjLoader.config.pixelMargin
518 self.makeSubtask(
"astrometry", refObjLoader=astromRefObjLoader,
520 if self.config.doPhotoCal:
521 if photoRefObjLoader
is None and butler
is not None:
522 self.makeSubtask(
'photoRefObjLoader', butler=butler)
523 photoRefObjLoader = self.photoRefObjLoader
524 self.
pixelMargin = photoRefObjLoader.config.pixelMargin
525 self.makeSubtask(
"photoCal", refObjLoader=photoRefObjLoader,
528 if initInputs
is not None and (astromRefObjLoader
is not None or photoRefObjLoader
is not None):
529 raise RuntimeError(
"PipelineTask form of this task should not be initialized with "
530 "reference object loaders.")
535 self.
schema.checkUnits(parse_strict=self.config.checkUnitsParseStrict)
542 def runDataRef(self, dataRef, exposure=None, background=None, icSourceCat=None,
544 """!Calibrate an exposure, optionally unpersisting inputs and
547 This is a wrapper around the `run` method that unpersists inputs
548 (if `doUnpersist` true) and persists outputs (if `config.doWrite` true)
550 @param[in] dataRef butler data reference corresponding to a science
552 @param[in,out] exposure characterized exposure (an
553 lsst.afw.image.ExposureF or similar), or None to unpersist existing
554 icExp and icBackground. See `run` method for details of what is
556 @param[in,out] background initial model of background already
557 subtracted from exposure (an lsst.afw.math.BackgroundList). May be
558 None if no background has been subtracted, though that is unusual
559 for calibration. A refined background model is output. Ignored if
561 @param[in] icSourceCat catalog from which to copy the fields specified
562 by icSourceKeys, or None;
563 @param[in] doUnpersist unpersist data:
564 - if True, exposure, background and icSourceCat are read from
565 dataRef and those three arguments must all be None;
566 - if False the exposure must be provided; background and
567 icSourceCat are optional. True is intended for running as a
568 command-line task, False for running as a subtask
569 @return same data as the calibrate method
571 self.log.
info(
"Processing %s" % (dataRef.dataId))
574 if any(item
is not None for item
in (exposure, background,
576 raise RuntimeError(
"doUnpersist true; exposure, background "
577 "and icSourceCat must all be None")
578 exposure = dataRef.get(
"icExp", immediate=
True)
579 background = dataRef.get(
"icExpBackground", immediate=
True)
580 icSourceCat = dataRef.get(
"icSrc", immediate=
True)
581 elif exposure
is None:
582 raise RuntimeError(
"doUnpersist false; exposure must be provided")
584 exposureIdInfo = dataRef.get(
"expIdInfo")
588 exposureIdInfo=exposureIdInfo,
589 background=background,
590 icSourceCat=icSourceCat,
593 if self.config.doWrite:
596 exposure=calRes.exposure,
597 background=calRes.background,
598 sourceCat=calRes.sourceCat,
599 astromMatches=calRes.astromMatches,
600 matchMeta=calRes.matchMeta,
606 inputs = butlerQC.get(inputRefs)
607 expId, expBits = butlerQC.quantum.dataId.pack(
"visit_detector",
611 if self.config.doAstrometry:
613 for ref
in inputRefs.astromRefCat],
614 refCats=inputs.pop(
'astromRefCat'),
615 config=self.config.astromRefObjLoader, log=self.log)
617 self.astrometry.setRefObjLoader(refObjLoader)
619 if self.config.doPhotoCal:
621 for ref
in inputRefs.photoRefCat],
622 refCats=inputs.pop(
'photoRefCat'),
623 config=self.config.photoRefObjLoader,
625 self.
pixelMargin = photoRefObjLoader.config.pixelMargin
626 self.photoCal.match.setRefObjLoader(photoRefObjLoader)
628 outputs = self.
run(**inputs)
630 if self.config.doWriteMatches
and self.config.doAstrometry:
632 normalizedMatches.table.setMetadata(outputs.matchMeta)
633 if self.config.doWriteMatchesDenormalized:
635 outputs.matchesDenormalized = denormMatches
636 outputs.matches = normalizedMatches
637 butlerQC.put(outputs, outputRefs)
640 def run(self, exposure, exposureIdInfo=None, background=None,
642 """!Calibrate an exposure (science image or coadd)
644 @param[in,out] exposure exposure to calibrate (an
645 lsst.afw.image.ExposureF or similar);
650 - MaskedImage has background subtracted
652 - PhotoCalib is replaced
653 @param[in] exposureIdInfo ID info for exposure (an
654 lsst.obs.base.ExposureIdInfo) If not provided, returned
655 SourceCatalog IDs will not be globally unique.
656 @param[in,out] background background model already subtracted from
657 exposure (an lsst.afw.math.BackgroundList). May be None if no
658 background has been subtracted, though that is unusual for
659 calibration. A refined background model is output.
660 @param[in] icSourceCat A SourceCatalog from CharacterizeImageTask
661 from which we can copy some fields.
663 @return pipe_base Struct containing these fields:
664 - exposure calibrate science exposure with refined WCS and PhotoCalib
665 - background model of background subtracted from exposure (an
666 lsst.afw.math.BackgroundList)
667 - sourceCat catalog of measured sources
668 - astromMatches list of source/refObj matches from the astrometry
672 if exposureIdInfo
is None:
675 if background
is None:
677 sourceIdFactory = IdFactory.makeSource(exposureIdInfo.expId,
678 exposureIdInfo.unusedBits)
679 table = SourceTable.make(self.
schema, sourceIdFactory)
682 detRes = self.detection.
run(table=table, exposure=exposure,
684 sourceCat = detRes.sources
685 if detRes.fpSets.background:
686 for bg
in detRes.fpSets.background:
687 background.append(bg)
688 if self.config.doSkySources:
689 skySourceFootprints = self.skySources.
run(mask=exposure.mask, seed=exposureIdInfo.expId)
690 if skySourceFootprints:
691 for foot
in skySourceFootprints:
692 s = sourceCat.addNew()
695 if self.config.doDeblend:
696 self.deblend.
run(exposure=exposure, sources=sourceCat)
697 self.measurement.
run(
700 exposureId=exposureIdInfo.expId
702 if self.config.doApCorr:
703 self.applyApCorr.
run(
705 apCorrMap=exposure.getInfo().getApCorrMap()
707 self.catalogCalculation.
run(sourceCat)
709 self.setPrimaryFlags.
run(sourceCat, includeDeblend=self.config.doDeblend)
711 if icSourceCat
is not None and \
712 len(self.config.icSourceFieldsToCopy) > 0:
720 if not sourceCat.isContiguous():
721 sourceCat = sourceCat.copy(deep=
True)
727 if self.config.doAstrometry:
729 astromRes = self.astrometry.
run(
733 astromMatches = astromRes.matches
734 matchMeta = astromRes.matchMeta
735 except Exception
as e:
736 if self.config.requireAstrometry:
738 self.log.
warn(
"Unable to perform astrometric calibration "
739 "(%s): attempting to proceed" % e)
742 if self.config.doPhotoCal:
744 photoRes = self.photoCal.
run(exposure, sourceCat=sourceCat, expId=exposureIdInfo.expId)
745 exposure.setPhotoCalib(photoRes.photoCalib)
747 self.log.
info(
"Photometric zero-point: %f" %
748 photoRes.photoCalib.instFluxToMagnitude(1.0))
749 self.
setMetadata(exposure=exposure, photoRes=photoRes)
750 except Exception
as e:
751 if self.config.requirePhotoCal:
753 self.log.
warn(
"Unable to perform photometric calibration "
754 "(%s): attempting to proceed" % e)
757 if self.config.doInsertFakes:
758 self.insertFakes.
run(exposure, background=background)
760 table = SourceTable.make(self.
schema, sourceIdFactory)
763 detRes = self.detection.
run(table=table, exposure=exposure,
765 sourceCat = detRes.sources
766 if detRes.fpSets.background:
767 for bg
in detRes.fpSets.background:
768 background.append(bg)
769 if self.config.doDeblend:
770 self.deblend.
run(exposure=exposure, sources=sourceCat)
771 self.measurement.
run(
774 exposureId=exposureIdInfo.expId
776 if self.config.doApCorr:
777 self.applyApCorr.
run(
779 apCorrMap=exposure.getInfo().getApCorrMap()
781 self.catalogCalculation.
run(sourceCat)
783 if icSourceCat
is not None and len(self.config.icSourceFieldsToCopy) > 0:
792 matches=astromMatches,
797 return pipeBase.Struct(
799 background=background,
801 astromMatches=astromMatches,
805 outputExposure=exposure,
807 outputBackground=background,
811 astromMatches, matchMeta):
812 """Write output data to the output repository
814 @param[in] dataRef butler data reference corresponding to a science
816 @param[in] exposure exposure to write
817 @param[in] background background model for exposure
818 @param[in] sourceCat catalog of measured sources
819 @param[in] astromMatches list of source/refObj matches from the
822 dataRef.put(sourceCat,
"src")
823 if self.config.doWriteMatches
and astromMatches
is not None:
825 normalizedMatches.table.setMetadata(matchMeta)
826 dataRef.put(normalizedMatches,
"srcMatch")
827 if self.config.doWriteMatchesDenormalized:
829 dataRef.put(denormMatches,
"srcMatchFull")
830 if self.config.doWriteExposure:
831 dataRef.put(exposure,
"calexp")
832 dataRef.put(background,
"calexpBackground")
835 """Return a dict of empty catalogs for each catalog dataset produced
840 return {
"src": sourceCat}
843 """!Set task and exposure metadata
845 Logs a warning and continues if needed data is missing.
847 @param[in,out] exposure exposure whose metadata is to be set
848 @param[in] photoRes results of running photoCal; if None then it was
854 metadata = exposure.getMetadata()
858 exposureTime = exposure.getInfo().getVisitInfo().getExposureTime()
859 magZero = photoRes.zp - 2.5*math.log10(exposureTime)
861 self.log.
warn(
"Could not set normalized MAGZERO in header: no "
866 metadata.set(
'MAGZERO', magZero)
867 metadata.set(
'MAGZERO_RMS', photoRes.sigma)
868 metadata.set(
'MAGZERO_NOBJ', photoRes.ngood)
869 metadata.set(
'COLORTERM1', 0.0)
870 metadata.set(
'COLORTERM2', 0.0)
871 metadata.set(
'COLORTERM3', 0.0)
872 except Exception
as e:
873 self.log.
warn(
"Could not set exposure metadata: %s" % (e,))
876 """!Match sources in icSourceCat and sourceCat and copy the specified fields
878 @param[in] icSourceCat catalog from which to copy fields
879 @param[in,out] sourceCat catalog to which to copy fields
881 The fields copied are those specified by `config.icSourceFieldsToCopy`
882 that actually exist in the schema. This was set up by the constructor
883 using self.schemaMapper.
886 raise RuntimeError(
"To copy icSource fields you must specify "
887 "icSourceSchema nd icSourceKeys when "
888 "constructing this task")
889 if icSourceCat
is None or sourceCat
is None:
890 raise RuntimeError(
"icSourceCat and sourceCat must both be "
892 if len(self.config.icSourceFieldsToCopy) == 0:
893 self.log.
warn(
"copyIcSourceFields doing nothing because "
894 "icSourceFieldsToCopy is empty")
898 mc.findOnlyClosest =
False
900 self.config.matchRadiusPix, mc)
901 if self.config.doDeblend:
902 deblendKey = sourceCat.schema[
"deblend_nChild"].asKey()
904 matches = [m
for m
in matches
if m[1].get(deblendKey) == 0]
911 for m0, m1, d
in matches:
913 match = bestMatches.get(id0)
914 if match
is None or d <= match[2]:
915 bestMatches[id0] = (m0, m1, d)
916 matches =
list(bestMatches.values())
921 numMatches = len(matches)
922 numUniqueSources = len(
set(m[1].getId()
for m
in matches))
923 if numUniqueSources != numMatches:
924 self.log.
warn(
"{} icSourceCat sources matched only {} sourceCat "
925 "sources".
format(numMatches, numUniqueSources))
927 self.log.
info(
"Copying flags from icSourceCat to sourceCat for "
928 "%s sources" % (numMatches,))
932 for icSrc, src, d
in matches:
938 icSrcFootprint = icSrc.getFootprint()
940 icSrc.setFootprint(src.getFootprint())
943 icSrc.setFootprint(icSrcFootprint)