LSSTApplications  21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-11-ga6ea59e8e+47cba9fc36,21.0.0-2-g103fe59+914993bf7c,21.0.0-2-g1367e85+e2614ded12,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g4bc9b9f+7b2b5f8678,21.0.0-2-g5242d73+e2614ded12,21.0.0-2-g54e2caa+6403186824,21.0.0-2-g7f82c8f+3ac4acbffc,21.0.0-2-g8dde007+04a6aea1af,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+3ac4acbffc,21.0.0-2-ga63a54e+81dd751046,21.0.0-2-gc738bc1+5f65c6e7a9,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+0993ddc9bd,21.0.0-2-gfc62afb+e2614ded12,21.0.0-21-gba890a8+5a4f502a26,21.0.0-23-g9966ff26+03098d1af8,21.0.0-3-g357aad2+8ad216c477,21.0.0-3-g4be5c26+e2614ded12,21.0.0-3-g6d51c4a+4d2fe0280d,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+522e0f12c2,21.0.0-3-ge02ed75+4d2fe0280d,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-gc004bbf+eac6615e82,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-gd1c1571+18b81799f9,21.0.0-5-g7b47fff+4d2fe0280d,21.0.0-5-gb155db7+d2632f662b,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g722ad07+28c848f42a,21.0.0-7-g959bb79+522e0f12c2,21.0.0-7-gfd72ab2+cf01990774,21.0.0-9-g87fb7b8d+e2ab11cdd6,w.2021.04
LSSTDataManagementBasePackage
BuildSpatialKernelVisitor.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
12 #include <memory>
13 #include "boost/timer.hpp"
14 
15 #include "Eigen/Core"
16 #include "Eigen/Cholesky"
17 #include "Eigen/LU"
18 #include "Eigen/QR"
19 
20 #include "lsst/afw/math.h"
21 #include "lsst/geom.h"
22 #include "lsst/log/Log.h"
25 
29 
30 namespace afwMath = lsst::afw::math;
31 namespace geom = lsst::afw::geom;
32 namespace dafBase = lsst::daf::base;
34 
35 namespace lsst {
36 namespace ip {
37 namespace diffim {
38 namespace detail {
72  template<typename PixelT>
74  lsst::afw::math::KernelList const& basisList,
75  lsst::geom::Box2I const& regionBBox,
77  ) :
78  afwMath::CandidateVisitor(),
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 
115  _kernelSolution = std::shared_ptr<SpatialKernelSolution>(
116  new SpatialKernelSolution(basisList, spatialKernelFunction, background, ps));
117  };
118 
119 
120  template<typename PixelT>
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())) {
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  }
155 
156  template<typename PixelT>
158  _kernelSolution->solve();
159  }
160 
161  template<typename PixelT>
164  return _kernelSolution->getSolutionPair();
165  }
166 
167  typedef float PixelT;
168  template class BuildSpatialKernelVisitor<PixelT>;
169 
170 }}}} // end of namespace lsst::ip::diffim::detail
lsst::daf::base::PropertySet::getAsInt
int getAsInt(std::string const &name) const
Get the last value for a bool/char/short/int property name (possibly hierarchical).
lsst::afw::math::SpatialCellCandidate
Base class for candidate objects in a SpatialCell.
Definition: SpatialCell.h:70
lsst::daf::base::PropertySet::getAsBool
bool getAsBool(std::string const &name) const
Get the last value for a bool property name (possibly hierarchical).
std::string
STL class.
std::shared_ptr
STL class.
lsst::afw::math::Chebyshev1Function2
2-dimensional weighted sum of Chebyshev polynomials of the first kind.
Definition: FunctionLibrary.h:719
lsst::afw::math::SpatialCellCandidate::setStatus
void setStatus(Status status)
Set the candidate's status.
Definition: SpatialCell.cc:54
std::pair
std::vector< std::shared_ptr< Kernel > >
lsst::ip::diffim::KernelCandidate
Class stored in SpatialCells for spatial Kernel fitting.
Definition: KernelCandidate.h:39
lsst::ip::diffim::detail::BuildSpatialKernelVisitor::processCandidate
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)
Definition: BuildSpatialKernelVisitor.cc:121
lsst::ip::diffim::detail::PixelT
float PixelT
Definition: AssessSpatialKernelVisitor.cc:208
BuildSpatialKernelVisitor.h
Declaration of BuildSpatialKernelVisitor.
KernelSolution.h
Declaration of classes to store the solution for convolution kernels.
lsst.pex.config.history.format
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
lsst::ip::diffim::SpatialKernelSolution
Definition: KernelSolution.h:174
math.h
lsst::afw::math::SpatialCellCandidate::BAD
@ BAD
Definition: SpatialCell.h:72
lsst::ip::diffim::detail::BuildSpatialKernelVisitor::getSolutionPair
std::pair< std::shared_ptr< lsst::afw::math::LinearCombinationKernel >, lsst::afw::math::Kernel::SpatialFunctionPtr > getSolutionPair()
Definition: BuildSpatialKernelVisitor.cc:163
lsst::afw::math::SpatialCellCandidate::getXCenter
float getXCenter() const
Return the object's column-centre.
Definition: SpatialCell.h:90
lsst.pipe.drivers.visualizeVisit.background
background
Definition: visualizeVisit.py:37
lsst::daf::base::PropertySet::getAsString
std::string getAsString(std::string const &name) const
Get the last value for a string property name (possibly hierarchical).
PropertySet.h
lsst.pex::exceptions::LogicError
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
lsst.pipe.tasks.cli.cmd.commands.str
str
Definition: commands.py:50
lsst::afw::math::SpatialCellCandidate::getId
int getId() const
Return the candidate's unique ID.
Definition: SpatialCell.h:104
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::ip::diffim::KernelCandidate::getKernelSolution
std::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
Definition: KernelCandidate.cc:322
lsst::geom
Definition: AffineTransform.h:36
Runtime.h
lsst::daf::base
Definition: Utils.h:47
lsst::ip::diffim::detail::BuildSpatialKernelVisitor::BuildSpatialKernelVisitor
BuildSpatialKernelVisitor(lsst::afw::math::KernelList const &basisList, lsst::geom::Box2I const &regionBBox, lsst::daf::base::PropertySet const &ps)
Definition: BuildSpatialKernelVisitor.cc:73
lsst::ip::diffim::KernelCandidate::isInitialized
bool isInitialized() const
Definition: KernelCandidate.h:128
LOGL_DEBUG
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:504
lsst::afw::math
Definition: statistics.dox:6
KernelCandidate.h
Class used by SpatialModelCell for spatial Kernel fitting.
lsst::ip::diffim::detail::BuildSpatialKernelVisitor::solveLinearEquation
void solveLinearEquation()
Definition: BuildSpatialKernelVisitor.cc:157
lsst::ip::diffim::detail::BuildSpatialKernelVisitor
Creates a spatial kernel and background from a list of candidates.
Definition: BuildSpatialKernelVisitor.h:28
lsst::daf::base::PropertySet
Class for storing generic metadata.
Definition: PropertySet.h:67
lsst::geom::Box2I
An integer coordinate rectangle.
Definition: Box.h:55
lsst.pex::exceptions
Definition: Exception.h:37
lsst.pex::exceptions::Exception
Provides consistent interface for LSST exceptions.
Definition: Exception.h:107
lsst::afw::math::PolynomialFunction2
2-dimensional polynomial function with cross terms
Definition: FunctionLibrary.h:449
lsst::geom::Box2D
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
lsst::afw::math::Kernel::SpatialFunctionPtr
std::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
Definition: Kernel.h:114
lsst::afw::math::SpatialCellCandidate::getYCenter
float getYCenter() const
Return the object's row-centre.
Definition: SpatialCell.h:93
Log.h
LSST DM logging module built on log4cxx.
geom.h
lsst::afw::geom
Definition: frameSetUtils.h:40