191 def apply(self, candidateList, spatialKernel, spatialBackground, dof=0):
192 """Evaluate the QA metrics for all KernelCandidates in the
193 candidateList; set the values of the metrics in their
194 associated Sources"""
195 for kernelCandidate
in candidateList:
196 source = kernelCandidate.getSource()
197 schema = source.schema
200 if kernelCandidate.getStatus() != afwMath.SpatialCellCandidate.UNKNOWN:
201 kType = getattr(diffimLib.KernelCandidateF,
"ORIG")
202 di = kernelCandidate.getDifferenceImage(kType)
203 kernelValues = kernelCandidate.getKernel(kType).getKernelParameters()
204 kernelValues = np.asarray(kernelValues)
206 lkim = kernelCandidate.getKernelImage(kType)
208 stdx, stdy =
calcWidth(lkim.getArray(), centx, centy)
214 metrics = {
"KCDiffimMean_LOCAL":localResults[
"mean"],
215 "KCDiffimMedian_LOCAL":localResults[
"median"],
216 "KCDiffimIQR_LOCAL":localResults[
"iqr"],
217 "KCDiffimStDev_LOCAL":localResults[
"stdev"],
218 "KCDiffimKSD_LOCAL":localResults[
"D"],
219 "KCDiffimKSProb_LOCAL":localResults[
"prob"],
220 "KCDiffimADA2_LOCAL":localResults[
"A2"],
221 "KCDiffimADCrit_LOCAL":localResults[
"crit"],
222 "KCDiffimADSig_LOCAL":localResults[
"sig"],
223 "KCDiffimChiSq_LOCAL":localResults[
"rchisq"],
224 "KCDiffimMseResids_LOCAL":localResults[
"mseResids"],
225 "KCKernelCentX_LOCAL":centx,
226 "KCKernelCentY_LOCAL":centy,
227 "KCKernelStdX_LOCAL":stdx,
228 "KCKernelStdY_LOCAL":stdy,
229 "KernelCandidateId_LOCAL":kernelCandidate.getId(),
230 "KernelCoeffValues_LOCAL":kernelValues}
231 for k
in metrics.keys():
232 key = schema[k].asKey()
233 setter = getattr(source,
"set"+key.getTypeString())
234 setter(key, metrics[k])
237 kType = getattr(diffimLib.KernelCandidateF,
"ORIG")
238 lkim = kernelCandidate.getKernelImage(kType)
244 skim = afwImage.ImageD(spatialKernel.getDimensions())
245 spatialKernel.computeImage(skim,
False, kernelCandidate.getXCenter(),
246 kernelCandidate.getYCenter())
248 stdx, stdy =
calcWidth(skim.getArray(), centx, centy)
251 sbg = spatialBackground(kernelCandidate.getXCenter(), kernelCandidate.getYCenter())
252 di = kernelCandidate.getDifferenceImage(sk, sbg)
258 bias = np.mean(skim.getArray())
259 variance = np.mean(np.power(skim.getArray(), 2.))
260 mseKernel = bias**2 + variance
264 metrics = {
"KCDiffimMean_SPATIAL":spatialResults[
"mean"],
265 "KCDiffimMedian_SPATIAL":spatialResults[
"median"],
266 "KCDiffimIQR_SPATIAL":spatialResults[
"iqr"],
267 "KCDiffimStDev_SPATIAL":spatialResults[
"stdev"],
268 "KCDiffimKSD_SPATIAL":spatialResults[
"D"],
269 "KCDiffimKSProb_SPATIAL":spatialResults[
"prob"],
270 "KCDiffimADA2_SPATIAL":spatialResults[
"A2"],
271 "KCDiffimADCrit_SPATIAL":spatialResults[
"crit"],
272 "KCDiffimADSig_SPATIAL":spatialResults[
"sig"],
273 "KCDiffimChiSq_SPATIAL":spatialResults[
"rchisq"],
274 "KCDiffimMseResids_SPATIAL":spatialResults[
"mseResids"],
275 "KCDiffimMseKernel_SPATIAL":mseKernel,
276 "KCKernelCentX_SPATIAL":centx,
277 "KCKernelCentY_SPATIAL":centy,
278 "KCKernelStdX_SPATIAL":stdx,
279 "KCKernelStdY_SPATIAL":stdy,
280 "KernelCandidateId_SPATIAL":kernelCandidate.getId()}
281 for k
in metrics.keys():
282 key = schema[k].asKey()
283 setter = getattr(source,
"set"+key.getTypeString())
284 setter(key, metrics[k])