LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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 "boost/shared_ptr.hpp"
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 boost::shared_ptr<KernelCandidate> Ptr;
49  typedef boost::shared_ptr<afw::image::MaskedImage<PixelT> > MaskedImagePtr;
50  typedef boost::shared_ptr<afw::image::Image<afw::image::VariancePixel> > VariancePtr;
51  typedef boost::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  boost::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  boost::shared_ptr<Eigen::MatrixXd> hMat
187  );
188 
189  private:
195  double _coreFlux;
199 
200  /* best single raw kernel */
201  boost::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionOrig;
202 
203  /* with Pca basis */
204  boost::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionPca;
205 
206  void _buildKernelSolution(afw::math::KernelList const& basisList,
207  boost::shared_ptr<Eigen::MatrixXd> hMat);
208  };
209 
210 
222  template <typename PixelT>
223  boost::shared_ptr<KernelCandidate<PixelT> >
224  makeKernelCandidate(float const xCenter,
225  float const yCenter,
226  boost::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
227  boost::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  boost::shared_ptr<KernelCandidate<PixelT> >
249  makeKernelCandidate(boost::shared_ptr<afw::table::SourceRecord> const & source,
250  boost::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
251  boost::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.
boost::shared_ptr< StaticKernelSolution< PixelT > > _kernelSolutionOrig
Original basis solution.
#define PTR(...)
Definition: base.h:41
MaskedImagePtr _scienceMaskedImage
Subimage around which you build kernel.
Class stored in SpatialCells for spatial Kernel fitting.
void _buildKernelSolution(afw::math::KernelList const &basisList, boost::shared_ptr< Eigen::MatrixXd > hMat)
boost::shared_ptr< afw::table::SourceRecord > SourcePtr
a container for holding hierarchical configuration data in memory.
Definition: Policy.h:169
#define CONST_PTR(...)
Definition: base.h:47
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.
afw::math::Kernel::Ptr getKernel(CandidateSwitch cand) const
Return results of kernel solution.
boost::shared_ptr< Kernel > Ptr
Definition: Kernel.h:141
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< 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
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:77
VariancePtr _varianceEstimate
Estimate of the local variance.
boost::shared_ptr< KernelCandidate< PixelT > > makeKernelCandidate(float const xCenter, float const yCenter, boost::shared_ptr< afw::image::MaskedImage< PixelT > > const &templateMaskedImage, boost::shared_ptr< afw::image::MaskedImage< PixelT > > const &scienceMaskedImage, pex::policy::Policy const &policy)
Return a KernelCandidate pointer of the right sort.
boost::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
double _coreFlux
Mean S/N in the science image.
boost::shared_ptr< afw::image::MaskedImage< PixelT > > MaskedImagePtr
MaskedImagePtr _templateMaskedImage
Subimage around which you build kernel.
bool _useRegularization
Use regularization?
double getBackground(CandidateSwitch cand) const
boost::shared_ptr< StaticKernelSolution< PixelT > > _kernelSolutionPca
Most recent solution.
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.
std::vector< boost::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:542
SourcePtr getSource() const
Return the original source.
A class to represent a 2-dimensional array of pixels.
Definition: PSF.h:43
boost::shared_ptr< afw::image::Image< afw::image::VariancePixel > > VariancePtr