LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT > Class Template Reference

Asseses the quality of a candidate given a spatial kernel and background model. More...

#include <AssessSpatialKernelVisitor.h>

Inheritance diagram for lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >:
lsst::afw::math::CandidateVisitor

Public Types

typedef boost::shared_ptr
< AssessSpatialKernelVisitor
< PixelT > > 
Ptr
 

Public Member Functions

 AssessSpatialKernelVisitor (lsst::afw::math::LinearCombinationKernel::Ptr spatialKernel, lsst::afw::math::Kernel::SpatialFunctionPtr spatialBackground, lsst::pex::policy::Policy const &policy)
 
virtual ~AssessSpatialKernelVisitor ()
 
void reset ()
 
int getNGood ()
 
int getNRejected ()
 
int getNProcessed ()
 
void processCandidate (lsst::afw::math::SpatialCellCandidate *candidate)
 
- Public Member Functions inherited from lsst::afw::math::CandidateVisitor
 CandidateVisitor ()
 
virtual ~CandidateVisitor ()
 

Private Types

typedef
lsst::afw::image::MaskedImage
< PixelT
MaskedImageT
 

Private Attributes

lsst::afw::math::LinearCombinationKernel::Ptr _spatialKernel
 Spatial kernel function. More...
 
lsst::afw::math::Kernel::SpatialFunctionPtr _spatialBackground
 Spatial background function. More...
 
lsst::pex::policy::Policy _policy
 Policy controlling behavior. More...
 
ImageStatistics< PixelT_imstats
 To calculate statistics of difference image. More...
 
int _nGood
 Number of good candidates remaining. More...
 
int _nRejected
 Number of candidates rejected during processCandidate() More...
 
int _nProcessed
 Number of candidates processed during processCandidate() More...
 
bool _useCoreStats
 Extracted from policy. More...
 
int _coreRadius
 Extracted from policy. More...
 

Detailed Description

template<typename PixelT>
class lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >

Asseses the quality of a candidate given a spatial kernel and background model.

detail::AssessSpatialKernelVisitor<PixelT> spatialKernelAssessor(spatialKernel,
spatialBackground,
policy);
spatialKernelAssessor.reset();
kernelCells.visitCandidates(&spatialKernelAssessor, nStarPerCell);
nRejected = spatialKernelAssessor.getNRejected();
*
Note
Evaluates the spatial kernel and spatial background at the location of each candidate, and computes the resulting difference image. Sets candidate as afwMath::SpatialCellCandidate::GOOD/BAD if requested by the Policy.

Definition at line 26 of file AssessSpatialKernelVisitor.h.

Member Typedef Documentation

Definition at line 27 of file AssessSpatialKernelVisitor.h.

template<typename PixelT >
typedef boost::shared_ptr<AssessSpatialKernelVisitor<PixelT> > lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::Ptr

Definition at line 29 of file AssessSpatialKernelVisitor.h.

Constructor & Destructor Documentation

Parameters
spatialKernelSpatially varying kernel
spatialBackgroundSpatially varying background
policyPolicy file

Definition at line 55 of file AssessSpatialKernelVisitor.cc.

59  :
61  _spatialKernel(spatialKernel),
62  _spatialBackground(spatialBackground),
63  _policy(policy),
64  _imstats(ImageStatistics<PixelT>(_policy)),
65  _nGood(0),
66  _nRejected(0),
67  _nProcessed(0),
68  _useCoreStats(_policy.getBool("useCoreStats")),
69  _coreRadius(_policy.getInt("candidateCoreRadius"))
70  {};
int getInt(const std::string &name) const
Definition: Policy.h:603
int _nProcessed
Number of candidates processed during processCandidate()
bool getBool(const std::string &name) const
Definition: Policy.h:589
int _nRejected
Number of candidates rejected during processCandidate()
lsst::afw::math::LinearCombinationKernel::Ptr _spatialKernel
Spatial kernel function.
ImageStatistics< PixelT > _imstats
To calculate statistics of difference image.
lsst::afw::math::Kernel::SpatialFunctionPtr _spatialBackground
Spatial background function.
lsst::pex::policy::Policy _policy
Policy controlling behavior.
template<typename PixelT >
virtual lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::~AssessSpatialKernelVisitor ( )
inlinevirtual

Definition at line 36 of file AssessSpatialKernelVisitor.h.

36 {};

Member Function Documentation

template<typename PixelT >
int lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::getNGood ( )
inline

Definition at line 40 of file AssessSpatialKernelVisitor.h.

40 {return _nGood;}
template<typename PixelT >
int lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::getNProcessed ( )
inline

Definition at line 42 of file AssessSpatialKernelVisitor.h.

42 {return _nProcessed;}
int _nProcessed
Number of candidates processed during processCandidate()
template<typename PixelT >
int lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::getNRejected ( )
inline

Definition at line 41 of file AssessSpatialKernelVisitor.h.

41 {return _nRejected;}
int _nRejected
Number of candidates rejected during processCandidate()
template<typename PixelT >
void lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::processCandidate ( lsst::afw::math::SpatialCellCandidate candidate)
virtual

Reimplemented from lsst::afw::math::CandidateVisitor.

Definition at line 73 of file AssessSpatialKernelVisitor.cc.

75  {
76 
77  KernelCandidate<PixelT> *kCandidate = dynamic_cast<KernelCandidate<PixelT> *>(candidate);
78  if (kCandidate == NULL) {
79  throw LSST_EXCEPT(pexExcept::LogicError,
80  "Failed to cast SpatialCellCandidate to KernelCandidate");
81  }
82  if (!(kCandidate->isInitialized())) {
83  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
84  pexLogging::TTrace<3>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
85  "Cannot process candidate %d, continuing", kCandidate->getId());
86  return;
87  }
88 
89  pexLogging::TTrace<2>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
90  "Processing candidate %d", kCandidate->getId());
91 
92  /*
93  Note - this is a hack until the Kernel API is upgraded by the
94  Davis crew. I need a "local" version of the spatially varying
95  Kernel
96  */
97  afwImage::Image<double> kImage(_spatialKernel->getDimensions());
98  double kSum = _spatialKernel->computeImage(kImage, false,
99  kCandidate->getXCenter(), kCandidate->getYCenter());
100  boost::shared_ptr<afwMath::Kernel>
101  kernelPtr(new afwMath::FixedKernel(kImage));
102  /* </hack> */
103 
104  double background = (*_spatialBackground)(kCandidate->getXCenter(), kCandidate->getYCenter());
105 
106  MaskedImageT diffim = kCandidate->getDifferenceImage(kernelPtr, background);
107 
108  if (DEBUG_IMAGES) {
109  kImage.writeFits(str(boost::format("askv_k%d.fits") % kCandidate->getId()));
110  diffim.writeFits(str(boost::format("askv_d%d.fits") % kCandidate->getId()));
111  }
112 
113  /* Official resids */
114  try {
115  if (_useCoreStats)
116  _imstats.apply(diffim, _coreRadius);
117  else
118  _imstats.apply(diffim);
119  } catch (pexExcept::Exception& e) {
120  pexLogging::TTrace<3>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
121  "Unable to calculate imstats for Candidate %d", kCandidate->getId());
122  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
123  return;
124  }
125 
126  _nProcessed += 1;
127 
128  pexLogging::TTrace<5>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
129  "Chi2 = %.3f", _imstats.getVariance());
130  pexLogging::TTrace<5>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
131  "X = %.2f Y = %.2f",
132  kCandidate->getXCenter(),
133  kCandidate->getYCenter());
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)",
140  kCandidate->getId(),
141  _imstats.getMean(),
142  _imstats.getRms(),
143  _imstats.getNpix());
144 
145  bool meanIsNan = std::isnan(_imstats.getMean());
146  bool rmsIsNan = std::isnan(_imstats.getRms());
147  if (meanIsNan || rmsIsNan) {
148  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
149  pexLogging::TTrace<4>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
150  "Rejecting candidate %d, encountered NaN",
151  kCandidate->getId());
152  _nRejected += 1;
153  return;
154  }
155 
156  if (_policy.getBool("spatialKernelClipping")) {
157  if (fabs(_imstats.getMean()) > _policy.getDouble("candidateResidualMeanMax")) {
158  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
159  pexLogging::TTrace<4>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
160  "Rejecting candidate %d; bad mean residual : |%.3f| > %.3f",
161  kCandidate->getId(),
162  _imstats.getMean(),
163  _policy.getDouble("candidateResidualMeanMax"));
164  _nRejected += 1;
165  }
166  else if (_imstats.getRms() > _policy.getDouble("candidateResidualStdMax")) {
167  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
168  pexLogging::TTrace<4>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
169  "Rejecting candidate %d; bad residual rms : %.3f > %.3f",
170  kCandidate->getId(),
171  _imstats.getRms(),
172  _policy.getDouble("candidateResidualStdMax"));
173  _nRejected += 1;
174  }
175  else {
176  kCandidate->setStatus(afwMath::SpatialCellCandidate::GOOD);
177  pexLogging::TTrace<4>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
178  "Spatial kernel OK");
179  _nGood += 1;
180  }
181  }
182  else {
183  kCandidate->setStatus(afwMath::SpatialCellCandidate::GOOD);
184  pexLogging::TTrace<6>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
185  "Sigma clipping not enabled");
186  _nGood += 1;
187  }
188 
189  /* Core resids for debugging */
190  if (!(_useCoreStats)) {
191  try {
192  _imstats.apply(diffim, _coreRadius);
193  } catch (pexExcept::Exception& e) {
194  pexLogging::TTrace<3>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
195  "Unable to calculate core imstats for Candidate %d",
196  kCandidate->getId());
197  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
198  return;
199  }
200  pexLogging::TTrace<4>("lsst.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
201  "Candidate %d core resids = %.3f +/- %.3f sigma (%d pix)",
202  kCandidate->getId(),
203  _imstats.getMean(),
204  _imstats.getRms(),
205  _imstats.getNpix());
206  }
207  }
int _nProcessed
Number of candidates processed during processCandidate()
bool getBool(const std::string &name) const
Definition: Policy.h:589
int isnan(T t)
Definition: ieee.h:110
int _nRejected
Number of candidates rejected during processCandidate()
lsst::afw::math::LinearCombinationKernel::Ptr _spatialKernel
Spatial kernel function.
ImageStatistics< PixelT > _imstats
To calculate statistics of difference image.
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
double getDouble(const std::string &name) const
Definition: Policy.h:617
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415
lsst::pex::policy::Policy _policy
Policy controlling behavior.
A kernel created from an Image.
Definition: Kernel.h:551
#define DEBUG_IMAGES
template<typename PixelT >
void lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::reset ( )
inlinevirtual

Reimplemented from lsst::afw::math::CandidateVisitor.

Definition at line 38 of file AssessSpatialKernelVisitor.h.

38 {_nGood = 0; _nRejected = 0; _nProcessed = 0;}
int _nProcessed
Number of candidates processed during processCandidate()
int _nRejected
Number of candidates rejected during processCandidate()

Member Data Documentation

template<typename PixelT >
int lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::_coreRadius
private

Extracted from policy.

Definition at line 55 of file AssessSpatialKernelVisitor.h.

template<typename PixelT >
ImageStatistics<PixelT> lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::_imstats
private

To calculate statistics of difference image.

Definition at line 49 of file AssessSpatialKernelVisitor.h.

template<typename PixelT >
int lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::_nGood
private

Number of good candidates remaining.

Definition at line 50 of file AssessSpatialKernelVisitor.h.

template<typename PixelT >
int lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::_nProcessed
private

Number of candidates processed during processCandidate()

Definition at line 52 of file AssessSpatialKernelVisitor.h.

template<typename PixelT >
int lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::_nRejected
private

Number of candidates rejected during processCandidate()

Definition at line 51 of file AssessSpatialKernelVisitor.h.

Policy controlling behavior.

Definition at line 48 of file AssessSpatialKernelVisitor.h.

Spatial background function.

Definition at line 47 of file AssessSpatialKernelVisitor.h.

Spatial kernel function.

Definition at line 46 of file AssessSpatialKernelVisitor.h.

template<typename PixelT >
bool lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::_useCoreStats
private

Extracted from policy.

Definition at line 54 of file AssessSpatialKernelVisitor.h.


The documentation for this class was generated from the following files: