LSST Applications g180d380827+0f66a164bb,g2079a07aa2+86d27d4dc4,g2305ad1205+7d304bc7a0,g29320951ab+500695df56,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+e42ea45bea,g48712c4677+36a86eeaa5,g487adcacf7+2dd8f347ac,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+c70619cc9d,g5a732f18d5+53520f316c,g5ea96fc03c+341ea1ce94,g64a986408d+f7cd9c7162,g858d7b2824+f7cd9c7162,g8a8a8dda67+585e252eca,g99cad8db69+469ab8c039,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+c92fc63c7e,gbd866b1f37+f7cd9c7162,gc120e1dc64+02c66aa596,gc28159a63d+0e5473021a,gc3e9b769f7+b0068a2d9f,gcf0d15dbbd+e42ea45bea,gdaeeff99f8+f9a426f77a,ge6526c86ff+84383d05b3,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+f7cd9c7162,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
directMatch.py
Go to the documentation of this file.
2__all__ = ["DirectMatchConfig", "DirectMatchTask", "DirectMatchConfigWithoutLoader"]
3
4from lsst.pex.config import Config, Field, ConfigurableField, ConfigField
5from lsst.pipe.base import Task, Struct
6from lsst.meas.algorithms import (LoadReferenceObjectsConfig, 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 = ConfigField(dtype=LoadReferenceObjectsConfig,
27 doc="Configuration of reference object loader")
28
29
30class DirectMatchTask(Task):
31 """Simple, brute force matching of a source catalog to a reference catalog.
32
33 Parameters
34 ----------
35 butler : `None`
36 Compatibility parameter. Should not be used.
37 refObjLoader : `lsst.meas.algorithms.ReferenceObjectLoader` or `None`
38 A reference object loader object; gen3 pipeline tasks will pass `None`
39 and call `setRefObjLoader` in `runQuantum`.
40 **kwargs
41 Other keyword arguments required for instantiating a Task (such as
42 ``config``).
43 """
44 ConfigClass = DirectMatchConfig
45 _DefaultName = "directMatch"
46
47 def __init__(self, refObjLoader=None, **kwargs):
48 Task.__init__(self, **kwargs)
49 self.refObjLoader = refObjLoader
50 self.makeSubtask("sourceSelection")
51 self.makeSubtask("referenceSelection")
52
53 def setRefObjLoader(self, refObjLoader):
54 """Set the reference object loader for the task.
55
56 Parameters
57 ----------
58 refObjLoader : `lsst.meas.algorithms.ReferenceObjectLoader`
59 An instance of a reference object loader.
60 """
61 self.refObjLoader = refObjLoader
62
63 def run(self, catalog, filterName=None, epoch=None):
64 """Load reference objects and match to them.
65
66 Parameters
67 ----------
68 catalog : `lsst.afw.table.SourceCatalog`
69 Catalog to match.
70 filterName : `str`
71 Name of filter loading fluxes.
72 epoch : `astropy.time.Time` or `None`
73 Epoch to which to correct proper motion and parallax, or `None` to
74 not apply such corrections.
75
76 Returns
77 -------
78 result : `lsst.pipe.base.Struct`
79 Result struct with components:
80
81 ``matches``
82 Matched sources with associated reference
83 (`lsst.afw.table.SourceMatchVector`).
84 ``matchMeta``
85 Match metadata (`lsst.meas.astrom.MatchMetadata`).
86 """
87 if self.refObjLoader is None:
88 raise RuntimeError("Running matcher task with no refObjLoader set in __ini__ or setRefObjLoader")
89 circle = self.calculateCircle(catalog)
90 matchMeta = self.refObjLoader.getMetadataCircle(circle.center, circle.radius, filterName, epoch=epoch)
91 emptyResult = Struct(matches=[], matchMeta=matchMeta)
92 sourceSelection = self.sourceSelection.run(catalog)
93 if len(sourceSelection.sourceCat) == 0:
94 self.log.warning("No objects selected from %d objects in source catalog", len(catalog))
95 return emptyResult
96 refData = self.refObjLoader.loadSkyCircle(circle.center, circle.radius, filterName, epoch=epoch)
97 refCat = refData.refCat
98 refSelection = self.referenceSelection.run(refCat)
99 if len(refSelection.sourceCat) == 0:
100 self.log.warning("No objects selected from %d objects in reference catalog", len(refCat))
101 return emptyResult
102 matches = afwTable.matchRaDec(refSelection.sourceCat, sourceSelection.sourceCat,
103 self.config.matchRadius*arcseconds)
104 self.log.info("Matched %d from %d/%d input and %d/%d reference sources",
105 len(matches), len(sourceSelection.sourceCat), len(catalog),
106 len(refSelection.sourceCat), len(refCat))
107 return Struct(matches=matches, matchMeta=matchMeta, refCat=refCat, sourceSelection=sourceSelection,
108 refSelection=refSelection)
109
110 def calculateCircle(self, catalog):
111 """Calculate a circle enclosing the catalog.
112
113 Parameters
114 ----------
115 catalog : `lsst.afw.table.SourceCatalog`
116 Catalog to encircle.
117
118 Returns
119 -------
120 result : `lsst.pipe.base.Struct`
121 Result struct with components:
122
123 ``center``
124 ICRS center coordinate (`lsst.afw.geom.SpherePoint`).
125 ``radius``
126 Radius of the circle (`lsst.geom.Angle`).
127 """
128 coordList = [src.getCoord() for src in catalog]
129 center = averageSpherePoint(coordList)
130 radius = max(center.separation(coord) for coord in coordList)
131 return Struct(center=center, radius=radius + self.config.matchRadius*arcseconds)
int max
__init__(self, refObjLoader=None, **kwargs)
run(self, catalog, filterName=None, epoch=None)
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