LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
directMatch.py
Go to the documentation of this file.
1 
2 __all__ = ["DirectMatchConfig", "DirectMatchTask", "DirectMatchConfigWithoutLoader"]
3 
4 from lsst.pex.config import Config, Field, ConfigurableField
5 from lsst.pipe.base import Task, Struct
6 from lsst.meas.algorithms import (LoadIndexedReferenceObjectsTask, ScienceSourceSelectorTask,
7  ReferenceSourceSelectorTask)
8 import lsst.afw.table as afwTable
9 from lsst.geom import arcseconds, averageSpherePoint
10 
11 
13  """Configuration for `DirectMatchTask` when an already-initialized
14  ``refObjLoader`` will be passed to this task.
15  """
16  matchRadius = Field(dtype=float, default=0.25, doc="Matching radius, arcsec")
17  sourceSelection = ConfigurableField(target=ScienceSourceSelectorTask,
18  doc="Selection of science sources")
19  referenceSelection = ConfigurableField(target=ReferenceSourceSelectorTask,
20  doc="Selection of reference sources")
21 
22 
24  """Configuration for `DirectMatchTask`.
25  """
26  refObjLoader = ConfigurableField(target=LoadIndexedReferenceObjectsTask, doc="Load reference objects")
27 
28 
30  """Simple, brute force matching of a source catalog to a reference catalog.
31 
32  Parameters
33  ----------
34  butler : `lsst.daf.persistence.Butler`
35  Data butler containing the relevant reference catalog data.
36  refObjLoader : `lsst.meas.algorithms.LoadReferenceObjectsTask` or `None`
37  For loading reference objects.
38  **kwargs
39  Other keyword arguments required for instantiating a Task (such as
40  ``config``).
41  """
42  ConfigClass = DirectMatchConfig
43  _DefaultName = "directMatch"
44 
45  def __init__(self, butler=None, refObjLoader=None, **kwargs):
46  Task.__init__(self, **kwargs)
47  if not refObjLoader:
48  if butler:
49  if not isinstance(self.configconfig, DirectMatchConfig):
50  raise RuntimeError("DirectMatchTask must be initialized with DirectMatchConfig "
51  "if a refObjLoader is not supplied at initialization")
52  self.makeSubtaskmakeSubtask("refObjLoader", butler=butler)
53  else:
54  self.refObjLoaderrefObjLoader = None
55 
56  else:
57  self.refObjLoaderrefObjLoader = refObjLoader
58  self.makeSubtaskmakeSubtask("sourceSelection")
59  self.makeSubtaskmakeSubtask("referenceSelection")
60 
61  def setRefObjLoader(self, refObjLoader):
62  """Set the reference object loader for the task.
63 
64  Parameters
65  ----------
66  refObjLoader
67  An instance of a reference object loader, either a
68  `lsst.meas.algorithms.LoadReferenceObjectsTask` task or a
69  `lsst.meas.algorithms.ReferenceObjectLoader` instance. A task can
70  be used as a subtask and is generally used in gen2 middleware. The
71  class is designed to be used with gen3 middleware and is
72  initialized outside the normal task framework.
73  """
74  self.refObjLoaderrefObjLoader = refObjLoader
75 
76  def run(self, catalog, filterName=None, epoch=None):
77  """Load reference objects and match to them.
78 
79  Parameters
80  ----------
81  catalog : `lsst.afw.table.SourceCatalog`
82  Catalog to match.
83  filterName : `str`
84  Name of filter loading fluxes.
85  epoch : `astropy.time.Time` or `None`
86  Epoch to which to correct proper motion and parallax, or `None` to
87  not apply such corrections.
88 
89  Returns
90  -------
91  result : `lsst.pipe.base.Struct`
92  Result struct with components:
93 
94  ``matches``
95  Matched sources with associated reference
96  (`lsst.afw.table.SourceMatchVector`).
97  ``matchMeta``
98  Match metadata (`lsst.meas.astrom.MatchMetadata`).
99  """
100  if self.refObjLoaderrefObjLoader is None:
101  raise RuntimeError("Running matcher task with no refObjLoader set in __ini__ or setRefObjLoader")
102  circle = self.calculateCirclecalculateCircle(catalog)
103  matchMeta = self.refObjLoaderrefObjLoader.getMetadataCircle(circle.center, circle.radius, filterName, epoch=epoch)
104  emptyResult = Struct(matches=[], matchMeta=matchMeta)
105  sourceSelection = self.sourceSelection.run(catalog)
106  if len(sourceSelection.sourceCat) == 0:
107  self.loglog.warn("No objects selected from %d objects in source catalog", len(catalog))
108  return emptyResult
109  refData = self.refObjLoaderrefObjLoader.loadSkyCircle(circle.center, circle.radius, filterName, epoch=epoch)
110  refCat = refData.refCat
111  refSelection = self.referenceSelection.run(refCat)
112  if len(refSelection.sourceCat) == 0:
113  self.loglog.warn("No objects selected from %d objects in reference catalog", len(refCat))
114  return emptyResult
115  matches = afwTable.matchRaDec(refSelection.sourceCat, sourceSelection.sourceCat,
116  self.configconfig.matchRadius*arcseconds)
117  self.loglog.info("Matched %d from %d/%d input and %d/%d reference sources" %
118  (len(matches), len(sourceSelection.sourceCat), len(catalog),
119  len(refSelection.sourceCat), len(refCat)))
120  return Struct(matches=matches, matchMeta=matchMeta, refCat=refCat, sourceSelection=sourceSelection,
121  refSelection=refSelection)
122 
123  def calculateCircle(self, catalog):
124  """Calculate a circle enclosing the catalog.
125 
126  Parameters
127  ----------
128  catalog : `lsst.afw.table.SourceCatalog`
129  Catalog to encircle.
130 
131  Returns
132  -------
133  result : `lsst.pipe.base.Struct`
134  Result struct with components:
135 
136  ``center``
137  ICRS center coordinate (`lsst.afw.geom.SpherePoint`).
138  ``radius``
139  Radius of the circle (`lsst.geom.Angle`).
140  """
141  coordList = [src.getCoord() for src in catalog]
142  center = averageSpherePoint(coordList)
143  radius = max(center.separation(coord) for coord in coordList)
144  return Struct(center=center, radius=radius + self.configconfig.matchRadius*arcseconds)
int max
def run(self, catalog, filterName=None, epoch=None)
Definition: directMatch.py:76
def __init__(self, butler=None, refObjLoader=None, **kwargs)
Definition: directMatch.py:45
def makeSubtask(self, name, **keyArgs)
Definition: task.py:299
std::vector< Match< typename Cat1::Record, typename Cat2::Record > > matchRaDec(Cat1 const &cat1, Cat2 const &cat2, lsst::geom::Angle 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...
Definition: Match.cc:158
SpherePoint averageSpherePoint(std::vector< SpherePoint > const &coords)
Return the average of a list of coordinates.
Definition: SpherePoint.cc:235
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations.