LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+bd2ed33bd6,g1470d8bcf6+de7501a2e0,g14a832a312+ff425fae3c,g2079a07aa2+86d27d4dc4,g2305ad1205+91a32aca49,g295015adf3+762506a1ad,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+c34e8be1fa,g487adcacf7+5fae3daba8,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ea1711114f,g5a732f18d5+53520f316c,g64a986408d+bd2ed33bd6,g858d7b2824+bd2ed33bd6,g8a8a8dda67+585e252eca,g99cad8db69+016a06b37a,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+09e12c87ab,gc120e1dc64+bc2e06c061,gc28159a63d+0e5473021a,gcf0d15dbbd+c34e8be1fa,gdaeeff99f8+f9a426f77a,ge6526c86ff+508d0e0a30,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+8d59551888,gf1cff7945b+bd2ed33bd6,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT > Class Template Reference

Creates a spatial kernel and background from a list of candidates. More...

#include <BuildSpatialKernelVisitor.h>

Inheritance diagram for lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >:
lsst::afw::math::CandidateVisitor

Public Types

typedef std::shared_ptr< BuildSpatialKernelVisitor< PixelT > > Ptr
 

Public Member Functions

 BuildSpatialKernelVisitor (lsst::afw::math::KernelList const &basisList, lsst::geom::Box2I const &regionBBox, lsst::daf::base::PropertySet const &ps)
 
int getNCandidates ()
 
void processCandidate (lsst::afw::math::SpatialCellCandidate *candidate)
 
void solveLinearEquation ()
 
std::shared_ptr< SpatialKernelSolutiongetKernelSolution ()
 
std::pair< std::shared_ptr< lsst::afw::math::LinearCombinationKernel >, lsst::afw::math::Kernel::SpatialFunctionPtrgetSolutionPair ()
 
virtual void reset ()
 

Detailed Description

template<typename PixelT>
class lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >

Creates a spatial kernel and background from a list of candidates.

std::shared_ptr<PropertySet> ps(new PropertySet);
ps->set("spatialKernelOrder", spatialKernelOrder);
ps->set("spatialBgOrder", spatialBgOrder);
ps->set("kernelBasisSet", "delta-function");
ps->set("usePcaForSpatialKernel", true);
detail::BuildSpatialKernelVisitor<PixelT> spatialKernelFitter(*basisListToUse,
*ps);
kernelCells.visitCandidates(&spatialKernelFitter, nStarPerCell);
spatialKernelFitter.solveLinearEquation();
afwMath::Kernel::SpatialFunctionPtr> kb = spatialKernelFitter.getKernelSolution();
spatialKernel = kb.first;
spatialBackground = kb.second;
Creates a spatial kernel and background from a list of candidates.
Note
After visiting all candidates, solveLinearEquation() must be called to trigger the matrix math.
The user has the option to enfore conservation of the kernel sum across the image through the property set. In this case, all terms but the first are fit for spatial variation. This requires a little extra code to make sure the matrices are the correct size, and that it is accessing the appropriate terms in the matrices when creating the spatial models.

Definition at line 28 of file BuildSpatialKernelVisitor.h.

Member Typedef Documentation

◆ Ptr

Definition at line 30 of file BuildSpatialKernelVisitor.h.

Constructor & Destructor Documentation

◆ BuildSpatialKernelVisitor()

template<typename PixelT >
lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >::BuildSpatialKernelVisitor ( lsst::afw::math::KernelList const & basisList,
lsst::geom::Box2I const & regionBBox,
lsst::daf::base::PropertySet const & ps )
Parameters
basisListBasis functions
regionBBoxSpatial region over which the function is fit
psPropertySet directing behavior

Definition at line 72 of file BuildSpatialKernelVisitor.cc.

76 :
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 };
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
2-dimensional weighted sum of Chebyshev polynomials of the first kind.
2-dimensional polynomial function with cross terms
A floating-point coordinate rectangle geometry.
Definition Box.h:413
Provides consistent interface for LSST exceptions.
Definition Exception.h:107

Member Function Documentation

◆ getKernelSolution()

Definition at line 44 of file BuildSpatialKernelVisitor.h.

44{return _kernelSolution;}

◆ getNCandidates()

template<typename PixelT >
int lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >::getNCandidates ( )
inline

Definition at line 38 of file BuildSpatialKernelVisitor.h.

38{return _nCandidates;}

◆ getSolutionPair()

template<typename PixelT >
std::pair< std::shared_ptr< afwMath::LinearCombinationKernel >, afwMath::Kernel::SpatialFunctionPtr > lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >::getSolutionPair ( )

Definition at line 162 of file BuildSpatialKernelVisitor.cc.

162 {
163 return _kernelSolution->getSolutionPair();
164 }

◆ processCandidate()

template<typename PixelT >
void lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >::processCandidate ( lsst::afw::math::SpatialCellCandidate * candidate)
virtual

Reimplemented from lsst::afw::math::CandidateVisitor.

Definition at line 120 of file BuildSpatialKernelVisitor.cc.

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 }
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition Log.h:515
Reports errors in the logical structure of the program.
Definition Runtime.h:46

◆ reset()

virtual void lsst::afw::math::CandidateVisitor::reset ( )
inlinevirtualinherited

◆ solveLinearEquation()

template<typename PixelT >
void lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >::solveLinearEquation ( )

Definition at line 156 of file BuildSpatialKernelVisitor.cc.

156 {
157 _kernelSolution->solve();
158 }

The documentation for this class was generated from the following files: