LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+b2075782a9,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g3ddfee87b4+a60788ef87,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+a60788ef87,g591dd9f2cf+ba8caea58f,g5ec818987f+864ee9cddb,g858d7b2824+9ee1ab4172,g876c692160+a40945ebb7,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+5e309b7bc6,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+aa12a14d27,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+d0da15e3be,gba4ed39666+1ac82b564f,gbb8dafda3b+5dfd9c994b,gbeb006f7da+97157f9740,gc28159a63d+c6dfa2ddaf,gc86a011abf+9ee1ab4172,gcf0d15dbbd+a60788ef87,gdaeeff99f8+1cafcb7cd4,gdc0c513512+9ee1ab4172,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,geb961e4c1e+f9439d1e6f,gee10cc3b42+90ebb246c7,gf1cff7945b+9ee1ab4172,w.2024.12
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Types | Public Member Functions | 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 std::shared_ptr< KernelSumVisitor< PixelT > > Ptr
 

Public Member Functions

 KernelSumVisitor (lsst::daf::base::PropertySet const &ps)
 
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 ()
 
virtual void reset ()
 

Detailed Description

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

A class to accumulate kernel sums across SpatialCells.

std::shared_ptr<PropertySet> ps(new PropertySet);
ps->set("kernelSumClipping", false);
ps->set("maxKsumSigma", 3.0);
detail::KernelSumVisitor<PixelT> kernelSumVisitor(*ps);
kernelSumVisitor.reset();
kernelCells.visitCandidates(&kernelSumVisitor, nStarPerCell);
kernelSumVisitor.processKsumDistribution();
kernelSumVisitor.setMode(detail::KernelSumVisitor<PixelT>::REJECT);
kernelCells.visitCandidates(&kernelSumVisitor, nStarPerCell);
int nRejected = kernelSumVisitor.getNRejected();
A class to accumulate kernel sums across SpatialCells.
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 ps). 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 27 of file KernelSumVisitor.h.

Member Typedef Documentation

◆ Ptr

Definition at line 29 of file KernelSumVisitor.h.

Member Enumeration Documentation

◆ Mode

Enumerator
AGGREGATE 
REJECT 

Definition at line 31 of file KernelSumVisitor.h.

Constructor & Destructor Documentation

◆ KernelSumVisitor()

template<typename PixelT >
lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::KernelSumVisitor ( lsst::daf::base::PropertySet const & ps)
Parameters
psps file directing behavior

Definition at line 65 of file KernelSumVisitor.cc.

67 :
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 {};

◆ ~KernelSumVisitor()

template<typename PixelT >
virtual lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::~KernelSumVisitor ( )
inlinevirtual

Definition at line 34 of file KernelSumVisitor.h.

34{};

Member Function Documentation

◆ getdkSumMax()

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

Definition at line 40 of file KernelSumVisitor.h.

40{return _dkSumMax;}

◆ getkSumMean()

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

Definition at line 38 of file KernelSumVisitor.h.

38{return _kSumMean;}

◆ getkSumNpts()

template<typename PixelT >
int lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::getkSumNpts ( )
inline

Definition at line 41 of file KernelSumVisitor.h.

41{return _kSumNpts;}

◆ getkSumStd()

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

Definition at line 39 of file KernelSumVisitor.h.

39{return _kSumStd;}

◆ getNRejected()

template<typename PixelT >
int lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::getNRejected ( )
inline

Definition at line 37 of file KernelSumVisitor.h.

37{return _nRejected;}

◆ 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 90 of file KernelSumVisitor.cc.

91 {
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 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition Log.h:515
Reports errors in the logical structure of the program.
Definition Runtime.h:46
T fabs(T... args)
T push_back(T... args)

◆ processKsumDistribution()

template<typename PixelT >
void lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::processKsumDistribution ( )

Definition at line 127 of file KernelSumVisitor.cc.

127 {
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 }
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it.
Definition Exception.h:54
A class to evaluate image statistics.
Definition Statistics.h:222
Provides consistent interface for LSST exceptions.
Definition Exception.h:107
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
T size(T... args)

◆ reset()

virtual void lsst::afw::math::CandidateVisitor::reset ( )
inlinevirtualinherited

◆ resetKernelSum()

template<typename PixelT >
void lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::resetKernelSum ( )

Definition at line 80 of file KernelSumVisitor.cc.

80 {
81 _kSums.clear();
82 _kSumMean = 0.;
83 _kSumStd = 0.;
84 _dkSumMax = 0.;
85 _kSumNpts = 0;
86 _nRejected = 0;
87 }
T clear(T... args)

◆ setMode()

template<typename PixelT >
void lsst::ip::diffim::detail::KernelSumVisitor< PixelT >::setMode ( Mode mode)
inline

Definition at line 36 of file KernelSumVisitor.h.

36{_mode = mode;}

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