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 Attributes | List of all members
lsst::ip::diffim::detail::KernelSumVisitor< PixelT > Class Template Reference

A class to accumulate kernel sums across SpatialCells. More...

#include <KernelSumVisitor.h>

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

Public Types

enum  Mode { AGGREGATE = 0, REJECT = 1 }
 
typedef boost::shared_ptr
< KernelSumVisitor< PixelT > > 
Ptr
 

Public Member Functions

 KernelSumVisitor (lsst::pex::policy::Policy const &policy)
 
virtual ~KernelSumVisitor ()
 
void setMode (Mode mode)
 
int getNRejected ()
 
double getkSumMean ()
 
double getkSumStd ()
 
double getdkSumMax ()
 
int getkSumNpts ()
 
void resetKernelSum ()
 
void processCandidate (lsst::afw::math::SpatialCellCandidate *candidate)
 
void processKsumDistribution ()
 
- Public Member Functions inherited from lsst::afw::math::CandidateVisitor
 CandidateVisitor ()
 
virtual ~CandidateVisitor ()
 
virtual void reset ()
 

Private Attributes

Mode _mode
 Processing mode; AGGREGATE or REJECT. More...
 
std::vector< double > _kSums
 List of all candidate kernel sums. More...
 
double _kSumMean
 Clipped mean of the kernel sums. More...
 
double _kSumStd
 Clipped standard deviation of kernel sums. More...
 
double _dkSumMax
 Maximum acceptable deviation from mean sum. More...
 
int _kSumNpts
 Number of points used in the statistics. More...
 
int _nRejected
 Number of candidates rejected during processCandidate() More...
 
lsst::pex::policy::Policy _policy
 Policy controlling behavior. More...
 

Detailed Description

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

A class to accumulate kernel sums across SpatialCells.

Policy::Ptr policy(new Policy);
policy->set("kernelSumClipping", false);
policy->set("maxKsumSigma", 3.0);
detail::KernelSumVisitor<PixelT> kernelSumVisitor(*policy);
kernelSumVisitor.reset();
kernelSumVisitor.setMode(detail::KernelSumVisitor<PixelT>::AGGREGATE);
kernelCells.visitCandidates(&kernelSumVisitor, nStarPerCell);
kernelSumVisitor.processKsumDistribution();
kernelSumVisitor.setMode(detail::KernelSumVisitor<PixelT>::REJECT);
kernelCells.visitCandidates(&kernelSumVisitor, nStarPerCell);
int nRejected = kernelSumVisitor.getNRejected();
*
Note
The class has 2 processing modes; the first AGGREGATES kernel sums across all candidates. You must the process the distribution to set member variables representing the mean and standard deviation of the kernel sums. The second mode then REJECTs candidates with kernel sums outside the acceptable range (set by the policy). It does this by setting candidate status to afwMath::SpatialCellCandidate::BAD. In this mode it also accumulates the number of candidates it sets as bad.
The statistics call calculates sigma-clipped values (afwMath::MEANCLIP, afwMath::STDEVCLIP)

Definition at line 26 of file KernelSumVisitor.h.

Member Typedef Documentation

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

Definition at line 28 of file KernelSumVisitor.h.

Member Enumeration Documentation

template<typename PixelT >
enum lsst::ip::diffim::detail::KernelSumVisitor::Mode

Constructor & Destructor Documentation

Parameters
policyPolicy file directing behavior

Definition at line 66 of file KernelSumVisitor.cc.

68  :
71  _kSums(std::vector<double>()),
72  _kSumMean(0.),
73  _kSumStd(0.),
74  _dkSumMax(0.),
75  _kSumNpts(0),
76  _nRejected(0),
77  _policy(policy)
78  {};
int _kSumNpts
Number of points used in the statistics.
Mode _mode
Processing mode; AGGREGATE or REJECT.
double _kSumMean
Clipped mean of the kernel sums.
double _dkSumMax
Maximum acceptable deviation from mean sum.
double _kSumStd
Clipped standard deviation of kernel sums.
std::vector< double > _kSums
List of all candidate kernel sums.
int _nRejected
Number of candidates rejected during processCandidate()
lsst::pex::policy::Policy _policy
Policy controlling behavior.
template<typename PixelT >
virtual lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::~KernelSumVisitor ( )
inlinevirtual

Definition at line 33 of file KernelSumVisitor.h.

33 {};

Member Function Documentation

template<typename PixelT >
double lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::getdkSumMax ( )
inline

Definition at line 39 of file KernelSumVisitor.h.

39 {return _dkSumMax;}
double _dkSumMax
Maximum acceptable deviation from mean sum.
template<typename PixelT >
double lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::getkSumMean ( )
inline

Definition at line 37 of file KernelSumVisitor.h.

37 {return _kSumMean;}
double _kSumMean
Clipped mean of the kernel sums.
template<typename PixelT >
int lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::getkSumNpts ( )
inline

Definition at line 40 of file KernelSumVisitor.h.

40 {return _kSumNpts;}
int _kSumNpts
Number of points used in the statistics.
template<typename PixelT >
double lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::getkSumStd ( )
inline

Definition at line 38 of file KernelSumVisitor.h.

38 {return _kSumStd;}
double _kSumStd
Clipped standard deviation of kernel sums.
template<typename PixelT >
int lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::getNRejected ( )
inline

Definition at line 36 of file KernelSumVisitor.h.

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

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

Definition at line 91 of file KernelSumVisitor.cc.

92  {
93 
94  KernelCandidate<PixelT> *kCandidate = dynamic_cast<KernelCandidate<PixelT> *>(candidate);
95  if (kCandidate == NULL) {
96  throw LSST_EXCEPT(pexExcept::LogicError,
97  "Failed to cast SpatialCellCandidate to KernelCandidate");
98  }
99  pexLogging::TTrace<6>("lsst.ip.diffim.KernelSumVisitor.processCandidate",
100  "Processing candidate %d, mode %d", kCandidate->getId(), _mode);
101 
102  /* Grab all kernel sums and look for outliers */
103  if (_mode == AGGREGATE) {
104  _kSums.push_back(kCandidate->getKernelSolution(KernelCandidate<PixelT>::ORIG)->getKsum());
105  }
106  else if (_mode == REJECT) {
107  if (_policy.getBool("kernelSumClipping")) {
108  double kSum =
109  kCandidate->getKernelSolution(KernelCandidate<PixelT>::ORIG)->getKsum();
110 
111  if (fabs(kSum - _kSumMean) > _dkSumMax) {
112  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
113  pexLogging::TTrace<4>("lsst.ip.diffim.KernelSumVisitor.processCandidate",
114  "Rejecting candidate %d; bad source kernel sum : (%.2f)",
115  kCandidate->getId(),
116  kSum);
117  _nRejected += 1;
118  }
119  }
120  else {
121  pexLogging::TTrace<6>("lsst.ip.diffim.KernelSumVisitor.processCandidate",
122  "Sigma clipping not enabled");
123  }
124  }
125  }
Mode _mode
Processing mode; AGGREGATE or REJECT.
bool getBool(const std::string &name) const
Definition: Policy.h:589
double _kSumMean
Clipped mean of the kernel sums.
double _dkSumMax
Maximum acceptable deviation from mean sum.
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
std::vector< double > _kSums
List of all candidate kernel sums.
int _nRejected
Number of candidates rejected during processCandidate()
lsst::pex::policy::Policy _policy
Policy controlling behavior.
template<typename PixelT >
void lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::processKsumDistribution ( )

Definition at line 128 of file KernelSumVisitor.cc.

128  {
129  if (_kSums.size() == 0) {
131  "Unable to determine kernel sum; 0 candidates");
132  }
133  else if (_kSums.size() == 1) {
134  pexLogging::TTrace<2>("lsst.ip.diffim.KernelSumVisitor.processKsumDistribution",
135  "WARNING: only 1 kernel candidate");
136 
137  _kSumMean = _kSums[0];
138  _kSumStd = 0.0;
139  _kSumNpts = 1;
140  }
141  else {
142  try {
144  afwMath::NPOINT |
149  _kSumNpts = static_cast<int>(stats.getValue(afwMath::NPOINT));
150  } catch (pexExcept::Exception &e) {
151  LSST_EXCEPT_ADD(e, "Unable to calculate kernel sum statistics");
152  throw e;
153  }
154  if (std::isnan(_kSumMean)) {
156  str(boost::format("Mean kernel sum returns NaN (%d points)")
157  % _kSumNpts));
158  }
159  if (std::isnan(_kSumStd)) {
161  str(boost::format("Kernel sum stdev returns NaN (%d points)")
162  % _kSumNpts));
163  }
164  }
165  _dkSumMax = _policy.getDouble("maxKsumSigma") * _kSumStd;
166  pexLogging::TTrace<2>("lsst.ip.diffim.KernelSumVisitor.processCandidate",
167  "Kernel Sum Distribution : %.3f +/- %.3f (%d points)",
169  }
int _kSumNpts
Number of points used in the statistics.
double _kSumMean
Clipped mean of the kernel sums.
int isnan(T t)
Definition: ieee.h:110
estimate sample N-sigma clipped stdev (N set in StatisticsControl, default=3)
Definition: Statistics.h:73
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
Definition: Statistics.cc:1009
estimate sample N-sigma clipped mean (N set in StatisticsControl, default=3)
Definition: Statistics.h:72
number of sample points
Definition: Statistics.h:66
double _dkSumMax
Maximum acceptable deviation from mean sum.
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
double getDouble(const std::string &name) const
Definition: Policy.h:617
double _kSumStd
Clipped standard deviation of kernel sums.
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1082
std::vector< double > _kSums
List of all candidate kernel sums.
#define LSST_EXCEPT_ADD(e, m)
Definition: Exception.h:51
lsst::pex::policy::Policy _policy
Policy controlling behavior.
template<typename PixelT >
void lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::resetKernelSum ( )

Definition at line 81 of file KernelSumVisitor.cc.

81  {
82  _kSums.clear();
83  _kSumMean = 0.;
84  _kSumStd = 0.;
85  _dkSumMax = 0.;
86  _kSumNpts = 0;
87  _nRejected = 0;
88  }
int _kSumNpts
Number of points used in the statistics.
double _kSumMean
Clipped mean of the kernel sums.
double _dkSumMax
Maximum acceptable deviation from mean sum.
double _kSumStd
Clipped standard deviation of kernel sums.
std::vector< double > _kSums
List of all candidate kernel sums.
int _nRejected
Number of candidates rejected during processCandidate()
template<typename PixelT >
void lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::setMode ( Mode  mode)
inline

Definition at line 35 of file KernelSumVisitor.h.

35 {_mode = mode;}
Mode _mode
Processing mode; AGGREGATE or REJECT.

Member Data Documentation

template<typename PixelT >
double lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::_dkSumMax
private

Maximum acceptable deviation from mean sum.

Definition at line 51 of file KernelSumVisitor.h.

template<typename PixelT >
double lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::_kSumMean
private

Clipped mean of the kernel sums.

Definition at line 49 of file KernelSumVisitor.h.

template<typename PixelT >
int lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::_kSumNpts
private

Number of points used in the statistics.

Definition at line 52 of file KernelSumVisitor.h.

template<typename PixelT >
std::vector<double> lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::_kSums
private

List of all candidate kernel sums.

Definition at line 48 of file KernelSumVisitor.h.

template<typename PixelT >
double lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::_kSumStd
private

Clipped standard deviation of kernel sums.

Definition at line 50 of file KernelSumVisitor.h.

template<typename PixelT >
Mode lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::_mode
private

Processing mode; AGGREGATE or REJECT.

Definition at line 47 of file KernelSumVisitor.h.

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

Number of candidates rejected during processCandidate()

Definition at line 53 of file KernelSumVisitor.h.

template<typename PixelT >
lsst::pex::policy::Policy lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::_policy
private

Policy controlling behavior.

Definition at line 54 of file KernelSumVisitor.h.


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