13 #include "boost/timer.hpp" 16 #include "Eigen/Cholesky" 20 #include "lsst/afw/math.h" 21 #include "lsst/afw/geom.h" 22 #include "lsst/log/Log.h" 23 #include "lsst/pex/policy/Policy.h" 24 #include "lsst/pex/exceptions/Runtime.h" 30 namespace afwMath = lsst::afw::math;
31 namespace afwGeom = lsst::afw::geom;
32 namespace pexPolicy = lsst::pex::policy;
33 namespace pexExcept = lsst::pex::exceptions;
72 template<
typename PixelT>
74 lsst::afw::math::KernelList
const& basisList,
75 lsst::afw::geom::Box2I
const& regionBBox,
76 lsst::pex::policy::Policy policy
78 afwMath::CandidateVisitor(),
82 int spatialKernelOrder = policy.getInt(
"spatialKernelOrder");
83 afwMath::Kernel::SpatialFunctionPtr spatialKernelFunction;
85 int fitForBackground = policy.getBool(
"fitForBackground");
86 int spatialBgOrder = fitForBackground ? policy.getInt(
"spatialBgOrder") : 0;
87 afwMath::Kernel::SpatialFunctionPtr background;
89 std::string spatialModelType = policy.getString(
"spatialModelType");
90 if (spatialModelType ==
"chebyshev1") {
91 spatialKernelFunction = afwMath::Kernel::SpatialFunctionPtr(
92 new afwMath::Chebyshev1Function2<double>(spatialKernelOrder, afwGeom::Box2D(regionBBox))
94 background = afwMath::Kernel::SpatialFunctionPtr(
95 new afwMath::Chebyshev1Function2<double>(spatialBgOrder, afwGeom::Box2D(regionBBox))
99 else if (spatialModelType ==
"polynomial") {
100 spatialKernelFunction = afwMath::Kernel::SpatialFunctionPtr(
101 new afwMath::PolynomialFunction2<double>(spatialKernelOrder)
103 background = afwMath::Kernel::SpatialFunctionPtr(
104 new afwMath::PolynomialFunction2<double>(spatialBgOrder)
108 throw LSST_EXCEPT(pexExcept::Exception,
109 str(boost::format(
"Invalid type (%s) for spatial models") %
120 template<
typename PixelT>
122 lsst::afw::math::SpatialCellCandidate *candidate
125 if (kCandidate == NULL) {
126 throw LSST_EXCEPT(pexExcept::LogicError,
127 "Failed to cast SpatialCellCandidate to KernelCandidate");
130 kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
131 LOGL_DEBUG(
"TRACE2.ip.diffim.BuildSpatialKernelVisitor.processCandidate",
132 "Cannot process candidate %d, continuing", kCandidate->getId());
136 LOGL_DEBUG(
"TRACE5.ip.diffim.BuildSpatialKernelVisitor.processCandidate",
137 "Processing candidate %d", kCandidate->getId());
146 kCandidate->getYCenter(),
156 template<
typename PixelT>
161 template<
typename PixelT>
162 std::pair<std::shared_ptr<afwMath::LinearCombinationKernel>, afwMath::Kernel::SpatialFunctionPtr>
Creates a spatial kernel and background from a list of candidates.
Class stored in SpatialCells for spatial Kernel fitting.
std::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
Declaration of BuildSpatialKernelVisitor.
void solveLinearEquation()
bool isInitialized() const
Declaration of classes to store the solution for convolution kernels.
int _nCandidates
Number of candidates visited.
BuildSpatialKernelVisitor(lsst::afw::math::KernelList const &basisList, lsst::afw::geom::Box2I const ®ionBBox, lsst::pex::policy::Policy policy)
std::pair< std::shared_ptr< lsst::afw::math::LinearCombinationKernel >, lsst::afw::math::Kernel::SpatialFunctionPtr > getSolutionPair()
Class used by SpatialModelCell for spatial Kernel fitting.
std::shared_ptr< SpatialKernelSolution > _kernelSolution
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)