LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
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