LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
directMatch.py
Go to the documentation of this file.
2__all__ = ["DirectMatchConfig", "DirectMatchTask", "DirectMatchConfigWithoutLoader"]
3
4from lsst.pex.config import Config, Field, ConfigurableField
5from lsst.pipe.base import Task, Struct
6from lsst.meas.algorithms import (LoadIndexedReferenceObjectsTask, ScienceSourceSelectorTask,
7 ReferenceSourceSelectorTask)
8import lsst.afw.table as afwTable
9from 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
29class DirectMatchTask(Task):
30 """Simple, brute force matching of a source catalog to a reference catalog.
31
32 Parameters
33 ----------
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.config, DirectMatchConfig):
50 raise RuntimeError("DirectMatchTask must be initialized with DirectMatchConfig "
51 "if a refObjLoader is not supplied at initialization")
52 self.makeSubtask("refObjLoader", butler=butler)
53 else:
54 self.refObjLoaderrefObjLoader = None
55
56 else:
57 self.refObjLoaderrefObjLoader = refObjLoader
58 self.makeSubtask("sourceSelection")
59 self.makeSubtask("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
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 ----------
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
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.log.warning("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.log.warning("No objects selected from %d objects in reference catalog", len(refCat))
114 return emptyResult
115 matches = afwTable.matchRaDec(refSelection.sourceCat, sourceSelection.sourceCat,
116 self.config.matchRadius*arcseconds)
117 self.log.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 ----------
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.config.matchRadius*arcseconds)
int max
table::Key< int > to
A class representing an angle.
Definition: Angle.h:128
def run(self, catalog, filterName=None, epoch=None)
Definition: directMatch.py:76
def __init__(self, butler=None, refObjLoader=None, **kwargs)
Definition: directMatch.py:45
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.