LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
KernelSumVisitor.cc
Go to the documentation of this file.
1// -*- lsst-c++ -*-
11#include <limits>
12
13#include "lsst/afw/math.h"
14#include "lsst/log/Log.h"
17
20
21namespace afwMath = lsst::afw::math;
22namespace dafBase = lsst::daf::base;
24
25namespace lsst {
26namespace ip {
27namespace diffim {
28namespace detail {
29
64 template<typename PixelT>
67 ) :
68 afwMath::CandidateVisitor(),
69 _mode(AGGREGATE),
70 _kSums(std::vector<double>()),
71 _kSumMean(0.),
72 _kSumStd(0.),
73 _dkSumMax(0.),
74 _kSumNpts(0),
75 _nRejected(0),
76 _ps(ps.deepCopy())
77 {};
78
79 template<typename PixelT>
81 _kSums.clear();
82 _kSumMean = 0.;
83 _kSumStd = 0.;
84 _dkSumMax = 0.;
85 _kSumNpts = 0;
86 _nRejected = 0;
87 }
88
89 template<typename PixelT>
91 *candidate) {
92
93 KernelCandidate<PixelT> *kCandidate = dynamic_cast<KernelCandidate<PixelT> *>(candidate);
94 if (kCandidate == NULL) {
96 "Failed to cast SpatialCellCandidate to KernelCandidate");
97 }
98 LOGL_DEBUG("TRACE5.ip.diffim.KernelSumVisitor.processCandidate",
99 "Processing candidate %d, mode %d", kCandidate->getId(), _mode);
100
101 /* Grab all kernel sums and look for outliers */
102 if (_mode == AGGREGATE) {
103 _kSums.push_back(kCandidate->getKernelSolution(KernelCandidate<PixelT>::ORIG)->getKsum());
104 }
105 else if (_mode == REJECT) {
106 if (_ps->getAsBool("kernelSumClipping")) {
107 double kSum =
108 kCandidate->getKernelSolution(KernelCandidate<PixelT>::ORIG)->getKsum();
109
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)",
114 kCandidate->getId(),
115 kSum);
116 _nRejected += 1;
117 }
118 }
119 else {
120 LOGL_DEBUG("TRACE5.ip.diffim.KernelSumVisitor.processCandidate",
121 "Sigma clipping not enabled");
122 }
123 }
124 }
125
126 template<typename PixelT>
128 if (_kSums.size() == 0) {
130 "Unable to determine kernel sum; 0 candidates");
131 }
132 else if (_kSums.size() == 1) {
133 LOGL_DEBUG("TRACE1.ip.diffim.KernelSumVisitor.processKsumDistribution",
134 "WARNING: only 1 kernel candidate");
135
136 _kSumMean = _kSums[0];
137 _kSumStd = 0.0;
138 _kSumNpts = 1;
139 }
140 else {
141 try {
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");
151 throw e;
152 }
153 if (std::isnan(_kSumMean)) {
155 str(boost::format("Mean kernel sum returns NaN (%d points)")
156 % _kSumNpts));
157 }
158 if (std::isnan(_kSumStd)) {
160 str(boost::format("Kernel sum stdev returns NaN (%d points)")
161 % _kSumNpts));
162 }
163 }
164 _dkSumMax = _ps->getAsDouble("maxKsumSigma") * _kSumStd;
165 LOGL_DEBUG("TRACE1.ip.diffim.KernelSumVisitor.processCandidate",
166 "Kernel Sum Distribution : %.3f +/- %.3f (%d points)",
167 _kSumMean, _kSumStd, _kSumNpts);
168 }
169
170 typedef float PixelT;
171
172 template class KernelSumVisitor<PixelT>;
173
176
177}}}} // end of namespace lsst::ip::diffim::detail
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it.
Definition Exception.h:54
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
Class used by SpatialModelCell for spatial Kernel fitting.
Declaration of KernelSumVisitor.
LSST DM logging module built on log4cxx.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition Log.h:515
Base class for candidate objects in a SpatialCell.
Definition SpatialCell.h:70
int getId() const
Return the candidate's unique ID.
void setStatus(Status status)
Set the candidate's status.
A class to evaluate image statistics.
Definition Statistics.h:222
Class for storing generic metadata.
Definition PropertySet.h:66
Class stored in SpatialCells for spatial Kernel fitting.
std::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
A class to accumulate kernel sums across SpatialCells.
KernelSumVisitor(lsst::daf::base::PropertySet const &ps)
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)
Provides consistent interface for LSST exceptions.
Definition Exception.h:107
Reports errors in the logical structure of the program.
Definition Runtime.h:46
Reports errors that are due to events beyond the control of the program.
Definition Runtime.h:104
T isnan(T... args)
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
Definition Statistics.h:361
@ STDEVCLIP
estimate sample N-sigma clipped stdev (N set in StatisticsControl, default=3)
Definition Statistics.h:63
@ MEANCLIP
estimate sample N-sigma clipped mean (N set in StatisticsControl, default=3)
Definition Statistics.h:62
@ NPOINT
number of sample points
Definition Statistics.h:56
template std::shared_ptr< KernelSumVisitor< PixelT > > makeKernelSumVisitor< PixelT >(lsst::daf::base::PropertySet const &)
STL namespace.