lsst.ip.diffim  15.0-3-ge6a6747+2
KernelCandidate.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
12 #ifndef LSST_IP_DIFFIM_KERNELCANDIDATE_H
13 #define LSST_IP_DIFFIM_KERNELCANDIDATE_H
14 
15 #include <memory>
16 #include "Eigen/Core"
17 
18 #include "lsst/afw/math.h"
19 #include "lsst/afw/image.h"
21 #include "lsst/afw/table/Source.h"
22 
23 namespace lsst {
24 namespace ip {
25 namespace diffim {
26 
27 
37  template <typename _PixelT>
39  public:
41  typedef _PixelT PixelT; // _after_ afw::math::Kernel::Pixel
42  public:
47 
49  ORIG = 0,
50  PCA = 1,
51  RECENT = 2
52  };
53 
63  KernelCandidate(float const xCenter,
64  float const yCenter,
65  MaskedImagePtr const& templateMaskedImage,
66  MaskedImagePtr const& scienceMaskedImage,
67  pex::policy::Policy const& policy);
68 
78  KernelCandidate(SourcePtr const& source,
79  MaskedImagePtr const& templateMaskedImage,
80  MaskedImagePtr const& scienceMaskedImage,
81  pex::policy::Policy const& policy);
83  virtual ~KernelCandidate() {};
84 
90  double getCandidateRating() const { return _coreFlux; }
94  SourcePtr getSource() const { return _source; }
98  MaskedImagePtr getTemplateMaskedImage() {return _templateMaskedImage;}
99  MaskedImagePtr getScienceMaskedImage() {return _scienceMaskedImage;}
100 
106  double getBackground(CandidateSwitch cand) const;
107  double getKsum(CandidateSwitch cand) const;
108  PTR(ImageT) getKernelImage(CandidateSwitch cand) const;
109  CONST_PTR(ImageT) getImage() const; // For SpatialCellImageCandidate
111 
116 
124  double background
125  );
126 
127  bool isInitialized() const {return _isInitialized;}
128 
129 
164  /*
165  * @note This method uses an estimate of the variance which is the
166  * straight difference of the 2 images. If requested in the Policy
167  * ("iterateSingleKernel"), the kernel will be rebuilt using the
168  * variance of the difference image resulting from this first
169  * approximate step. This is particularly useful when convolving a
170  * single-depth science image; the variance (and thus resulting kernel)
171  * generally converges after 1 iteration. If
172  * "constantVarianceWeighting" is requested in the Policy, no iterations
173  * will be performed even if requested.
174  */
175 
176  void build(
177  afw::math::KernelList const& basisList
178  );
179  void build(
180  afw::math::KernelList const& basisList,
181  Eigen::MatrixXd const& hMat
182  );
183 
184  private:
185  MaskedImagePtr _templateMaskedImage;
186  MaskedImagePtr _scienceMaskedImage;
187  VariancePtr _varianceEstimate;
188  pex::policy::Policy _policy;
189  SourcePtr _source;
190  double _coreFlux;
191  bool _isInitialized;
192  bool _useRegularization;
193  bool _fitForBackground;
194 
195  /* best single raw kernel */
196  std::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionOrig;
197 
198  /* with Pca basis */
199  std::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionPca;
200 
201  void _buildKernelSolution(afw::math::KernelList const& basisList,
202  Eigen::MatrixXd const& hMat);
203  };
204 
205 
217  template <typename PixelT>
219  makeKernelCandidate(float const xCenter,
220  float const yCenter,
221  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
222  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& scienceMaskedImage,
223  pex::policy::Policy const& policy){
224 
226  templateMaskedImage,
227  scienceMaskedImage,
228  policy));
229  }
230 
242  template <typename PixelT>
245  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
246  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& scienceMaskedImage,
247  pex::policy::Policy const& policy){
248 
250  templateMaskedImage,
251  scienceMaskedImage,
252  policy));
253  }
254 
255 
256 }}} // end of namespace lsst::ip::diffim
257 
258 #endif
double getBackground(CandidateSwitch cand) const
Class stored in SpatialCells for spatial Kernel fitting.
double getCandidateRating() const
Return Candidate rating.
afw::image::MaskedImage< PixelT > getDifferenceImage(CandidateSwitch cand)
Calculate associated difference image using internal solutions.
std::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
std::shared_ptr< afw::math::Kernel > getKernel(CandidateSwitch cand) const
Return results of kernel solution.
void build(afw::math::KernelList const &basisList)
Core functionality of KernelCandidate, to build and fill a KernelSolution.
#define PTR(...)
boost::shared_ptr< ImageT > getKernelImage(CandidateSwitch cand) const
#define CONST_PTR(...)
Declaration of classes to store the solution for convolution kernels.
std::shared_ptr< afw::image::Image< afw::image::VariancePixel > > VariancePtr
std::shared_ptr< KernelCandidate > Ptr
MaskedImagePtr getTemplateMaskedImage()
Return pointers to the image pixels used in kernel determination.
afw::image::Image< afw::math::Kernel::Pixel > ImageT
virtual ~KernelCandidate()
Destructor.
std::shared_ptr< afw::image::MaskedImage< PixelT > > MaskedImagePtr
SourcePtr getSource() const
Return the original source.
STL class.
boost::shared_ptr< ImageT const > getImage() const
KernelCandidate(float const xCenter, float const yCenter, MaskedImagePtr const &templateMaskedImage, MaskedImagePtr const &scienceMaskedImage, pex::policy::Policy const &policy)
Constructor.
std::shared_ptr< afw::table::SourceRecord > SourcePtr
double getKsum(CandidateSwitch cand) const
std::shared_ptr< KernelCandidate< PixelT > > makeKernelCandidate(float const xCenter, float const yCenter, std::shared_ptr< afw::image::MaskedImage< PixelT > > const &templateMaskedImage, std::shared_ptr< afw::image::MaskedImage< PixelT > > const &scienceMaskedImage, pex::policy::Policy const &policy)
Return a KernelCandidate pointer of the right sort.