LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
LSST Data Management Base Package
Loading...
Searching...
No Matches
BuildSpatialKernelVisitor.cc
Go to the documentation of this file.
1// -*- lsst-c++ -*-
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"
24
28
29namespace afwMath = lsst::afw::math;
30namespace geom = lsst::afw::geom;
31namespace dafBase = lsst::daf::base;
33
34namespace lsst {
35namespace ip {
36namespace diffim {
37namespace detail {
71 template<typename PixelT>
73 lsst::afw::math::KernelList const& basisList,
74 lsst::geom::Box2I const& regionBBox,
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 {
108 str(boost::format("Invalid type (%s) for spatial models") %
109 spatialModelType));
110 }
111
112 /* */
113
115 new SpatialKernelSolution(basisList, spatialKernelFunction, background, ps));
116 };
117
118
119 template<typename PixelT>
122 ) {
123 KernelCandidate<PixelT> *kCandidate = dynamic_cast<KernelCandidate<PixelT> *>(candidate);
124 if (kCandidate == NULL) {
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(
148 )->getM(),
149 kCandidate->getKernelSolution(
151 )->getB());
152
153 }
154
155 template<typename PixelT>
157 _kernelSolution->solve();
158 }
159
160 template<typename PixelT>
161 std::pair<std::shared_ptr<afwMath::LinearCombinationKernel>, afwMath::Kernel::SpatialFunctionPtr>
163 return _kernelSolution->getSolutionPair();
164 }
165
166 typedef float PixelT;
168
169}}}} // end of namespace lsst::ip::diffim::detail
Declaration of BuildSpatialKernelVisitor.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
Class used by SpatialModelCell for spatial Kernel fitting.
Declaration of classes to store the solution for convolution kernels.
LSST DM logging module built on log4cxx.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition Log.h:515
2-dimensional weighted sum of Chebyshev polynomials of the first kind.
2-dimensional polynomial function with cross terms
Base class for candidate objects in a SpatialCell.
Definition SpatialCell.h:70
float getYCenter() const
Return the object's row-centre.
Definition SpatialCell.h:91
float getXCenter() const
Return the object's column-centre.
Definition SpatialCell.h:88
int getId() const
Return the candidate's unique ID.
void setStatus(Status status)
Set the candidate's status.
Class for storing generic metadata.
Definition PropertySet.h:66
std::string getAsString(std::string const &name) const
Get the last value for a string property name (possibly hierarchical).
int getAsInt(std::string const &name) const
Get the last value for a bool/char/short/int property name (possibly hierarchical).
bool getAsBool(std::string const &name) const
Get the last value for a bool property name (possibly hierarchical).
A floating-point coordinate rectangle geometry.
Definition Box.h:413
An integer coordinate rectangle.
Definition Box.h:55
Class stored in SpatialCells for spatial Kernel fitting.
std::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
Creates a spatial kernel and background from a list of candidates.
std::pair< std::shared_ptr< lsst::afw::math::LinearCombinationKernel >, lsst::afw::math::Kernel::SpatialFunctionPtr > getSolutionPair()
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)
BuildSpatialKernelVisitor(lsst::afw::math::KernelList const &basisList, lsst::geom::Box2I const &regionBBox, lsst::daf::base::PropertySet const &ps)
Provides consistent interface for LSST exceptions.
Definition Exception.h:107
Reports errors in the logical structure of the program.
Definition Runtime.h:46