LSST Applications g180d380827+770a9040cc,g2079a07aa2+86d27d4dc4,g2305ad1205+09cfdadad9,g2bbee38e9b+c6a8a0fb72,g337abbeb29+c6a8a0fb72,g33d1c0ed96+c6a8a0fb72,g3a166c0a6a+c6a8a0fb72,g3ddfee87b4+1ea5e09c42,g48712c4677+7e2ea9cd42,g487adcacf7+301d09421d,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+96fcb956a6,g64a986408d+23540ee355,g858d7b2824+23540ee355,g864b0138d7+aa38e45daa,g95921f966b+d83dc58ecd,g991b906543+23540ee355,g99cad8db69+7f13b58a93,g9c22b2923f+e2510deafe,g9ddcbc5298+9a081db1e4,ga1e77700b3+03d07e1c1f,gb0e22166c9+60f28cb32d,gb23b769143+23540ee355,gba4ed39666+c2a2e4ac27,gbb8dafda3b+49e7449578,gbd998247f1+585e252eca,gc120e1dc64+1bbfa184e1,gc28159a63d+c6a8a0fb72,gc3e9b769f7+385ea95214,gcf0d15dbbd+1ea5e09c42,gdaeeff99f8+f9a426f77a,ge6526c86ff+1bccc98490,ge79ae78c31+c6a8a0fb72,gee10cc3b42+585e252eca,w.2024.18
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