lsst.ip.diffim
g174f8ebed5+0e497d1560
Toggle main menu visibility
Loading...
Searching...
No Matches
src
BuildSpatialKernelVisitor.cc
Go to the documentation of this file.
1
// -*- lsst-c++ -*-
11
12
#include <memory>
13
14
#include "Eigen/Core"
15
#include "Eigen/Cholesky"
16
#include "Eigen/LU"
17
#include "Eigen/QR"
18
19
#include "
lsst/afw/math.h
"
20
#include "
lsst/geom.h
"
21
#include "
lsst/log/Log.h
"
22
#include "
lsst/daf/base/PropertySet.h
"
23
#include "
lsst/pex/exceptions/Runtime.h
"
24
25
#include "
lsst/ip/diffim/KernelCandidate.h
"
26
#include "
lsst/ip/diffim/KernelSolution.h
"
27
#include "
lsst/ip/diffim/BuildSpatialKernelVisitor.h
"
28
29
namespace
afwMath
=
lsst::afw::math
;
30
namespace
geom
=
lsst::afw::geom
;
31
namespace
dafBase
=
lsst::daf::base
;
32
namespace
pexExcept
=
lsst::pex::exceptions
;
33
34
namespace
lsst
{
35
namespace
ip
{
36
namespace
diffim
{
37
namespace
detail
{
71
template
<
typename
PixelT>
72
BuildSpatialKernelVisitor<PixelT>::BuildSpatialKernelVisitor
(
73
lsst::afw::math::KernelList
const
& basisList,
74
lsst::geom::Box2I
const
& regionBBox,
75
lsst::daf::base::PropertySet
const
& ps
76
) :
77
afwMath
::
CandidateVisitor
(),
78
_kernelSolution(),
79
_nCandidates(0)
80
{
81
int
spatialKernelOrder = ps.
getAsInt
(
"spatialKernelOrder"
);
82
afwMath::Kernel::SpatialFunctionPtr
spatialKernelFunction;
83
84
int
fitForBackground = ps.
getAsBool
(
"fitForBackground"
);
85
int
spatialBgOrder = fitForBackground ? ps.
getAsInt
(
"spatialBgOrder"
) : 0;
86
afwMath::Kernel::SpatialFunctionPtr
background
;
87
88
std::string
spatialModelType = ps.
getAsString
(
"spatialModelType"
);
89
if
(spatialModelType ==
"chebyshev1"
) {
90
spatialKernelFunction =
afwMath::Kernel::SpatialFunctionPtr
(
91
new
afwMath::Chebyshev1Function2<double>
(spatialKernelOrder,
geom::Box2D
(regionBBox))
92
);
93
background
=
afwMath::Kernel::SpatialFunctionPtr
(
94
new
afwMath::Chebyshev1Function2<double>
(spatialBgOrder,
geom::Box2D
(regionBBox))
95
);
96
97
}
98
else
if
(spatialModelType ==
"polynomial"
) {
99
spatialKernelFunction =
afwMath::Kernel::SpatialFunctionPtr
(
100
new
afwMath::PolynomialFunction2<double>
(spatialKernelOrder)
101
);
102
background
=
afwMath::Kernel::SpatialFunctionPtr
(
103
new
afwMath::PolynomialFunction2<double>
(spatialBgOrder)
104
);
105
}
106
else
{
107
throw
LSST_EXCEPT
(
pexExcept::Exception
,
108
str(boost::format(
"Invalid type (%s) for spatial models"
) %
109
spatialModelType));
110
}
111
112
/* */
113
114
_kernelSolution =
std::shared_ptr<SpatialKernelSolution>
(
115
new
SpatialKernelSolution
(basisList, spatialKernelFunction,
background
, ps));
116
};
117
118
119
template
<
typename
PixelT>
120
void
BuildSpatialKernelVisitor<PixelT>::processCandidate
(
121
lsst::afw::math::SpatialCellCandidate
*candidate
122
) {
123
KernelCandidate<PixelT>
*kCandidate =
dynamic_cast<
KernelCandidate<PixelT>
*
>
(candidate);
124
if
(kCandidate == NULL) {
125
throw
LSST_EXCEPT
(
pexExcept::LogicError
,
126
"Failed to cast SpatialCellCandidate to KernelCandidate"
);
127
}
128
if
(!(kCandidate->
isInitialized
())) {
129
kCandidate->
setStatus
(
afwMath::SpatialCellCandidate::BAD
);
130
LOGL_DEBUG
(
"TRACE2.ip.diffim.BuildSpatialKernelVisitor.processCandidate"
,
131
"Cannot process candidate %d, continuing"
, kCandidate->
getId
());
132
return
;
133
}
134
135
LOGL_DEBUG
(
"TRACE5.ip.diffim.BuildSpatialKernelVisitor.processCandidate"
,
136
"Processing candidate %d"
, kCandidate->
getId
());
137
_nCandidates += 1;
138
139
/*
140
Build the spatial kernel from the most recent fit, e.g. if its Pca
141
you want to build a spatial model on the Pca basis, not original
142
basis
143
*/
144
_kernelSolution->addConstraint(kCandidate->
getXCenter
(),
145
kCandidate->
getYCenter
(),
146
kCandidate->
getKernelSolution
(
147
KernelCandidate<PixelT>::RECENT
148
)->getM(),
149
kCandidate->
getKernelSolution
(
150
KernelCandidate<PixelT>::RECENT
151
)->getB());
152
153
}
154
155
template
<
typename
PixelT>
156
void
BuildSpatialKernelVisitor<PixelT>::solveLinearEquation
() {
157
_kernelSolution->solve();
158
}
159
160
template
<
typename
PixelT>
161
std::pair<std::shared_ptr<afwMath::LinearCombinationKernel>
,
afwMath::Kernel::SpatialFunctionPtr
>
162
BuildSpatialKernelVisitor<PixelT>::getSolutionPair
() {
163
return
_kernelSolution->getSolutionPair();
164
}
165
166
typedef
float
PixelT
;
167
template
class
BuildSpatialKernelVisitor<PixelT>
;
168
169
}}}}
// end of namespace lsst::ip::diffim::detail
Log.h
LOGL_DEBUG
#define LOGL_DEBUG(logger, message...)
BuildSpatialKernelVisitor.h
Declaration of BuildSpatialKernelVisitor.
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
KernelCandidate.h
Class used by SpatialModelCell for spatial Kernel fitting.
KernelSolution.h
Declaration of classes to store the solution for convolution kernels.
PropertySet.h
Runtime.h
std::string
lsst::afw::math::CandidateVisitor::CandidateVisitor
CandidateVisitor()=default
lsst::afw::math::Chebyshev1Function2
lsst::afw::math::Kernel::SpatialFunctionPtr
std::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
lsst::afw::math::PolynomialFunction2
lsst::afw::math::SpatialCellCandidate
lsst::afw::math::SpatialCellImageCandidate::getYCenter
float getYCenter() const
lsst::afw::math::SpatialCellImageCandidate::getXCenter
float getXCenter() const
lsst::afw::math::SpatialCellImageCandidate::getId
int getId() const
lsst::afw::math::SpatialCellCandidate::BAD
BAD
lsst::afw::math::SpatialCellImageCandidate::setStatus
void setStatus(Status status)
lsst::daf::base::PropertySet
lsst::daf::base::PropertySet::getAsString
std::string getAsString(std::string const &name) const
lsst::daf::base::PropertySet::getAsInt
int getAsInt(std::string const &name) const
lsst::daf::base::PropertySet::getAsBool
bool getAsBool(std::string const &name) const
lsst::geom::Box2D
lsst::geom::Box2I
lsst::ip::diffim::KernelCandidate
Class stored in SpatialCells for spatial Kernel fitting.
Definition
KernelCandidate.h:39
lsst::ip::diffim::KernelCandidate::isInitialized
bool isInitialized() const
Definition
KernelCandidate.h:128
lsst::ip::diffim::KernelCandidate::RECENT
@ RECENT
Definition
KernelCandidate.h:52
lsst::ip::diffim::KernelCandidate::getKernelSolution
std::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
Definition
KernelCandidate.cc:337
lsst::ip::diffim::SpatialKernelSolution
Definition
KernelSolution.h:174
lsst::ip::diffim::detail::BuildSpatialKernelVisitor
Creates a spatial kernel and background from a list of candidates.
Definition
BuildSpatialKernelVisitor.h:28
lsst::ip::diffim::detail::BuildSpatialKernelVisitor::solveLinearEquation
void solveLinearEquation()
Definition
BuildSpatialKernelVisitor.cc:156
lsst::ip::diffim::detail::BuildSpatialKernelVisitor::getSolutionPair
std::pair< std::shared_ptr< lsst::afw::math::LinearCombinationKernel >, lsst::afw::math::Kernel::SpatialFunctionPtr > getSolutionPair()
Definition
BuildSpatialKernelVisitor.cc:162
lsst::ip::diffim::detail::BuildSpatialKernelVisitor::processCandidate
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)
Definition
BuildSpatialKernelVisitor.cc:120
lsst::ip::diffim::detail::BuildSpatialKernelVisitor::BuildSpatialKernelVisitor
BuildSpatialKernelVisitor(lsst::afw::math::KernelList const &basisList, lsst::geom::Box2I const ®ionBBox, lsst::daf::base::PropertySet const &ps)
Definition
BuildSpatialKernelVisitor.cc:72
lsst::pex::exceptions::Exception
lsst::pex::exceptions::LogicError
geom.h
math.h
lsst::afw::geom
lsst::afw::math
lsst::afw::math::KernelList
std::vector< std::shared_ptr< Kernel > > KernelList
lsst::daf::base
lsst::geom
lsst::ip::diffim::detail
Definition
AssessSpatialKernelVisitor.h:23
lsst::ip::diffim::detail::PixelT
float PixelT
Definition
AssessSpatialKernelVisitor.cc:208
lsst::ip::diffim.detectAndMeasure.background
background
Definition
detectAndMeasure.py:763
lsst::ip::diffim
Definition
AssessSpatialKernelVisitor.h:22
lsst::ip
Definition
AssessSpatialKernelVisitor.h:21
lsst::pex::exceptions
lsst
std::pair
std::shared_ptr
Generated on
for lsst.ip.diffim by
1.17.0