13 #include "lsst/afw/math.h"
14 #include "lsst/log/Log.h"
15 #include "lsst/pex/policy/Policy.h"
16 #include "lsst/pex/exceptions/Runtime.h"
21 namespace afwMath = lsst::afw::math;
22 namespace pexPolicy = lsst::pex::policy;
23 namespace pexExcept = lsst::pex::exceptions;
64 template<
typename PixelT>
66 lsst::pex::policy::Policy
const& policy
68 afwMath::CandidateVisitor(),
70 _kSums(std::vector<double>()),
79 template<
typename PixelT>
89 template<
typename PixelT>
94 if (kCandidate == NULL) {
95 throw LSST_EXCEPT(pexExcept::LogicError,
96 "Failed to cast SpatialCellCandidate to KernelCandidate");
98 LOGL_DEBUG(
"TRACE5.ip.diffim.KernelSumVisitor.processCandidate",
99 "Processing candidate %d, mode %d", kCandidate->getId(), _mode);
102 if (_mode == AGGREGATE) {
105 else if (_mode == REJECT) {
106 if (_policy.getBool(
"kernelSumClipping")) {
110 if (fabs(kSum - _kSumMean) > _dkSumMax) {
111 kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
112 LOGL_DEBUG(
"TRACE3.ip.diffim.KernelSumVisitor.processCandidate",
113 "Rejecting candidate %d; bad source kernel sum : (%.2f)",
120 LOGL_DEBUG(
"TRACE5.ip.diffim.KernelSumVisitor.processCandidate",
121 "Sigma clipping not enabled");
126 template<
typename PixelT>
128 if (_kSums.size() == 0) {
129 throw LSST_EXCEPT(pexExcept::Exception,
130 "Unable to determine kernel sum; 0 candidates");
132 else if (_kSums.size() == 1) {
133 LOGL_DEBUG(
"TRACE1.ip.diffim.KernelSumVisitor.processKsumDistribution",
134 "WARNING: only 1 kernel candidate");
136 _kSumMean = _kSums[0];
142 afwMath::Statistics stats = afwMath::makeStatistics(_kSums,
146 _kSumMean = stats.getValue(afwMath::MEANCLIP);
147 _kSumStd = stats.getValue(afwMath::STDEVCLIP);
148 _kSumNpts =
static_cast<int>(stats.getValue(afwMath::NPOINT));
149 }
catch (pexExcept::Exception &e) {
150 LSST_EXCEPT_ADD(e,
"Unable to calculate kernel sum statistics");
153 if (std::isnan(_kSumMean)) {
154 throw LSST_EXCEPT(pexExcept::Exception,
155 str(boost::format(
"Mean kernel sum returns NaN (%d points)")
158 if (std::isnan(_kSumStd)) {
159 throw LSST_EXCEPT(pexExcept::Exception,
160 str(boost::format(
"Kernel sum stdev returns NaN (%d points)")
164 _dkSumMax = _policy.getDouble(
"maxKsumSigma") * _kSumStd;
165 LOGL_DEBUG(
"TRACE1.ip.diffim.KernelSumVisitor.processCandidate",
166 "Kernel Sum Distribution : %.3f +/- %.3f (%d points)",
167 _kSumMean, _kSumStd, _kSumNpts);
174 template std::shared_ptr<KernelSumVisitor<PixelT> >
Class stored in SpatialCells for spatial Kernel fitting.
Declaration of KernelSumVisitor.
std::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
A class to accumulate kernel sums across SpatialCells.
void processKsumDistribution()
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)
Class used by SpatialModelCell for spatial Kernel fitting.
template std::shared_ptr< KernelSumVisitor< PixelT > > makeKernelSumVisitor< PixelT >(lsst::pex::policy::Policy const &)
KernelSumVisitor(lsst::pex::policy::Policy const &policy)