22 #define DEBUG_IMAGES 0
24 namespace afwMath = lsst::afw::math;
26 namespace pexLogging = lsst::pex::logging;
27 namespace pexPolicy = lsst::pex::policy;
28 namespace pexExcept = lsst::pex::exceptions;
54 template<
typename PixelT>
60 afwMath::CandidateVisitor(),
61 _spatialKernel(spatialKernel),
62 _spatialBackground(spatialBackground),
68 _useCoreStats(_policy.getBool(
"useCoreStats")),
69 _coreRadius(_policy.getInt(
"candidateCoreRadius"))
72 template<
typename PixelT>
78 if (kCandidate == NULL) {
80 "Failed to cast SpatialCellCandidate to KernelCandidate");
84 pexLogging::TTrace<3>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
85 "Cannot process candidate %d, continuing", kCandidate->
getId());
89 pexLogging::TTrace<2>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
90 "Processing candidate %d", kCandidate->
getId());
98 double kSum = _spatialKernel->computeImage(kImage,
false,
100 boost::shared_ptr<afwMath::Kernel>
116 _imstats.apply(diffim, _coreRadius);
118 _imstats.apply(diffim);
120 pexLogging::TTrace<3>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
121 "Unable to calculate imstats for Candidate %d", kCandidate->
getId());
128 pexLogging::TTrace<5>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
129 "Chi2 = %.3f", _imstats.getVariance());
130 pexLogging::TTrace<5>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
134 pexLogging::TTrace<5>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
135 "Kernel Sum = %.3f", kSum);
136 pexLogging::TTrace<5>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
137 "Background = %.3f", background);
138 pexLogging::TTrace<3>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
139 "Candidate %d resids = %.3f +/- %.3f sigma (%d pix)",
145 bool meanIsNan =
std::isnan(_imstats.getMean());
146 bool rmsIsNan =
std::isnan(_imstats.getRms());
147 if (meanIsNan || rmsIsNan) {
149 pexLogging::TTrace<4>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
150 "Rejecting candidate %d, encountered NaN",
151 kCandidate->
getId());
156 if (_policy.getBool(
"spatialKernelClipping")) {
157 if (fabs(_imstats.getMean()) > _policy.getDouble(
"candidateResidualMeanMax")) {
159 pexLogging::TTrace<4>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
160 "Rejecting candidate %d; bad mean residual : |%.3f| > %.3f",
163 _policy.getDouble(
"candidateResidualMeanMax"));
166 else if (_imstats.getRms() > _policy.getDouble(
"candidateResidualStdMax")) {
168 pexLogging::TTrace<4>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
169 "Rejecting candidate %d; bad residual rms : %.3f > %.3f",
172 _policy.getDouble(
"candidateResidualStdMax"));
177 pexLogging::TTrace<4>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
178 "Spatial kernel OK");
184 pexLogging::TTrace<6>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
185 "Sigma clipping not enabled");
190 if (!(_useCoreStats)) {
192 _imstats.apply(diffim, _coreRadius);
194 pexLogging::TTrace<3>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
195 "Unable to calculate core imstats for Candidate %d",
196 kCandidate->
getId());
200 pexLogging::TTrace<4>(
"lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
201 "Candidate %d core resids = %.3f +/- %.3f sigma (%d pix)",
An include file to include the public header files for lsst::afw::math.
boost::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
Asseses the quality of a candidate given a spatial kernel and background model.
float getYCenter() const
Return the object's row-centre.
Class stored in SpatialCells for spatial Kernel fitting.
AssessSpatialKernelVisitor(lsst::afw::math::LinearCombinationKernel::Ptr spatialKernel, lsst::afw::math::Kernel::SpatialFunctionPtr spatialBackground, lsst::pex::policy::Policy const &policy)
a container for holding hierarchical configuration data in memory.
int getId() const
Return the candidate's unique ID.
definition of the Trace messaging facilities
afw::image::MaskedImage< PixelT > getDifferenceImage(CandidateSwitch cand)
Calculate associated difference image using internal solutions.
void setStatus(Status status)
Set the candidate's status.
table::Key< table::Array< Kernel::Pixel > > image
bool isInitialized() const
An include file to include the header files for lsst::afw::image.
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.
#define LSST_EXCEPT(type,...)
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)
Declaration of AssessSpatialKernelVisitor.
A class to represent a 2-dimensional array of pixels.
Image Subtraction helper functions.
boost::shared_ptr< LinearCombinationKernel > Ptr
A kernel created from an Image.
float getXCenter() const
Return the object's column-centre.