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.
detectiondetection.doTempLocalBackground =
False
299 self.
deblenddeblend.maxFootprintSize = 2000
300 self.
measurementmeasurement.plugins.names |= [
"base_LocalPhotoCalib",
"base_LocalWcs"]
304 astromRefCatGen2 = getattr(self.
astromRefObjLoaderastromRefObjLoader,
"ref_dataset_name",
None)
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."
310 photoRefCatGen2 = getattr(self.
photoRefObjLoaderphotoRefObjLoader,
"ref_dataset_name",
None)
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.
schemaMapperschemaMapper.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)
478 self.
schemaMapperschemaMapper.addMapping(schemaItem.getKey())
480 if missingFieldNames:
481 raise RuntimeError(
"isSourceCat is missing fields {} "
482 "specified in icSourceFieldsToCopy"
483 .
format(missingFieldNames))
490 self.
schemaschema = afwTable.SourceTable.makeMinimalSchema()
491 self.makeSubtask(
'detection', schema=self.
schemaschema)
498 if self.config.doInsertFakes:
499 self.makeSubtask(
"insertFakes")
501 if self.config.doDeblend:
502 self.makeSubtask(
"deblend", schema=self.
schemaschema)
503 if self.config.doSkySources:
504 self.makeSubtask(
"skySources")
505 self.
skySourceKeyskySourceKey = self.
schemaschema.addField(
"sky_source", type=
"Flag", doc=
"Sky objects.")
506 self.makeSubtask(
'measurement', schema=self.
schemaschema,
508 self.makeSubtask(
"setPrimaryFlags", schema=self.
schemaschema, isSingleFrame=
True)
509 if self.config.doApCorr:
510 self.makeSubtask(
'applyApCorr', schema=self.
schemaschema)
511 self.makeSubtask(
'catalogCalculation', schema=self.
schemaschema)
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.makeSubtask(
"astrometry", refObjLoader=astromRefObjLoader,
519 if self.config.doPhotoCal:
520 if photoRefObjLoader
is None and butler
is not None:
521 self.makeSubtask(
'photoRefObjLoader', butler=butler)
522 photoRefObjLoader = self.photoRefObjLoader
523 self.makeSubtask(
"photoCal", refObjLoader=photoRefObjLoader,
526 if initInputs
is not None and (astromRefObjLoader
is not None or photoRefObjLoader
is not None):
527 raise RuntimeError(
"PipelineTask form of this task should not be initialized with "
528 "reference object loaders.")
533 self.
schemaschema.checkUnits(parse_strict=self.config.checkUnitsParseStrict)
540 def runDataRef(self, dataRef, exposure=None, background=None, icSourceCat=None,
542 """!Calibrate an exposure, optionally unpersisting inputs and
545 This is a wrapper around the `run` method that unpersists inputs
546 (if `doUnpersist` true) and persists outputs (if `config.doWrite` true)
548 @param[in] dataRef butler data reference corresponding to a science
550 @param[in,out] exposure characterized exposure (an
551 lsst.afw.image.ExposureF or similar), or None to unpersist existing
552 icExp and icBackground. See `run` method for details of what is
554 @param[in,out] background initial model of background already
555 subtracted from exposure (an lsst.afw.math.BackgroundList). May be
556 None if no background has been subtracted, though that is unusual
557 for calibration. A refined background model is output. Ignored if
559 @param[in] icSourceCat catalog from which to copy the fields specified
560 by icSourceKeys, or None;
561 @param[in] doUnpersist unpersist data:
562 - if True, exposure, background and icSourceCat are read from
563 dataRef and those three arguments must all be None;
564 - if False the exposure must be provided; background and
565 icSourceCat are optional. True is intended for running as a
566 command-line task, False for running as a subtask
567 @return same data as the calibrate method
569 self.log.
info(
"Processing %s" % (dataRef.dataId))
572 if any(item
is not None for item
in (exposure, background,
574 raise RuntimeError(
"doUnpersist true; exposure, background "
575 "and icSourceCat must all be None")
576 exposure = dataRef.get(
"icExp", immediate=
True)
577 background = dataRef.get(
"icExpBackground", immediate=
True)
578 icSourceCat = dataRef.get(
"icSrc", immediate=
True)
579 elif exposure
is None:
580 raise RuntimeError(
"doUnpersist false; exposure must be provided")
582 exposureIdInfo = dataRef.get(
"expIdInfo")
584 calRes = self.
runrun(
586 exposureIdInfo=exposureIdInfo,
587 background=background,
588 icSourceCat=icSourceCat,
591 if self.config.doWrite:
594 exposure=calRes.exposure,
595 background=calRes.background,
596 sourceCat=calRes.sourceCat,
597 astromMatches=calRes.astromMatches,
598 matchMeta=calRes.matchMeta,
604 inputs = butlerQC.get(inputRefs)
605 inputs[
'exposureIdInfo'] = ExposureIdInfo.fromDataId(butlerQC.quantum.dataId,
"visit_detector")
607 if self.config.doAstrometry:
609 for ref
in inputRefs.astromRefCat],
610 refCats=inputs.pop(
'astromRefCat'),
611 config=self.config.astromRefObjLoader, log=self.log)
612 self.astrometry.setRefObjLoader(refObjLoader)
614 if self.config.doPhotoCal:
616 for ref
in inputRefs.photoRefCat],
617 refCats=inputs.pop(
'photoRefCat'),
618 config=self.config.photoRefObjLoader,
620 self.photoCal.match.setRefObjLoader(photoRefObjLoader)
622 outputs = self.
runrun(**inputs)
624 if self.config.doWriteMatches
and self.config.doAstrometry:
626 normalizedMatches.table.setMetadata(outputs.matchMeta)
627 if self.config.doWriteMatchesDenormalized:
629 outputs.matchesDenormalized = denormMatches
630 outputs.matches = normalizedMatches
631 butlerQC.put(outputs, outputRefs)
634 def run(self, exposure, exposureIdInfo=None, background=None,
636 """!Calibrate an exposure (science image or coadd)
638 @param[in,out] exposure exposure to calibrate (an
639 lsst.afw.image.ExposureF or similar);
644 - MaskedImage has background subtracted
646 - PhotoCalib is replaced
647 @param[in] exposureIdInfo ID info for exposure (an
648 lsst.obs.base.ExposureIdInfo) If not provided, returned
649 SourceCatalog IDs will not be globally unique.
650 @param[in,out] background background model already subtracted from
651 exposure (an lsst.afw.math.BackgroundList). May be None if no
652 background has been subtracted, though that is unusual for
653 calibration. A refined background model is output.
654 @param[in] icSourceCat A SourceCatalog from CharacterizeImageTask
655 from which we can copy some fields.
657 @return pipe_base Struct containing these fields:
658 - exposure calibrate science exposure with refined WCS and PhotoCalib
659 - background model of background subtracted from exposure (an
660 lsst.afw.math.BackgroundList)
661 - sourceCat catalog of measured sources
662 - astromMatches list of source/refObj matches from the astrometry
666 if exposureIdInfo
is None:
667 exposureIdInfo = ExposureIdInfo()
669 if background
is None:
671 sourceIdFactory = exposureIdInfo.makeSourceIdFactory()
672 table = SourceTable.make(self.
schemaschema, sourceIdFactory)
675 detRes = self.detection.
run(table=table, exposure=exposure,
677 sourceCat = detRes.sources
678 if detRes.fpSets.background:
679 for bg
in detRes.fpSets.background:
680 background.append(bg)
681 if self.config.doSkySources:
682 skySourceFootprints = self.skySources.
run(mask=exposure.mask, seed=exposureIdInfo.expId)
683 if skySourceFootprints:
684 for foot
in skySourceFootprints:
685 s = sourceCat.addNew()
688 if self.config.doDeblend:
689 self.deblend.
run(exposure=exposure, sources=sourceCat)
690 self.measurement.
run(
693 exposureId=exposureIdInfo.expId
695 if self.config.doApCorr:
696 self.applyApCorr.
run(
698 apCorrMap=exposure.getInfo().getApCorrMap()
700 self.catalogCalculation.
run(sourceCat)
702 self.setPrimaryFlags.
run(sourceCat)
704 if icSourceCat
is not None and \
705 len(self.config.icSourceFieldsToCopy) > 0:
713 if not sourceCat.isContiguous():
714 sourceCat = sourceCat.copy(deep=
True)
720 if self.config.doAstrometry:
722 astromRes = self.astrometry.
run(
726 astromMatches = astromRes.matches
727 matchMeta = astromRes.matchMeta
728 except Exception
as e:
729 if self.config.requireAstrometry:
731 self.log.
warn(
"Unable to perform astrometric calibration "
732 "(%s): attempting to proceed" % e)
735 if self.config.doPhotoCal:
737 photoRes = self.photoCal.
run(exposure, sourceCat=sourceCat, expId=exposureIdInfo.expId)
738 exposure.setPhotoCalib(photoRes.photoCalib)
740 self.log.
info(
"Photometric zero-point: %f" %
741 photoRes.photoCalib.instFluxToMagnitude(1.0))
742 self.
setMetadatasetMetadata(exposure=exposure, photoRes=photoRes)
743 except Exception
as e:
744 if self.config.requirePhotoCal:
746 self.log.
warn(
"Unable to perform photometric calibration "
747 "(%s): attempting to proceed" % e)
748 self.
setMetadatasetMetadata(exposure=exposure, photoRes=
None)
750 if self.config.doInsertFakes:
751 self.insertFakes.
run(exposure, background=background)
753 table = SourceTable.make(self.
schemaschema, sourceIdFactory)
756 detRes = self.detection.
run(table=table, exposure=exposure,
758 sourceCat = detRes.sources
759 if detRes.fpSets.background:
760 for bg
in detRes.fpSets.background:
761 background.append(bg)
762 if self.config.doDeblend:
763 self.deblend.
run(exposure=exposure, sources=sourceCat)
764 self.measurement.
run(
767 exposureId=exposureIdInfo.expId
769 if self.config.doApCorr:
770 self.applyApCorr.
run(
772 apCorrMap=exposure.getInfo().getApCorrMap()
774 self.catalogCalculation.
run(sourceCat)
776 if icSourceCat
is not None and len(self.config.icSourceFieldsToCopy) > 0:
785 matches=astromMatches,
790 return pipeBase.Struct(
792 background=background,
794 astromMatches=astromMatches,
798 outputExposure=exposure,
800 outputBackground=background,
804 astromMatches, matchMeta):
805 """Write output data to the output repository
807 @param[in] dataRef butler data reference corresponding to a science
809 @param[in] exposure exposure to write
810 @param[in] background background model for exposure
811 @param[in] sourceCat catalog of measured sources
812 @param[in] astromMatches list of source/refObj matches from the
815 dataRef.put(sourceCat,
"src")
816 if self.config.doWriteMatches
and astromMatches
is not None:
818 normalizedMatches.table.setMetadata(matchMeta)
819 dataRef.put(normalizedMatches,
"srcMatch")
820 if self.config.doWriteMatchesDenormalized:
822 dataRef.put(denormMatches,
"srcMatchFull")
823 if self.config.doWriteExposure:
824 dataRef.put(exposure,
"calexp")
825 dataRef.put(background,
"calexpBackground")
828 """Return a dict of empty catalogs for each catalog dataset produced
833 return {
"src": sourceCat}
836 """!Set task and exposure metadata
838 Logs a warning and continues if needed data is missing.
840 @param[in,out] exposure exposure whose metadata is to be set
841 @param[in] photoRes results of running photoCal; if None then it was
847 metadata = exposure.getMetadata()
851 exposureTime = exposure.getInfo().getVisitInfo().getExposureTime()
852 magZero = photoRes.zp - 2.5*math.log10(exposureTime)
854 self.log.
warn(
"Could not set normalized MAGZERO in header: no "
859 metadata.set(
'MAGZERO', magZero)
860 metadata.set(
'MAGZERO_RMS', photoRes.sigma)
861 metadata.set(
'MAGZERO_NOBJ', photoRes.ngood)
862 metadata.set(
'COLORTERM1', 0.0)
863 metadata.set(
'COLORTERM2', 0.0)
864 metadata.set(
'COLORTERM3', 0.0)
865 except Exception
as e:
866 self.log.
warn(
"Could not set exposure metadata: %s" % (e,))
869 """!Match sources in icSourceCat and sourceCat and copy the specified fields
871 @param[in] icSourceCat catalog from which to copy fields
872 @param[in,out] sourceCat catalog to which to copy fields
874 The fields copied are those specified by `config.icSourceFieldsToCopy`
875 that actually exist in the schema. This was set up by the constructor
876 using self.schemaMapper.
879 raise RuntimeError(
"To copy icSource fields you must specify "
880 "icSourceSchema nd icSourceKeys when "
881 "constructing this task")
882 if icSourceCat
is None or sourceCat
is None:
883 raise RuntimeError(
"icSourceCat and sourceCat must both be "
885 if len(self.config.icSourceFieldsToCopy) == 0:
886 self.log.
warn(
"copyIcSourceFields doing nothing because "
887 "icSourceFieldsToCopy is empty")
891 mc.findOnlyClosest =
False
893 self.config.matchRadiusPix, mc)
894 if self.config.doDeblend:
895 deblendKey = sourceCat.schema[
"deblend_nChild"].asKey()
897 matches = [m
for m
in matches
if m[1].get(deblendKey) == 0]
904 for m0, m1, d
in matches:
906 match = bestMatches.get(id0)
907 if match
is None or d <= match[2]:
908 bestMatches[id0] = (m0, m1, d)
909 matches =
list(bestMatches.values())
914 numMatches = len(matches)
915 numUniqueSources = len(
set(m[1].getId()
for m
in matches))
916 if numUniqueSources != numMatches:
917 self.log.
warn(
"{} icSourceCat sources matched only {} sourceCat "
918 "sources".
format(numMatches, numUniqueSources))
920 self.log.
info(
"Copying flags from icSourceCat to sourceCat for "
921 "%s sources" % (numMatches,))
925 for icSrc, src, d
in matches:
931 icSrcFootprint = icSrc.getFootprint()
933 icSrc.setFootprint(src.getFootprint())
936 icSrc.setFootprint(icSrcFootprint)
afw::table::PointKey< int > dimensions
Pass parameters to algorithms that match list of sources.
A mapping between the keys of two Schemas, used to copy data between them.
Class for storing ordered metadata with comments.
def __init__(self, *config=None)
Calibrate an exposure: measure sources and perform astrometric and photometric calibration.
def writeOutputs(self, dataRef, exposure, background, sourceCat, astromMatches, matchMeta)
def runDataRef(self, dataRef, exposure=None, background=None, icSourceCat=None, doUnpersist=True)
Calibrate an exposure, optionally unpersisting inputs and persisting outputs.
def __init__(self, butler=None, astromRefObjLoader=None, photoRefObjLoader=None, icSourceSchema=None, initInputs=None, **kwargs)
Construct a CalibrateTask.
def setMetadata(self, exposure, photoRes=None)
Set task and exposure metadata.
def runQuantum(self, butlerQC, inputRefs, outputRefs)
def getSchemaCatalogs(self)
def copyIcSourceFields(self, icSourceCat, sourceCat)
Match sources in icSourceCat and sourceCat and copy the specified fields.
def run(self, exposure, exposureIdInfo=None, background=None, icSourceCat=None)
Calibrate an exposure (science image or coadd)
daf::base::PropertyList * list
daf::base::PropertySet * set
BaseCatalog packMatches(std::vector< Match< Record1, Record2 > > const &matches)
Return a table representation of a MatchVector that can be used to persist it.
SourceMatchVector matchXy(SourceCatalog const &cat1, SourceCatalog const &cat2, double radius, MatchControl const &mc=MatchControl())
Compute all tuples (s1,s2,d) where s1 belings to cat1, s2 belongs to cat2 and d, the distance between...
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations.
def denormalizeMatches(matches, matchMeta=None)
def displayAstrometry(refCat=None, sourceCat=None, distortedCentroidKey=None, bbox=None, exposure=None, matches=None, frame=1, title="", pause=True)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
def getDebugFrame(debugDisplay, name)
A description of a field in a table.