87 template<
typename PixelT>
94 _basisList(basisList),
101 _useRegularization(false),
102 _useCoreStats(ps.getAsBool(
"useCoreStats")),
103 _coreRadius(ps.getAsInt(
"candidateCoreRadius"))
106 template<
typename PixelT>
111 Eigen::MatrixXd
const& hMat
114 _basisList(basisList),
121 _useRegularization(true),
122 _useCoreStats(ps.getAsBool(
"useCoreStats")),
123 _coreRadius(ps.getAsInt(
"candidateCoreRadius"))
127 template<
typename PixelT>
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");
146 LOGL_DEBUG(
"TRACE1.ip.diffim.BuildSingleKernelVisitor.processCandidate",
147 "Processing candidate %d", kCandidate->
getId());
148 LOGL_DEBUG(
"TRACE4.ip.diffim.BuildSingleKernelVisitor.processCandidate",
155 if (_useRegularization)
156 kCandidate->
build(_basisList, _hMat);
158 kCandidate->
build(_basisList);
162 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
163 "Unable to process candidate %d; exception caught (%s)",
171 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
172 "Candidate %d Returned BAD upon build, exiting",
173 kCandidate->
getId());
186 _imstats.apply(diffim, _coreRadius);
188 _imstats.apply(diffim);
190 LOGL_DEBUG(
"TRACE2.ip.diffim.BuildSingleKernelVisitor.processCandidate",
191 "Unable to calculate imstats for Candidate %d", kCandidate->
getId());
197 kCandidate->
setChi2(_imstats.getVariance());
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)",
217 bool meanIsNan =
std::isnan(_imstats.getMean());
218 bool rmsIsNan =
std::isnan(_imstats.getRms());
219 if (meanIsNan || rmsIsNan) {
221 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
222 "Rejecting candidate %d, encountered NaN",
223 kCandidate->
getId());
228 if (_ps->getAsBool(
"singleKernelClipping")) {
229 if (fabs(_imstats.getMean()) > _ps->getAsDouble(
"candidateResidualMeanMax")) {
231 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
232 "Rejecting candidate %d; bad mean residual : |%.3f| > %.3f",
235 _ps->getAsDouble(
"candidateResidualMeanMax"));
238 else if (_imstats.getRms() > _ps->getAsDouble(
"candidateResidualStdMax")) {
240 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
241 "Rejecting candidate %d; bad residual rms : %.3f > %.3f",
244 _ps->getAsDouble(
"candidateResidualStdMax"));
249 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
255 LOGL_DEBUG(
"TRACE5.ip.diffim.BuildSingleKernelVisitor.processCandidate",
256 "Sigma clipping not enabled");
260 if (!(_useCoreStats)) {
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());
270 LOGL_DEBUG(
"TRACE3.ip.diffim.BuildSingleKernelVisitor.processCandidate",
271 "Candidate %d core resids = %.3f +/- %.3f sigma (%d pix)",
291 Eigen::MatrixXd
const &);
#define LOGL_DEBUG(logger, message...)
Declaration of BuildSingleKernelVisitor.
#define LSST_EXCEPT(type,...)
Image Subtraction helper functions.
Class used by SpatialModelCell for spatial Kernel fitting.
void setStatus(Status status)
void setChi2(double chi2)
Class to calculate difference image statistics.
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.
Builds the convolution kernel for a given candidate.
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)
BuildSingleKernelVisitor(lsst::afw::math::KernelList const &basisList, lsst::daf::base::PropertySet const &ps)
virtual char const * what(void) const noexcept
template std::shared_ptr< BuildSingleKernelVisitor< PixelT > > makeBuildSingleKernelVisitor< PixelT >(lsst::afw::math::KernelList const &, lsst::daf::base::PropertySet const &)