LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
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:
41  typedef _PixelT PixelT; // _after_ afw::math::Kernel::Pixel
42  public:
43  typedef std::shared_ptr<KernelCandidate> Ptr;
44  typedef std::shared_ptr<afw::image::MaskedImage<PixelT> > MaskedImagePtr;
45  typedef std::shared_ptr<afw::image::Image<afw::image::VariancePixel> > VariancePtr;
46  typedef std::shared_ptr<afw::table::SourceRecord> SourcePtr;
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; }
100 
106  double getBackground(CandidateSwitch cand) const;
107  double getKsum(CandidateSwitch cand) const;
109  CONST_PTR(ImageT) getImage() const; // For SpatialCellImageCandidate
110  std::shared_ptr<StaticKernelSolution<PixelT> > getKernelSolution(CandidateSwitch cand) const;
111 
115  afw::image::MaskedImage<PixelT> getDifferenceImage(CandidateSwitch cand);
116 
122  afw::image::MaskedImage<PixelT> getDifferenceImage(
123  afw::math::Kernel::Ptr kernel,
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  std::shared_ptr<Eigen::MatrixXd> hMat
182  );
183 
184  private:
190  double _coreFlux;
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  std::shared_ptr<Eigen::MatrixXd> hMat);
203  };
204 
205 
217  template <typename PixelT>
218  std::shared_ptr<KernelCandidate<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 
225  return typename KernelCandidate<PixelT>::Ptr(new KernelCandidate<PixelT>(xCenter, yCenter,
226  templateMaskedImage,
227  scienceMaskedImage,
228  policy));
229  }
230 
242  template <typename PixelT>
243  std::shared_ptr<KernelCandidate<PixelT> >
244  makeKernelCandidate(std::shared_ptr<afw::table::SourceRecord> const & source,
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 
249  return typename KernelCandidate<PixelT>::Ptr(new KernelCandidate<PixelT>(source,
250  templateMaskedImage,
251  scienceMaskedImage,
252  policy));
253  }
254 
255 
256 }}} // end of namespace lsst::ip::diffim
257 
258 #endif
An include file to include the public header files for lsst::afw::math.
boost::shared_ptr< ImageT const > getImage() const
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.
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.
Base class for candidate objects in a SpatialCell that are able to return an Image of some sort (e...
Definition: SpatialCell.h:132
#define PTR(...)
Definition: base.h:41
MaskedImagePtr _templateMaskedImage
Subimage around which you build kernel.
bool _useRegularization
Use regularization?
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.
#define CONST_PTR(...)
A shared pointer to a const object.
Definition: base.h:47
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: Image.h:416
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.