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