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