22 #define DEBUG_IMAGES 0
53 template<
typename PixelT>
60 _spatialKernel(spatialKernel),
61 _spatialBackground(spatialBackground),
67 _useCoreStats(ps.getAsBool(
"useCoreStats")),
68 _coreRadius(ps.getAsInt(
"candidateCoreRadius"))
71 template<
typename PixelT>
77 if (kCandidate == NULL) {
79 "Failed to cast SpatialCellCandidate to KernelCandidate");
83 LOGL_DEBUG(
"TRACE2.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
84 "Cannot process candidate %d, continuing", kCandidate->
getId());
88 LOGL_DEBUG(
"TRACE1.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
89 "Processing candidate %d", kCandidate->
getId());
97 double kSum = _spatialKernel->computeImage(kImage,
false,
108 kImage.
writeFits(str(boost::format(
"askv_k%d.fits") % kCandidate->
getId()));
109 diffim.writeFits(str(boost::format(
"askv_d%d.fits") % kCandidate->
getId()));
115 _imstats.apply(diffim, _coreRadius);
117 _imstats.apply(diffim);
119 LOGL_DEBUG(
"TRACE2.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
120 "Unable to calculate imstats for Candidate %d", kCandidate->
getId());
127 LOGL_DEBUG(
"TRACE4.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
128 "Chi2 = %.3f", _imstats.getVariance());
129 LOGL_DEBUG(
"TRACE4.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
133 LOGL_DEBUG(
"TRACE4.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
134 "Kernel Sum = %.3f", kSum);
135 LOGL_DEBUG(
"TRACE4.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
136 "Background = %.3f", background);
137 LOGL_DEBUG(
"TRACE2.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
138 "Candidate %d resids = %.3f +/- %.3f sigma (%d pix)",
144 bool meanIsNan =
std::isnan(_imstats.getMean());
145 bool rmsIsNan =
std::isnan(_imstats.getRms());
146 if (meanIsNan || rmsIsNan) {
148 LOGL_DEBUG(
"TRACE3.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
149 "Rejecting candidate %d, encountered NaN",
150 kCandidate->
getId());
155 if (_ps->getAsBool(
"spatialKernelClipping")) {
156 if (fabs(_imstats.getMean()) > _ps->getAsDouble(
"candidateResidualMeanMax")) {
158 LOGL_DEBUG(
"TRACE3.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
159 "Rejecting candidate %d; bad mean residual : |%.3f| > %.3f",
162 _ps->getAsDouble(
"candidateResidualMeanMax"));
165 else if (_imstats.getRms() > _ps->getAsDouble(
"candidateResidualStdMax")) {
167 LOGL_DEBUG(
"TRACE3.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
168 "Rejecting candidate %d; bad residual rms : %.3f > %.3f",
171 _ps->getAsDouble(
"candidateResidualStdMax"));
176 LOGL_DEBUG(
"TRACE3.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
177 "Spatial kernel OK");
183 LOGL_DEBUG(
"TRACE5.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
184 "Sigma clipping not enabled");
189 if (!(_useCoreStats)) {
191 _imstats.apply(diffim, _coreRadius);
193 LOGL_DEBUG(
"TRACE2.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
194 "Unable to calculate core imstats for Candidate %d",
195 kCandidate->
getId());
199 LOGL_DEBUG(
"TRACE3.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
200 "Candidate %d core resids = %.3f +/- %.3f sigma (%d pix)",