130 {
131
134 if (kCandidate == NULL) {
135 LOGL_DEBUG(
"TRACE2.ip.diffim.BuildSingleKernelVisitor.processCandidate",
136 "Failed to cast SpatialCellCandidate to KernelCandidate %d",
137 kCandidate->
getId());
139 "Failed to cast SpatialCellCandidate to KernelCandidate");
140 }
141
143 return;
144 }
145
146 LOGL_DEBUG(
"TRACE1.ip.diffim.BuildSingleKernelVisitor.processCandidate",
147 "Processing candidate %d", kCandidate->
getId());
148 LOGL_DEBUG(
"TRACE4.ip.diffim.BuildSingleKernelVisitor.processCandidate",
149 "X = %.2f Y = %.2f",
152
153
154 try {
155 if (_useRegularization)
156 kCandidate->
build(_basisList, _hMat);
157 else
158 kCandidate->
build(_basisList);
159
161 kCandidate->
setStatus(afwMath::SpatialCellCandidate::BAD);
162 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
163 "Unable to process candidate %d; exception caught (%s)",
166 _nRejected += 1;
167 return;
168 }
169
170 if (kCandidate->
getStatus() == afwMath::SpatialCellCandidate::BAD) {
171 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
172 "Candidate %d Returned BAD upon build, exiting",
173 kCandidate->
getId());
174 _nRejected += 1;
175 return;
176 }
177
178
179
180
181
182
184 try {
185 if (_useCoreStats)
186 _imstats.apply(diffim, _coreRadius);
187 else
188 _imstats.apply(diffim);
190 LOGL_DEBUG(
"TRACE2.ip.diffim.BuildSingleKernelVisitor.processCandidate",
191 "Unable to calculate imstats for Candidate %d", kCandidate->
getId());
192 kCandidate->
setStatus(afwMath::SpatialCellCandidate::BAD);
193 return;
194 }
195 _nProcessed += 1;
196
197 kCandidate->
setChi2(_imstats.getVariance());
198
199
200
203
204 LOGL_DEBUG(
"TRACE4.ip.diffim.BuildSingleKernelVisitor.processCandidate",
205 "Chi2 = %.3f", kCandidate->
getChi2());
206 LOGL_DEBUG(
"TRACE4.ip.diffim.BuildSingleKernelVisitor.processCandidate",
207 "Kernel Sum = %.3f", kSum);
208 LOGL_DEBUG(
"TRACE4.ip.diffim.BuildSingleKernelVisitor.processCandidate",
209 "Background = %.3f", background);
210 LOGL_DEBUG(
"TRACE2.ip.diffim.BuildSingleKernelVisitor.processCandidate",
211 "Candidate %d resids = %.3f +/- %.3f sigma (%d pix)",
213 _imstats.getMean(),
214 _imstats.getRms(),
215 _imstats.getNpix());
216
217 bool meanIsNan =
std::isnan(_imstats.getMean());
218 bool rmsIsNan =
std::isnan(_imstats.getRms());
219 if (meanIsNan || rmsIsNan) {
220 kCandidate->
setStatus(afwMath::SpatialCellCandidate::BAD);
221 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
222 "Rejecting candidate %d, encountered NaN",
223 kCandidate->
getId());
224 _nRejected += 1;
225 return;
226 }
227
228 if (_ps->getAsBool("singleKernelClipping")) {
229 if (
fabs(_imstats.getMean()) > _ps->getAsDouble(
"candidateResidualMeanMax")) {
230 kCandidate->
setStatus(afwMath::SpatialCellCandidate::BAD);
231 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
232 "Rejecting candidate %d; bad mean residual : |%.3f| > %.3f",
234 _imstats.getMean(),
235 _ps->getAsDouble("candidateResidualMeanMax"));
236 _nRejected += 1;
237 }
238 else if (_imstats.getRms() > _ps->getAsDouble("candidateResidualStdMax")) {
239 kCandidate->
setStatus(afwMath::SpatialCellCandidate::BAD);
240 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
241 "Rejecting candidate %d; bad residual rms : %.3f > %.3f",
243 _imstats.getRms(),
244 _ps->getAsDouble("candidateResidualStdMax"));
245 _nRejected += 1;
246 }
247 else {
248 kCandidate->
setStatus(afwMath::SpatialCellCandidate::GOOD);
249 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
250 "Source kernel OK");
251 }
252 }
253 else {
254 kCandidate->
setStatus(afwMath::SpatialCellCandidate::GOOD);
255 LOGL_DEBUG(
"TRACE5.ip.diffim.BuildSingleKernelVisitor.processCandidate",
256 "Sigma clipping not enabled");
257 }
258
259
260 if (!(_useCoreStats)) {
261 try {
262 _imstats.apply(diffim, _coreRadius);
264 LOGL_DEBUG(
"TRACE2.ip.diffim.BuildSingleKernelVisitor.processCandidate",
265 "Unable to calculate core imstats for Candidate %d",
266 kCandidate->
getId());
267 kCandidate->
setStatus(afwMath::SpatialCellCandidate::BAD);
268 return;
269 }
270 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
271 "Candidate %d core resids = %.3f +/- %.3f sigma (%d pix)",
273 _imstats.getMean(),
274 _imstats.getRms(),
275 _imstats.getNpix());
276 }
277
278 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
float getYCenter() const
Return the object's row-centre.
float getXCenter() const
Return the object's column-centre.
int getId() const
Return the candidate's unique ID.
void setStatus(Status status)
Set the candidate's status.
Status getStatus() const
Return the candidate's status.
double getChi2() const
Return the candidate's chi^2.
void setChi2(double chi2)
Set the candidate's chi^2.
Class stored in SpatialCells for spatial Kernel fitting.
bool isInitialized() const
afw::image::MaskedImage< PixelT > getDifferenceImage(CandidateSwitch cand)
Calculate associated difference image using internal solutions.
double getBackground(CandidateSwitch cand) const
double getKsum(CandidateSwitch cand) const
void build(afw::math::KernelList const &basisList)
Core functionality of KernelCandidate, to build and fill a KernelSolution.
Provides consistent interface for LSST exceptions.
virtual char const * what(void) const noexcept
Return a character string summarizing this exception.
Reports errors in the logical structure of the program.