12 #include "boost/shared_ptr.hpp"
26 #define DEBUG_MATRIX 0
28 namespace afwMath = lsst::afw::math;
30 namespace pexLogging = lsst::pex::logging;
31 namespace pexPolicy = lsst::pex::policy;
32 namespace pexExcept = lsst::pex::exceptions;
33 namespace ipDiffim = lsst::ip::diffim;
89 template<
typename PixelT>
95 afwMath::CandidateVisitor(),
96 _basisList(basisList),
103 _useRegularization(false),
104 _useCoreStats(_policy.getBool(
"useCoreStats")),
105 _coreRadius(_policy.getInt(
"candidateCoreRadius"))
108 template<
typename PixelT>
113 boost::shared_ptr<Eigen::MatrixXd> hMat
115 afwMath::CandidateVisitor(),
116 _basisList(basisList),
123 _useRegularization(true),
124 _useCoreStats(_policy.getBool(
"useCoreStats")),
125 _coreRadius(_policy.getInt(
"candidateCoreRadius"))
129 template<
typename PixelT>
136 if (kCandidate == NULL) {
137 pexLogging::TTrace<3>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
138 "Failed to cast SpatialCellCandidate to KernelCandidate %d",
139 kCandidate->
getId());
141 "Failed to cast SpatialCellCandidate to KernelCandidate");
148 pexLogging::TTrace<2>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
149 "Processing candidate %d", kCandidate->
getId());
150 pexLogging::TTrace<5>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
157 if (_useRegularization)
158 kCandidate->
build(_basisList, _hMat);
160 kCandidate->
build(_basisList);
164 pexLogging::TTrace<4>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
165 "Unable to process candidate %d; exception caught (%s)",
173 pexLogging::TTrace<4>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
174 "Candidate %d Returned BAD upon build, exiting",
175 kCandidate->
getId());
188 _imstats.apply(diffim, _coreRadius);
190 _imstats.apply(diffim);
192 pexLogging::TTrace<3>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
193 "Unable to calculate imstats for Candidate %d", kCandidate->
getId());
199 kCandidate->
setChi2(_imstats.getVariance());
206 pexLogging::TTrace<5>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
207 "Chi2 = %.3f", kCandidate->
getChi2());
208 pexLogging::TTrace<5>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
209 "Kernel Sum = %.3f", kSum);
210 pexLogging::TTrace<5>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
211 "Background = %.3f", background);
212 pexLogging::TTrace<3>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
213 "Candidate %d resids = %.3f +/- %.3f sigma (%d pix)",
219 bool meanIsNan =
std::isnan(_imstats.getMean());
220 bool rmsIsNan =
std::isnan(_imstats.getRms());
221 if (meanIsNan || rmsIsNan) {
223 pexLogging::TTrace<4>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
224 "Rejecting candidate %d, encountered NaN",
225 kCandidate->
getId());
230 if (_policy.getBool(
"singleKernelClipping")) {
231 if (fabs(_imstats.getMean()) > _policy.getDouble(
"candidateResidualMeanMax")) {
233 pexLogging::TTrace<4>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
234 "Rejecting candidate %d; bad mean residual : |%.3f| > %.3f",
237 _policy.getDouble(
"candidateResidualMeanMax"));
240 else if (_imstats.getRms() > _policy.getDouble(
"candidateResidualStdMax")) {
242 pexLogging::TTrace<4>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
243 "Rejecting candidate %d; bad residual rms : %.3f > %.3f",
246 _policy.getDouble(
"candidateResidualStdMax"));
251 pexLogging::TTrace<4>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
257 pexLogging::TTrace<6>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
258 "Sigma clipping not enabled");
262 if (!(_useCoreStats)) {
264 _imstats.apply(diffim, _coreRadius);
266 pexLogging::TTrace<3>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
267 "Unable to calculate core imstats for Candidate %d",
268 kCandidate->
getId());
272 pexLogging::TTrace<4>(
"lsst.ip.diffim.BuildSingleKernelVisitor.processCandidate",
273 "Candidate %d core resids = %.3f +/- %.3f sigma (%d pix)",
286 template boost::shared_ptr<BuildSingleKernelVisitor<PixelT> >
290 template boost::shared_ptr<BuildSingleKernelVisitor<PixelT> >
293 boost::shared_ptr<Eigen::MatrixXd>);
An include file to include the public header files for lsst::afw::math.
float getYCenter() const
Return the object's row-centre.
Class stored in SpatialCells for spatial Kernel fitting.
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)
a container for holding hierarchical configuration data in memory.
int getId() const
Return the candidate's unique ID.
definition of the Trace messaging facilities
Builds the convolution kernel for a given candidate.
afw::image::MaskedImage< PixelT > getDifferenceImage(CandidateSwitch cand)
Calculate associated difference image using internal solutions.
void build(afw::math::KernelList const &basisList)
Core functionality of KernelCandidate, to build and fill a KernelSolution.
void setStatus(Status status)
Set the candidate's status.
template boost::shared_ptr< BuildSingleKernelVisitor< PixelT > > makeBuildSingleKernelVisitor< PixelT >(lsst::afw::math::KernelList const &, lsst::pex::policy::Policy const &)
table::Key< table::Array< Kernel::Pixel > > image
BuildSingleKernelVisitor(lsst::afw::math::KernelList const &basisList, lsst::pex::policy::Policy const &policy)
bool isInitialized() const
An include file to include the header files for lsst::afw::image.
Status getStatus() const
Return the candidate's status.
double getKsum(CandidateSwitch cand) const
A class to manipulate images, masks, and variance as a single object.
Class used by SpatialModelCell for spatial Kernel fitting.
Class to calculate difference image statistics.
void setChi2(double chi2)
Set the candidate's chi^2.
virtual char const * what(void) const
#define LSST_EXCEPT(type,...)
double getChi2() const
Return the candidate's chi^2.
double getBackground(CandidateSwitch cand) const
std::vector< boost::shared_ptr< Kernel > > KernelList
Implementation of BuildSingleKernelVisitor.
Image Subtraction helper functions.
float getXCenter() const
Return the object's column-centre.