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 .createMatchMetadata
import MatchMetadata
8 from lsst.meas.algorithms
import LoadIndexedReferenceObjectsTask
9 import lsst.afw.table
as afwTable
11 from lsst.afw.geom
import arcseconds
15 """Configuration for DirectMatchTask"""
16 refObjLoader = ConfigurableField(target=LoadIndexedReferenceObjectsTask, doc=
"Load reference objects")
17 matchRadius = Field(dtype=float, default=0.25, doc=
"Matching radius, arcsec")
21 """!Simple matching of a source catalog to a reference catalog
23 @anchor DirectMatchTask_
25 @section meas_astrom_match_Contents Contents
27 - @ref meas_astrom_match_Purpose
28 - @ref meas_astrom_match_Initialize
29 - @ref meas_astrom_match_IO
30 - @ref meas_astrom_match_Config
31 - @ref meas_astrom_match_Example
33 @section meas_astrom_match_Purpose Description
35 Match sources to reference objects. The matching permits no rotation or scaling,
36 but uses the existing sky positions in the source catalog. This is often useful
37 for QA, as it allows validating the pipeline astrometry and photometry against
38 the reference catalog.
40 Note that this DirectMatchTask is not currently suitable for use within the
41 AstrometryTask, as it has a different interface and serves a different purpose.
43 @section meas_astrom_match_Initialize Task initialisation
47 @section meas_astrom_match_IO Invoking the Task
51 @section meas_astrom_match_Config Configuration parameters
53 See @ref DirectMatchConfig
55 @section meas_astrom_match_Example A complete example of using DirectMatchTask
57 config = DirectMatchConfig()
58 task = DirectMatchTask(butler=butler, config=config)
59 matchResults = task.run(catalog)
63 ConfigClass = DirectMatchConfig
64 _DefaultName =
"directMatch"
66 def __init__(self, butler=None, refObjLoader=None, **kwargs):
69 Either a 'butler' or 'refObjLoader' is required.
71 @param butler Data butler, or None
72 @param refObjLoader For loading reference objects (lsst.meas.algorithms.LoadReferenceObjectsTask), or
74 @param kwargs Other keyword arguments required for instantiating a Task (e.g., 'config')
76 Task.__init__(self, **kwargs)
78 self.makeSubtask(
"refObjLoader", butler=butler)
82 def run(self, catalog, filterName=None):
83 """!Load reference objects and match to them
85 @param[in] catalog Catalog to match to (lsst.afw.table.SourceCatalog)
86 @param[in] filterName Name of filter, for loading fluxes (str)
87 @return Struct with matches (lsst.afw.table.SourceMatchVector) and
88 matchMeta (lsst.meas.astrom.MatchMetadata)
91 matchMeta = MatchMetadata(circle.center, circle.radius, filterName)
92 refData = self.refObjLoader.loadSkyCircle(circle.center, circle.radius, filterName)
93 matches = afwTable.matchRaDec(refData.refCat, catalog, self.config.matchRadius*arcseconds)
94 self.log.info(
"Matched %d from %d input and %d reference sources" %
95 (len(matches), len(catalog), len(refData.refCat)))
96 return Struct(matches=matches, matchMeta=matchMeta)
99 """!Calculate a circle enclosing the catalog
101 @param[in] catalog Catalog we will encircle (lsst.afw.table.SourceCatalog)
102 @return Struct with center (lsst.afw.coord.Coord) and radius (lsst.afw.geom.Angle)
104 coordList = [src.getCoord()
for src
in catalog]
105 center = afwCoord.averageCoord(coordList)
106 radius = max(center.angularSeparation(coord)
for coord
in coordList)
107 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.