199 lsst.pipe.base.Task.__init__(self, **kwds)
202 apCorrNameSet = getApCorrNameSet()
203 ignoreSet = set(self.config.ignoreList)
204 missingNameSet = ignoreSet - set(apCorrNameSet)
206 self.log.
warning(
"Fields in ignoreList that are not in fluxCorrectList: %s",
207 sorted(missingNameSet))
208 for name
in sorted(apCorrNameSet - ignoreSet):
209 if name +
"_instFlux" not in schema:
214 for name, model
in self.config.proxies.items():
215 if name
in apCorrNameSet:
218 if name +
"_instFlux" not in schema:
223 def run(self, catalog, apCorrMap):
224 """Apply aperture corrections to a catalog of sources.
228 catalog : `lsst.afw.table.SourceCatalog`
229 Catalog of sources. Will be updated in place.
230 apCorrMap : `lsst.afw.image.ApCorrMap`
231 Aperture correction map
235 If you show debug-level log messages then you will see statistics for
236 the effects of aperture correction.
240 self.log.debug(
"Use naive instFlux sigma computation")
242 self.log.debug(
"Use complex instFlux sigma computation that double-counts photon noise "
243 "and thus over-estimates instFlux uncertainty")
246 periodicLog = PeriodicLogger(self.log)
249 apCorrModel = apCorrMap.get(apCorrInfo.modelName)
250 apCorrErrModel = apCorrMap.get(apCorrInfo.modelSigmaName)
251 if None in (apCorrModel, apCorrErrModel):
252 missingNames = [(apCorrInfo.modelName, apCorrInfo.modelSigmaName)[i]
253 for i, model
in enumerate((apCorrModel, apCorrErrModel))
if model
is None]
254 self.log.
warning(
"Cannot aperture correct %s because could not find %s in apCorrMap",
255 apCorrInfo.name,
" or ".join(missingNames))
256 for source
in catalog:
257 source.set(apCorrInfo.apCorrFlagKey,
True)
260 for sourceIndex, source
in enumerate(catalog):
261 center = source.getCentroid()
263 source.set(apCorrInfo.apCorrFlagKey,
True)
264 oldFluxFlagState =
False
265 if self.config.doFlagApCorrFailures:
266 oldFluxFlagState = source.get(apCorrInfo.fluxFlagKey)
267 source.set(apCorrInfo.fluxFlagKey,
True)
272 apCorr = apCorrModel.evaluate(center)
273 if not UseNaiveFluxErr:
274 apCorrErr = apCorrErrModel.evaluate(center)
278 if apCorrInfo.doApCorrColumn:
279 source.set(apCorrInfo.apCorrKey, apCorr)
280 source.set(apCorrInfo.apCorrErrKey, apCorrErr)
282 if apCorr <= 0.0
or apCorrErr < 0.0:
285 instFlux = source.get(apCorrInfo.instFluxKey)
286 instFluxErr = source.get(apCorrInfo.instFluxErrKey)
287 source.set(apCorrInfo.instFluxKey, instFlux*apCorr)
289 source.set(apCorrInfo.instFluxErrKey, instFluxErr*apCorr)
291 a = instFluxErr/instFlux
293 source.set(apCorrInfo.instFluxErrKey,
abs(instFlux*apCorr)*math.sqrt(a*a + b*b))
294 source.set(apCorrInfo.apCorrFlagKey,
False)
295 if self.config.doFlagApCorrFailures:
296 source.set(apCorrInfo.fluxFlagKey, oldFluxFlagState)
299 periodicLog.log(
"Aperture corrections applied to %d sources out of %d",
300 sourceIndex + 1,
len(catalog))
302 if self.log.isEnabledFor(self.log.DEBUG):
304 apCorrArr = np.array([s.get(apCorrInfo.apCorrKey)
for s
in catalog])
305 apCorrErrArr = np.array([s.get(apCorrInfo.apCorrErrKey)
for s
in catalog])
306 self.log.debug(
"For instFlux field %r: mean apCorr=%s, stdDev apCorr=%s, "
307 "mean apCorrErr=%s, stdDev apCorrErr=%s for %s sources",
308 apCorrInfo.name, apCorrArr.mean(), apCorrArr.std(),
309 apCorrErrArr.mean(), apCorrErrArr.std(),
len(catalog))