lsst.ip.diffim
g174f8ebed5+ec711f8d5b
Toggle main menu visibility
Loading...
Searching...
No Matches
src
KernelSumVisitor.cc
Go to the documentation of this file.
1
// -*- lsst-c++ -*-
11
#include <limits>
12
13
#include "
lsst/afw/math.h
"
14
#include "
lsst/log/Log.h
"
15
#include "
lsst/daf/base/PropertySet.h
"
16
#include "
lsst/pex/exceptions/Runtime.h
"
17
18
#include "
lsst/ip/diffim/KernelCandidate.h
"
19
#include "
lsst/ip/diffim/KernelSumVisitor.h
"
20
21
namespace
afwMath
=
lsst::afw::math
;
22
namespace
dafBase
=
lsst::daf::base
;
23
namespace
pexExcept
=
lsst::pex::exceptions
;
24
25
namespace
lsst
{
26
namespace
ip
{
27
namespace
diffim
{
28
namespace
detail
{
29
64
template
<
typename
PixelT>
65
KernelSumVisitor<PixelT>::KernelSumVisitor
(
66
lsst::daf::base::PropertySet
const
& ps
67
) :
68
afwMath
::
CandidateVisitor
(),
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
{};
78
79
template
<
typename
PixelT>
80
void
KernelSumVisitor<PixelT>::resetKernelSum
() {
81
_kSums.clear();
82
_kSumMean = 0.;
83
_kSumStd = 0.;
84
_dkSumMax = 0.;
85
_kSumNpts = 0;
86
_nRejected = 0;
87
}
88
89
template
<
typename
PixelT>
90
void
KernelSumVisitor<PixelT>::processCandidate
(
lsst::afw::math::SpatialCellCandidate
91
*candidate) {
92
93
KernelCandidate<PixelT>
*kCandidate =
dynamic_cast<
KernelCandidate<PixelT>
*
>
(candidate);
94
if
(kCandidate == NULL) {
95
throw
LSST_EXCEPT
(
pexExcept::LogicError
,
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
}
125
126
template
<
typename
PixelT>
127
void
KernelSumVisitor<PixelT>::processKsumDistribution
() {
128
if
(_kSums.size() == 0) {
129
throw
LSST_EXCEPT
(
pexExcept::RuntimeError
,
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
{
142
afwMath::Statistics
stats =
afwMath::makeStatistics
(_kSums,
143
afwMath::NPOINT
|
144
afwMath::MEANCLIP
|
145
afwMath::STDEVCLIP
);
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)) {
154
throw
LSST_EXCEPT
(
pexExcept::RuntimeError
,
155
str(boost::format(
"Mean kernel sum returns NaN (%d points)"
)
156
% _kSumNpts));
157
}
158
if
(
std::isnan
(_kSumStd)) {
159
throw
LSST_EXCEPT
(
pexExcept::RuntimeError
,
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
}
169
170
typedef
float
PixelT
;
171
172
template
class
KernelSumVisitor<PixelT>
;
173
174
template
std::shared_ptr<KernelSumVisitor<PixelT>
>
175
makeKernelSumVisitor<PixelT>
(
lsst::daf::base::PropertySet
const
&);
176
177
}}}}
// end of namespace lsst::ip::diffim::detail
Log.h
LOGL_DEBUG
#define LOGL_DEBUG(logger, message...)
LSST_EXCEPT_ADD
#define LSST_EXCEPT_ADD(e, m)
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
KernelCandidate.h
Class used by SpatialModelCell for spatial Kernel fitting.
KernelSumVisitor.h
Declaration of KernelSumVisitor.
PropertySet.h
Runtime.h
lsst::afw::math::CandidateVisitor::CandidateVisitor
CandidateVisitor()=default
lsst::afw::math::SpatialCellCandidate
lsst::afw::math::SpatialCellImageCandidate::getId
int getId() const
lsst::afw::math::SpatialCellCandidate::BAD
BAD
lsst::afw::math::SpatialCellImageCandidate::setStatus
void setStatus(Status status)
lsst::afw::math::Statistics
lsst::afw::math::Statistics::getValue
double getValue(Property const prop=NOTHING) const
lsst::daf::base::PropertySet
lsst::ip::diffim::KernelCandidate
Class stored in SpatialCells for spatial Kernel fitting.
Definition
KernelCandidate.h:39
lsst::ip::diffim::KernelCandidate::ORIG
@ ORIG
Definition
KernelCandidate.h:50
lsst::ip::diffim::KernelCandidate::getKernelSolution
std::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
Definition
KernelCandidate.cc:337
lsst::ip::diffim::detail::KernelSumVisitor
A class to accumulate kernel sums across SpatialCells.
Definition
KernelSumVisitor.h:27
lsst::ip::diffim::detail::KernelSumVisitor::REJECT
@ REJECT
Definition
KernelSumVisitor.h:31
lsst::ip::diffim::detail::KernelSumVisitor::AGGREGATE
@ AGGREGATE
Definition
KernelSumVisitor.h:31
lsst::ip::diffim::detail::KernelSumVisitor::KernelSumVisitor
KernelSumVisitor(lsst::daf::base::PropertySet const &ps)
Definition
KernelSumVisitor.cc:65
lsst::ip::diffim::detail::KernelSumVisitor::processKsumDistribution
void processKsumDistribution()
Definition
KernelSumVisitor.cc:127
lsst::ip::diffim::detail::KernelSumVisitor::processCandidate
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)
Definition
KernelSumVisitor.cc:90
lsst::ip::diffim::detail::KernelSumVisitor::resetKernelSum
void resetKernelSum()
Definition
KernelSumVisitor.cc:80
lsst::pex::exceptions::Exception
lsst::pex::exceptions::LogicError
lsst::pex::exceptions::RuntimeError
std::isnan
T isnan(T... args)
math.h
lsst::afw::math
lsst::afw::math::makeStatistics
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
lsst::afw::math::STDEVCLIP
STDEVCLIP
lsst::afw::math::MEANCLIP
MEANCLIP
lsst::afw::math::NPOINT
NPOINT
lsst::daf::base
lsst::ip::diffim::detail
Definition
AssessSpatialKernelVisitor.h:23
lsst::ip::diffim::detail::PixelT
float PixelT
Definition
AssessSpatialKernelVisitor.cc:208
lsst::ip::diffim::detail::makeKernelSumVisitor< PixelT >
template std::shared_ptr< KernelSumVisitor< PixelT > > makeKernelSumVisitor< PixelT >(lsst::daf::base::PropertySet const &)
lsst::ip::diffim
Definition
AssessSpatialKernelVisitor.h:22
lsst::ip
Definition
AssessSpatialKernelVisitor.h:21
lsst::pex::exceptions
lsst
std
STL namespace.
std::shared_ptr
Generated on
for lsst.ip.diffim by
1.17.0