LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Private Attributes | 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 boost::shared_ptr
< BuildSpatialKernelVisitor
< PixelT > > 
Ptr
 

Public Member Functions

 BuildSpatialKernelVisitor (lsst::afw::math::KernelList const &basisList, lsst::afw::geom::Box2I const &regionBBox, lsst::pex::policy::Policy policy)
 
int getNCandidates ()
 
void processCandidate (lsst::afw::math::SpatialCellCandidate *candidate)
 
void solveLinearEquation ()
 
boost::shared_ptr
< SpatialKernelSolution
getKernelSolution ()
 
std::pair
< lsst::afw::math::LinearCombinationKernel::Ptr,
lsst::afw::math::Kernel::SpatialFunctionPtr
getSolutionPair ()
 
- Public Member Functions inherited from lsst::afw::math::CandidateVisitor
 CandidateVisitor ()
 
virtual ~CandidateVisitor ()
 
virtual void reset ()
 

Private Attributes

boost::shared_ptr
< SpatialKernelSolution
_kernelSolution
 
int _nCandidates
 Number of candidates visited. More...
 

Detailed Description

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

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

Policy::Ptr policy(new Policy);
policy->set("spatialKernelOrder", spatialKernelOrder);
policy->set("spatialBgOrder", spatialBgOrder);
policy->set("kernelBasisSet", "delta-function");
policy->set("usePcaForSpatialKernel", true);
detail::BuildSpatialKernelVisitor<PixelT> spatialKernelFitter(*basisListToUse,
*policy);
kernelCells.visitCandidates(&spatialKernelFitter, nStarPerCell);
spatialKernelFitter.solveLinearEquation();
afwMath::Kernel::SpatialFunctionPtr> kb = spatialKernelFitter.getKernelSolution();
spatialKernel = kb.first;
spatialBackground = kb.second;
*
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 policy. 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 27 of file BuildSpatialKernelVisitor.h.

Member Typedef Documentation

template<typename PixelT >
typedef boost::shared_ptr<BuildSpatialKernelVisitor<PixelT> > lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >::Ptr

Definition at line 29 of file BuildSpatialKernelVisitor.h.

Constructor & Destructor Documentation

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

Definition at line 74 of file BuildSpatialKernelVisitor.cc.

78  :
81  _nCandidates(0)
82  {
83  int spatialKernelOrder = policy.getInt("spatialKernelOrder");
84  afwMath::Kernel::SpatialFunctionPtr spatialKernelFunction;
85 
86  int fitForBackground = policy.getBool("fitForBackground");
87  int spatialBgOrder = fitForBackground ? policy.getInt("spatialBgOrder") : 0;
89 
90  std::string spatialModelType = policy.getString("spatialModelType");
91  if (spatialModelType == "chebyshev1") {
92  spatialKernelFunction = afwMath::Kernel::SpatialFunctionPtr(
93  new afwMath::Chebyshev1Function2<double>(spatialKernelOrder, afwGeom::Box2D(regionBBox))
94  );
96  new afwMath::Chebyshev1Function2<double>(spatialBgOrder, afwGeom::Box2D(regionBBox))
97  );
98 
99  }
100  else if (spatialModelType == "polynomial") {
101  spatialKernelFunction = afwMath::Kernel::SpatialFunctionPtr(
102  new afwMath::PolynomialFunction2<double>(spatialKernelOrder)
103  );
105  new afwMath::PolynomialFunction2<double>(spatialBgOrder)
106  );
107  }
108  else {
110  str(boost::format("Invalid type (%s) for spatial models") %
111  spatialModelType));
112  }
113 
114  /* */
115 
116  _kernelSolution = boost::shared_ptr<SpatialKernelSolution>(
117  new SpatialKernelSolution(basisList, spatialKernelFunction, background, policy));
118  };
2-dimensional weighted sum of Chebyshev polynomials of the first kind.
boost::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
Definition: Kernel.h:143
int getInt(const std::string &name) const
Definition: Policy.h:603
bool getBool(const std::string &name) const
Definition: Policy.h:589
boost::shared_ptr< SpatialKernelSolution > _kernelSolution
2-dimensional polynomial function with cross terms
const std::string getString(const std::string &name) const
Definition: Policy.h:631
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
A floating-point coordinate rectangle geometry.
Definition: Box.h:271

Member Function Documentation

template<typename PixelT >
boost::shared_ptr<SpatialKernelSolution> lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >::getKernelSolution ( )
inline

Definition at line 43 of file BuildSpatialKernelVisitor.h.

43 {return _kernelSolution;}
boost::shared_ptr< SpatialKernelSolution > _kernelSolution
template<typename PixelT >
int lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >::getNCandidates ( )
inline

Definition at line 37 of file BuildSpatialKernelVisitor.h.

37 {return _nCandidates;}

Definition at line 164 of file BuildSpatialKernelVisitor.cc.

164  {
165  return _kernelSolution->getSolutionPair();
166  }
boost::shared_ptr< SpatialKernelSolution > _kernelSolution
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 122 of file BuildSpatialKernelVisitor.cc.

124  {
125  KernelCandidate<PixelT> *kCandidate = dynamic_cast<KernelCandidate<PixelT> *>(candidate);
126  if (kCandidate == NULL) {
127  throw LSST_EXCEPT(pexExcept::LogicError,
128  "Failed to cast SpatialCellCandidate to KernelCandidate");
129  }
130  if (!(kCandidate->isInitialized())) {
131  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
132  pexLogging::TTrace<3>("lsst.ip.diffim.BuildSpatialKernelVisitor.processCandidate",
133  "Cannot process candidate %d, continuing", kCandidate->getId());
134  return;
135  }
136 
137  pexLogging::TTrace<6>("lsst.ip.diffim.BuildSpatialKernelVisitor.processCandidate",
138  "Processing candidate %d", kCandidate->getId());
139  _nCandidates += 1;
140 
141  /*
142  Build the spatial kernel from the most recent fit, e.g. if its Pca
143  you want to build a spatial model on the Pca basis, not original
144  basis
145  */
146  _kernelSolution->addConstraint(kCandidate->getXCenter(),
147  kCandidate->getYCenter(),
148  kCandidate->getKernelSolution(
149  KernelCandidate<PixelT>::RECENT
150  )->getM(),
151  kCandidate->getKernelSolution(
152  KernelCandidate<PixelT>::RECENT
153  )->getB());
154 
155  }
boost::shared_ptr< SpatialKernelSolution > _kernelSolution
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename PixelT >
void lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >::solveLinearEquation ( )

Definition at line 158 of file BuildSpatialKernelVisitor.cc.

158  {
159  _kernelSolution->solve();
160  }
boost::shared_ptr< SpatialKernelSolution > _kernelSolution

Member Data Documentation

template<typename PixelT >
boost::shared_ptr<SpatialKernelSolution> lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >::_kernelSolution
private

Definition at line 49 of file BuildSpatialKernelVisitor.h.

template<typename PixelT >
int lsst::ip::diffim::detail::BuildSpatialKernelVisitor< PixelT >::_nCandidates
private

Number of candidates visited.

Definition at line 50 of file BuildSpatialKernelVisitor.h.


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