LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
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;
std::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
Definition: Kernel.h:113
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()

Parameters
basisListBasis functions
regionBBoxSpatial region over which the function is fit
psPropertySet directing behavior

Definition at line 73 of file BuildSpatialKernelVisitor.cc.

77 :
79 _kernelSolution(),
80 _nCandidates(0)
81 {
82 int spatialKernelOrder = ps.getAsInt("spatialKernelOrder");
83 afwMath::Kernel::SpatialFunctionPtr spatialKernelFunction;
84
85 int fitForBackground = ps.getAsBool("fitForBackground");
86 int spatialBgOrder = fitForBackground ? ps.getAsInt("spatialBgOrder") : 0;
88
89 std::string spatialModelType = ps.getAsString("spatialModelType");
90 if (spatialModelType == "chebyshev1") {
91 spatialKernelFunction = afwMath::Kernel::SpatialFunctionPtr(
92 new afwMath::Chebyshev1Function2<double>(spatialKernelOrder, geom::Box2D(regionBBox))
93 );
95 new afwMath::Chebyshev1Function2<double>(spatialBgOrder, geom::Box2D(regionBBox))
96 );
97
98 }
99 else if (spatialModelType == "polynomial") {
100 spatialKernelFunction = afwMath::Kernel::SpatialFunctionPtr(
101 new afwMath::PolynomialFunction2<double>(spatialKernelOrder)
102 );
104 new afwMath::PolynomialFunction2<double>(spatialBgOrder)
105 );
106 }
107 else {
109 str(boost::format("Invalid type (%s) for spatial models") %
110 spatialModelType));
111 }
112
113 /* */
114
116 new SpatialKernelSolution(basisList, spatialKernelFunction, background, ps));
117 };
#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
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

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()

Definition at line 163 of file BuildSpatialKernelVisitor.cc.

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

◆ 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 121 of file BuildSpatialKernelVisitor.cc.

123 {
124 KernelCandidate<PixelT> *kCandidate = dynamic_cast<KernelCandidate<PixelT> *>(candidate);
125 if (kCandidate == NULL) {
127 "Failed to cast SpatialCellCandidate to KernelCandidate");
128 }
129 if (!(kCandidate->isInitialized())) {
130 kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
131 LOGL_DEBUG("TRACE2.ip.diffim.BuildSpatialKernelVisitor.processCandidate",
132 "Cannot process candidate %d, continuing", kCandidate->getId());
133 return;
134 }
135
136 LOGL_DEBUG("TRACE5.ip.diffim.BuildSpatialKernelVisitor.processCandidate",
137 "Processing candidate %d", kCandidate->getId());
138 _nCandidates += 1;
139
140 /*
141 Build the spatial kernel from the most recent fit, e.g. if its Pca
142 you want to build a spatial model on the Pca basis, not original
143 basis
144 */
145 _kernelSolution->addConstraint(kCandidate->getXCenter(),
146 kCandidate->getYCenter(),
147 kCandidate->getKernelSolution(
149 )->getM(),
150 kCandidate->getKernelSolution(
152 )->getB());
153
154 }
#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 157 of file BuildSpatialKernelVisitor.cc.

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

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