136 def run(self, butler, coaddSources, ccdInputs, coaddWcs, visitCatalogs=None, wcsUpdates=None):
137 """Propagate flags from individual visit measurements to coadd.
138
139 This requires matching the coadd source catalog to each of the catalogs
140 from the inputs, and thresholding on the number of times a source is
141 flagged on the input catalog. The threshold is made on the relative
142 occurrence of the flag in each source. Flagging a source that is always
143 flagged in inputs corresponds to a threshold of 1, while flagging a
144 source that is flagged in any of the input corresponds to a threshold of
145 0. But neither of these extrema are really useful in practise.
146
147 Setting the threshold too high means that sources that are not consistently
148 flagged (e.g., due to chip gaps) will not have the flag propagated. Setting
149 that threshold too low means that random sources which are falsely flagged in
150 the inputs will start to dominate. If in doubt, we suggest making this threshold
151 relatively low, but not zero (e.g., 0.1 to 0.2 or so). The more confidence in
152 the quality of the flagging, the lower the threshold can be.
153
154 The relative occurrence accounts for the edge of the field-of-view of
155 the camera, but does not include chip gaps, bad or saturated pixels, etc.
156
157 Parameters
158 ----------
159 butler : `Unknown`
160 Data butler, for retrieving the input source catalogs.
161 coaddSources : `lsst.afw.image.SourceCatalog`
162 Source catalog from the coadd.
163 ccdInputs : `lsst.afw.table.ExposureCatalog`
164 Table of CCDs that contribute to the coadd.
165 coaddWcs : `lsst.afw.geom.SkyWcs`
166 Wcs for coadd.
167 visitCatalogs : `list` of `lsst.afw.image.SourceCatalog`, optional
168 List of loaded source catalogs for each input ccd in
169 the coadd. If provided this is used instead of this
170 method loading in the catalogs itself.
171 wcsUpdates : `list` of `lsst.afw.geom.SkyWcs`, optional
172 If visitCatalogs is a list of ccd catalogs, this
173 should be a list of updated wcs to apply.
174
175 Raises
176 ------
177 ValueError
178 Raised if any of the following occur:
179 - A list of wcs updates for each catalog is not supplied in the wcsUpdates parameter
180 and ccdInputs is a list of src catalogs.
181 - The visitCatalogs and ccdInput parameters are both `None`.
182 """
183 if len(self.config.flags) == 0:
184 return
185
186 flags = self._keys.keys()
187 counts = dict((f, numpy.zeros(len(coaddSources), dtype=int)) for f in flags)
188 indices = numpy.array([s.getId() for s in coaddSources])
189 radius = self.config.matchRadius*geom.arcseconds
190
191 def processCcd(ccdSources, wcsUpdate):
192 for sourceRecord in ccdSources:
193 sourceRecord.updateCoord(wcsUpdate)
194 for flag in flags:
195
196
197
198
200 mc.findOnlyClosest = False
202 for m in matches:
203 index = (numpy.where(indices == m.first.getId()))[0][0]
204 counts[flag][index] += 1
205
206 if visitCatalogs is not None:
207 if wcsUpdates is None:
208 raise pexExceptions.ValueError("If ccdInputs is a list of src catalogs, a list of wcs"
209 " updates for each catalog must be supplied in the "
210 "wcsUpdates parameter")
211 for i, ccdSource in enumerate(visitCatalogs):
212 processCcd(ccdSource, wcsUpdates[i])
213 else:
214 if ccdInputs is None:
215 raise pexExceptions.ValueError("The visitCatalogs and ccdInput parameters can't both be None")
216 visitKey = ccdInputs.schema.find("visit").key
217 ccdKey = ccdInputs.schema.find("ccd").key
218
219 self.log.info("Propagating flags %s from inputs", flags)
220
221
222 for ccdRecord in ccdInputs:
223 v = ccdRecord.get(visitKey)
224 c = ccdRecord.get(ccdKey)
225 dataId = {"visit": int(v), self.config.ccdName: int(c)}
226 ccdSources = butler.get("src", dataId=dataId)
227 processCcd(ccdSources, ccdRecord.getWcs())
228
229
230 for f in flags:
231 key = self._keys[f]
232 for s, num in zip(coaddSources, counts[f]):
233 numOverlaps = len(ccdInputs.subsetContaining(s.getCentroid(), coaddWcs, True))
234 s.setFlag(key, bool(num > numOverlaps*self.config.flags[f]))
235 self.log.info("Propagated %d sources with flag %s", sum(s.get(key) for s in coaddSources), f)
Pass parameters to algorithms that match list of sources.
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...