1 from __future__
import absolute_import, division, print_function
3 __all__ = [
"DirectMatchConfig",
"DirectMatchTask"]
5 from lsst.pex.config
import Config, Field, ConfigurableField
6 from lsst.pipe.base
import Task, Struct
7 from lsst.meas.algorithms
import LoadIndexedReferenceObjectsTask
8 import lsst.afw.table
as afwTable
10 from lsst.afw.geom
import arcseconds
14 """Configuration for DirectMatchTask"""
15 refObjLoader = ConfigurableField(target=LoadIndexedReferenceObjectsTask, doc=
"Load reference objects")
16 matchRadius = Field(dtype=float, default=0.25, doc=
"Matching radius, arcsec")
20 """!Simple matching of a source catalog to a reference catalog
22 @anchor DirectMatchTask_
24 @section meas_astrom_match_Contents Contents
26 - @ref meas_astrom_match_Purpose
27 - @ref meas_astrom_match_Initialize
28 - @ref meas_astrom_match_IO
29 - @ref meas_astrom_match_Config
30 - @ref meas_astrom_match_Example
32 @section meas_astrom_match_Purpose Description
34 Match sources to reference objects. The matching permits no rotation or scaling,
35 but uses the existing sky positions in the source catalog. This is often useful
36 for QA, as it allows validating the pipeline astrometry and photometry against
37 the reference catalog.
39 Note that this DirectMatchTask is not currently suitable for use within the
40 AstrometryTask, as it has a different interface and serves a different purpose.
42 @section meas_astrom_match_Initialize Task initialisation
46 @section meas_astrom_match_IO Invoking the Task
50 @section meas_astrom_match_Config Configuration parameters
52 See @ref DirectMatchConfig
54 @section meas_astrom_match_Example A complete example of using DirectMatchTask
56 config = DirectMatchConfig()
57 task = DirectMatchTask(butler=butler, config=config)
58 matchResults = task.run(catalog)
62 ConfigClass = DirectMatchConfig
63 _DefaultName =
"directMatch"
65 def __init__(self, butler=None, refObjLoader=None, **kwargs):
68 Either a 'butler' or 'refObjLoader' is required.
70 @param butler Data butler, or None
71 @param refObjLoader For loading reference objects (lsst.meas.algorithms.LoadReferenceObjectsTask), or
73 @param kwargs Other keyword arguments required for instantiating a Task (e.g., 'config')
75 Task.__init__(self, **kwargs)
77 self.makeSubtask(
"refObjLoader", butler=butler)
81 def run(self, catalog, filterName=None):
82 """!Load reference objects and match to them
84 @param[in] catalog Catalog to match to (lsst.afw.table.SourceCatalog)
85 @param[in] filterName Name of filter, for loading fluxes (str)
86 @return Struct with matches (lsst.afw.table.SourceMatchVector) and
87 matchMeta (lsst.meas.astrom.MatchMetadata)
90 matchMeta = self.refObjLoader.getMetadataCircle(circle.center, circle.radius, filterName)
91 refData = self.refObjLoader.loadSkyCircle(circle.center, circle.radius, filterName)
92 matches = afwTable.matchRaDec(refData.refCat, catalog, self.config.matchRadius*arcseconds)
93 self.log.info(
"Matched %d from %d input and %d reference sources" %
94 (len(matches), len(catalog), len(refData.refCat)))
95 return Struct(matches=matches, matchMeta=matchMeta)
98 """!Calculate a circle enclosing the catalog
100 @param[in] catalog Catalog we will encircle (lsst.afw.table.SourceCatalog)
101 @return Struct with center (lsst.afw.coord.Coord) and radius (lsst.afw.geom.Angle)
103 coordList = [src.getCoord()
for src
in catalog]
104 center = afwCoord.averageCoord(coordList)
105 radius = max(center.angularSeparation(coord)
for coord
in coordList)
106 return Struct(center=center, radius=radius + self.config.matchRadius*arcseconds)
def run
Load reference objects and match to them.
Simple matching of a source catalog to a reference catalog.
def calculateCircle
Calculate a circle enclosing the catalog.