LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
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 afw::math::SpatialCellImageCandidate<afw::math::Kernel::Pixel> {
40  public:
42  typedef _PixelT PixelT; // _after_ afw::math::Kernel::Pixel
43 
44  private:
46 
47  public:
48  typedef std::shared_ptr<KernelCandidate> Ptr;
49  typedef std::shared_ptr<afw::image::MaskedImage<PixelT> > MaskedImagePtr;
50  typedef std::shared_ptr<afw::image::Image<afw::image::VariancePixel> > VariancePtr;
51  typedef std::shared_ptr<afw::table::SourceRecord> SourcePtr;
52 
54  ORIG = 0,
55  PCA = 1,
56  RECENT = 2
57  };
58 
68  KernelCandidate(float const xCenter,
69  float const yCenter,
70  MaskedImagePtr const& templateMaskedImage,
71  MaskedImagePtr const& scienceMaskedImage,
72  pex::policy::Policy const& policy);
73 
83  KernelCandidate(SourcePtr const& source,
84  MaskedImagePtr const& templateMaskedImage,
85  MaskedImagePtr const& scienceMaskedImage,
86  pex::policy::Policy const& policy);
88  virtual ~KernelCandidate() {};
89 
95  double getCandidateRating() const { return _coreFlux; }
99  SourcePtr getSource() const { return _source; }
105 
111  double getBackground(CandidateSwitch cand) const;
112  double getKsum(CandidateSwitch cand) const;
114  CONST_PTR(ImageT) getImage() const; // For SpatialCellImageCandidate
115  std::shared_ptr<StaticKernelSolution<PixelT> > getKernelSolution(CandidateSwitch cand) const;
116 
120  afw::image::MaskedImage<PixelT> getDifferenceImage(CandidateSwitch cand);
121 
127  afw::image::MaskedImage<PixelT> getDifferenceImage(
128  afw::math::Kernel::Ptr kernel,
129  double background
130  );
131 
132  bool isInitialized() const {return _isInitialized;}
133 
134 
169  /*
170  * @note This method uses an estimate of the variance which is the
171  * straight difference of the 2 images. If requested in the Policy
172  * ("iterateSingleKernel"), the kernel will be rebuilt using the
173  * variance of the difference image resulting from this first
174  * approximate step. This is particularly useful when convolving a
175  * single-depth science image; the variance (and thus resulting kernel)
176  * generally converges after 1 iteration. If
177  * "constantVarianceWeighting" is requested in the Policy, no iterations
178  * will be performed even if requested.
179  */
180 
181  void build(
182  afw::math::KernelList const& basisList
183  );
184  void build(
185  afw::math::KernelList const& basisList,
186  std::shared_ptr<Eigen::MatrixXd> hMat
187  );
188 
189  private:
195  double _coreFlux;
199 
200  /* best single raw kernel */
201  std::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionOrig;
202 
203  /* with Pca basis */
204  std::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionPca;
205 
206  void _buildKernelSolution(afw::math::KernelList const& basisList,
207  std::shared_ptr<Eigen::MatrixXd> hMat);
208  };
209 
210 
222  template <typename PixelT>
223  std::shared_ptr<KernelCandidate<PixelT> >
224  makeKernelCandidate(float const xCenter,
225  float const yCenter,
226  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
227  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& scienceMaskedImage,
228  pex::policy::Policy const& policy){
229 
230  return typename KernelCandidate<PixelT>::Ptr(new KernelCandidate<PixelT>(xCenter, yCenter,
231  templateMaskedImage,
232  scienceMaskedImage,
233  policy));
234  }
235 
247  template <typename PixelT>
248  std::shared_ptr<KernelCandidate<PixelT> >
249  makeKernelCandidate(std::shared_ptr<afw::table::SourceRecord> const & source,
250  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
251  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& scienceMaskedImage,
252  pex::policy::Policy const& policy){
253 
254  return typename KernelCandidate<PixelT>::Ptr(new KernelCandidate<PixelT>(source,
255  templateMaskedImage,
256  scienceMaskedImage,
257  policy));
258  }
259 
260 
261 }}} // end of namespace lsst::ip::diffim
262 
263 #endif
An include file to include the public header files for lsst::afw::math.
boost::shared_ptr< ImageT const > getImage() const
Return the Candidate&#39;s Image.
bool _isInitialized
Has the kernel been built.
MaskedImagePtr _scienceMaskedImage
Subimage around which you build kernel.
Class stored in SpatialCells for spatial Kernel fitting.
a container for holding hierarchical configuration data in memory.
Definition: Policy.h:169
std::shared_ptr< StaticKernelSolution< PixelT > > _kernelSolutionOrig
Original basis solution.
afw::image::MaskedImage< PixelT > getDifferenceImage(CandidateSwitch cand)
Calculate associated difference image using internal solutions.
void build(afw::math::KernelList const &basisList)
Core functionality of KernelCandidate, to build and fill a KernelSolution.
std::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
afw::math::Kernel::Ptr getKernel(CandidateSwitch cand) const
Return results of kernel solution.
#define CONST_PTR(...)
Definition: base.h:47
void _buildKernelSolution(afw::math::KernelList const &basisList, std::shared_ptr< Eigen::MatrixXd > hMat)
Declaration of classes to store the solution for convolution kernels.
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
An include file to include the header files for lsst::afw::image.
boost::shared_ptr< Kernel > Ptr
Definition: Kernel.h:138
std::shared_ptr< afw::image::Image< afw::image::VariancePixel > > VariancePtr
std::shared_ptr< KernelCandidate > Ptr
pex::policy::Policy _policy
Policy.
MaskedImagePtr getTemplateMaskedImage()
Return pointers to the image pixels used in kernel determination.
afw::image::Image< afw::math::Kernel::Pixel > ImageT
virtual ~KernelCandidate()
Destructor.
double getKsum(CandidateSwitch cand) const
std::shared_ptr< afw::image::MaskedImage< PixelT > > MaskedImagePtr
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:78
VariancePtr _varianceEstimate
Estimate of the local variance.
double _coreFlux
Mean S/N in the science image.
MaskedImagePtr _templateMaskedImage
Subimage around which you build kernel.
bool _useRegularization
Use regularization?
#define PTR(...)
Definition: base.h:41
double getBackground(CandidateSwitch cand) const
double getCandidateRating() const
Return Candidate rating.
boost::shared_ptr< ImageT > getKernelImage(CandidateSwitch cand) const
KernelCandidate(float const xCenter, float const yCenter, MaskedImagePtr const &templateMaskedImage, MaskedImagePtr const &scienceMaskedImage, pex::policy::Policy const &policy)
Constructor.
SourcePtr getSource() const
Return the original source.
std::shared_ptr< afw::table::SourceRecord > SourcePtr
A class to represent a 2-dimensional array of pixels.
Definition: PSF.h:43
std::shared_ptr< StaticKernelSolution< PixelT > > _kernelSolutionPca
Most recent solution.
std::vector< boost::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:539
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.