LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
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