lsst.meas.astrom  14.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
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 .createMatchMetadata import MatchMetadata
8 from lsst.meas.algorithms import LoadIndexedReferenceObjectsTask
9 import lsst.afw.table as afwTable
10 import lsst.afw.coord as afwCoord
11 from lsst.afw.geom import arcseconds
12 
13 
14 class DirectMatchConfig(Config):
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")
18 
19 
20 class DirectMatchTask(Task):
21  """!Simple matching of a source catalog to a reference catalog
22 
23  @anchor DirectMatchTask_
24 
25  @section meas_astrom_match_Contents Contents
26 
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
32 
33  @section meas_astrom_match_Purpose Description
34 
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.
39 
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.
42 
43  @section meas_astrom_match_Initialize Task initialisation
44 
45  @copydoc \_\_init\_\_
46 
47  @section meas_astrom_match_IO Invoking the Task
48 
49  @copydoc run
50 
51  @section meas_astrom_match_Config Configuration parameters
52 
53  See @ref DirectMatchConfig
54 
55  @section meas_astrom_match_Example A complete example of using DirectMatchTask
56 
57  config = DirectMatchConfig()
58  task = DirectMatchTask(butler=butler, config=config)
59  matchResults = task.run(catalog)
60 
61  """
62 
63  ConfigClass = DirectMatchConfig
64  _DefaultName = "directMatch"
65 
66  def __init__(self, butler=None, refObjLoader=None, **kwargs):
67  """!Ctor
68 
69  Either a 'butler' or 'refObjLoader' is required.
70 
71  @param butler Data butler, or None
72  @param refObjLoader For loading reference objects (lsst.meas.algorithms.LoadReferenceObjectsTask), or
73  None
74  @param kwargs Other keyword arguments required for instantiating a Task (e.g., 'config')
75  """
76  Task.__init__(self, **kwargs)
77  if not refObjLoader:
78  self.makeSubtask("refObjLoader", butler=butler)
79  else:
80  self.refObjLoader = refObjLoader
81 
82  def run(self, catalog, filterName=None):
83  """!Load reference objects and match to them
84 
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)
89  """
90  circle = self.calculateCircle(catalog)
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)
97 
98  def calculateCircle(self, catalog):
99  """!Calculate a circle enclosing the catalog
100 
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)
103  """
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.
Definition: directMatch.py:82
Simple matching of a source catalog to a reference catalog.
Definition: directMatch.py:20
def calculateCircle
Calculate a circle enclosing the catalog.
Definition: directMatch.py:98