119 def loadAndMatch(self, exposure, sourceCat):
120 """Load reference objects overlapping an exposure and match to sources
121 detected on that exposure.
122
123 Parameters
124 ----------
125 exposure : `lsst.afw.image.Exposure`
126 exposure that the sources overlap
127 sourceCat : `lsst.afw.table.SourceCatalog.`
128 catalog of sources detected on the exposure
129
130 Returns
131 -------
132 result : `lsst.pipe.base.Struct`
133 Result struct with Components:
134
135 - ``refCat`` : reference object catalog of objects that overlap the
136 exposure (`lsst.afw.table.SimpleCatalog`)
137 - ``matches`` : Matched sources and references
138 (`list` of `lsst.afw.table.ReferenceMatch`)
139 - ``matchMeta`` : metadata needed to unpersist matches
140 (`lsst.daf.base.PropertyList`)
141
142 Notes
143 -----
144 ignores config.matchDistanceSigma
145 """
146 if self.refObjLoader is None:
147 raise RuntimeError("Running matcher task with no refObjLoader set in __ini__ or setRefObjLoader")
148 import lsstDebug
150
151 epoch = exposure.visitInfo.date.toAstropy()
152
153 sourceSelection = self.sourceSelector.run(sourceCat)
154
155 sourceFluxField = "slot_%sFlux_instFlux" % (self.config.sourceFluxType)
156
157 loadRes = self.refObjLoader.loadPixelBox(
158 bbox=exposure.getBBox(),
159 wcs=exposure.wcs,
160 filterName=exposure.filter.bandLabel,
161 epoch=epoch,
162 )
163
164 refSelection = self.referenceSelector.run(loadRes.refCat)
165
166 matchMeta = self.refObjLoader.getMetadataBox(
167 bbox=exposure.getBBox(),
168 wcs=exposure.wcs,
169 filterName=exposure.filter.bandLabel,
170 epoch=epoch,
171 )
172
173 matchRes = self.matcher.matchObjectsToSources(
174 refCat=refSelection.sourceCat,
175 sourceCat=sourceSelection.sourceCat,
176 wcs=exposure.wcs,
177 sourceFluxField=sourceFluxField,
178 refFluxField=loadRes.fluxField,
179 matchTolerance=None,
180 bbox=exposure.getBBox(),
181 )
182
183 distStats = self._computeMatchStatsOnSky(matchRes.matches)
184 self.log.info(
185 "Found %d matches with scatter = %0.3f +- %0.3f arcsec; ",
186 len(matchRes.matches), distStats.distMean.asArcseconds(), distStats.distStdDev.asArcseconds()
187 )
188
189 if debug.display:
190 frame = int(debug.frame)
191 displayAstrometry(
192 refCat=refSelection.sourceCat,
193 sourceCat=sourceSelection.sourceCat,
194 matches=matchRes.matches,
195 exposure=exposure,
196 bbox=exposure.getBBox(),
197 frame=frame,
198 title="Matches",
199 )
200
201 return pipeBase.Struct(
202 refCat=loadRes.refCat,
203 refSelection=refSelection,
204 sourceSelection=sourceSelection,
205 matches=matchRes.matches,
206 matchMeta=matchMeta,
207 )
208