lsst.meas.astrom  13.0-16-g30f6da5+26
directMatch.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division, print_function
2 
3 __all__ = ["DirectMatchConfig", "DirectMatchTask"]
4 
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
9 import lsst.afw.coord as afwCoord
10 from lsst.afw.geom import arcseconds
11 
12 
13 class DirectMatchConfig(Config):
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")
17 
18 
19 class DirectMatchTask(Task):
20  """!Simple matching of a source catalog to a reference catalog
21 
22  @anchor DirectMatchTask_
23 
24  @section meas_astrom_match_Contents Contents
25 
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
31 
32  @section meas_astrom_match_Purpose Description
33 
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.
38 
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.
41 
42  @section meas_astrom_match_Initialize Task initialisation
43 
44  @copydoc \_\_init\_\_
45 
46  @section meas_astrom_match_IO Invoking the Task
47 
48  @copydoc run
49 
50  @section meas_astrom_match_Config Configuration parameters
51 
52  See @ref DirectMatchConfig
53 
54  @section meas_astrom_match_Example A complete example of using DirectMatchTask
55 
56  config = DirectMatchConfig()
57  task = DirectMatchTask(butler=butler, config=config)
58  matchResults = task.run(catalog)
59 
60  """
61 
62  ConfigClass = DirectMatchConfig
63  _DefaultName = "directMatch"
64 
65  def __init__(self, butler=None, refObjLoader=None, **kwargs):
66  """!Ctor
67 
68  Either a 'butler' or 'refObjLoader' is required.
69 
70  @param butler Data butler, or None
71  @param refObjLoader For loading reference objects (lsst.meas.algorithms.LoadReferenceObjectsTask), or
72  None
73  @param kwargs Other keyword arguments required for instantiating a Task (e.g., 'config')
74  """
75  Task.__init__(self, **kwargs)
76  if not refObjLoader:
77  self.makeSubtask("refObjLoader", butler=butler)
78  else:
79  self.refObjLoader = refObjLoader
80 
81  def run(self, catalog, filterName=None):
82  """!Load reference objects and match to them
83 
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)
88  """
89  circle = self.calculateCircle(catalog)
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)
96 
97  def calculateCircle(self, catalog):
98  """!Calculate a circle enclosing the catalog
99 
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)
102  """
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)
Simple matching of a source catalog to a reference catalog.
Definition: directMatch.py:19
def run(self, catalog, filterName=None)
Load reference objects and match to them.
Definition: directMatch.py:81
def calculateCircle(self, catalog)
Calculate a circle enclosing the catalog.
Definition: directMatch.py:97
def __init__(self, butler=None, refObjLoader=None, kwargs)
Ctor.
Definition: directMatch.py:65