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);
106 if (
_policy.getBool(
"kernelSumClipping")) {
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>
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");
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");
154 throw LSST_EXCEPT(pexExcept::Exception,
155 str(boost::format(
"Mean kernel sum returns NaN (%d points)")
159 throw LSST_EXCEPT(pexExcept::Exception,
160 str(boost::format(
"Kernel sum stdev returns NaN (%d points)")
165 LOGL_DEBUG(
"TRACE1.ip.diffim.KernelSumVisitor.processCandidate",
166 "Kernel Sum Distribution : %.3f +/- %.3f (%d points)",
174 template std::shared_ptr<KernelSumVisitor<PixelT> >
int _kSumNpts
Number of points used in the statistics.
Mode _mode
Processing mode; AGGREGATE or REJECT.
Class stored in SpatialCells for spatial Kernel fitting.
Declaration of KernelSumVisitor.
std::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
double _kSumMean
Clipped mean of the kernel sums.
A class to accumulate kernel sums across SpatialCells.
void processKsumDistribution()
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)
double _dkSumMax
Maximum acceptable deviation from mean sum.
Class used by SpatialModelCell for spatial Kernel fitting.
double _kSumStd
Clipped standard deviation of kernel sums.
template std::shared_ptr< KernelSumVisitor< PixelT > > makeKernelSumVisitor< PixelT >(lsst::pex::policy::Policy const &)
std::vector< double > _kSums
List of all candidate kernel sums.
KernelSumVisitor(lsst::pex::policy::Policy const &policy)
int _nRejected
Number of candidates rejected during processCandidate()
lsst::pex::policy::Policy _policy
Policy controlling behavior.