LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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 #include "lsst/pex/policy.h"
23 
24 namespace lsst {
25 namespace ip {
26 namespace diffim {
27 
28 
38  template <typename _PixelT>
40  public:
42  typedef _PixelT PixelT; // _after_ afw::math::Kernel::Pixel
43  public:
48 
50  ORIG = 0,
51  PCA = 1,
52  RECENT = 2
53  };
54 
64  KernelCandidate(float const xCenter,
65  float const yCenter,
66  MaskedImagePtr const& templateMaskedImage,
67  MaskedImagePtr const& scienceMaskedImage,
68  pex::policy::Policy const& policy);
69 
79  KernelCandidate(SourcePtr const& source,
80  MaskedImagePtr const& templateMaskedImage,
81  MaskedImagePtr const& scienceMaskedImage,
82  pex::policy::Policy const& policy);
84  virtual ~KernelCandidate() {};
85 
91  double getCandidateRating() const { return _coreFlux; }
95  SourcePtr getSource() const { return _source; }
99  MaskedImagePtr getTemplateMaskedImage() {return _templateMaskedImage;}
100  MaskedImagePtr getScienceMaskedImage() {return _scienceMaskedImage;}
101 
107  double getBackground(CandidateSwitch cand) const;
108  double getKsum(CandidateSwitch cand) const;
109  PTR(ImageT) getKernelImage(CandidateSwitch cand) const;
110  CONST_PTR(ImageT) getImage() const; // For SpatialCellImageCandidate
112 
117 
125  double background
126  );
127 
128  bool isInitialized() const {return _isInitialized;}
129 
130 
165  /*
166  * @note This method uses an estimate of the variance which is the
167  * straight difference of the 2 images. If requested in the Policy
168  * ("iterateSingleKernel"), the kernel will be rebuilt using the
169  * variance of the difference image resulting from this first
170  * approximate step. This is particularly useful when convolving a
171  * single-depth science image; the variance (and thus resulting kernel)
172  * generally converges after 1 iteration. If
173  * "constantVarianceWeighting" is requested in the Policy, no iterations
174  * will be performed even if requested.
175  */
176 
177  void build(
178  afw::math::KernelList const& basisList
179  );
180  void build(
181  afw::math::KernelList const& basisList,
182  Eigen::MatrixXd const& hMat
183  );
184 
185  private:
186  MaskedImagePtr _templateMaskedImage;
187  MaskedImagePtr _scienceMaskedImage;
188  VariancePtr _varianceEstimate;
189  pex::policy::Policy _policy;
190  SourcePtr _source;
191  double _coreFlux;
192  bool _isInitialized;
193  bool _useRegularization;
194  bool _fitForBackground;
195 
196  /* best single raw kernel */
197  std::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionOrig;
198 
199  /* with Pca basis */
200  std::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionPca;
201 
202  void _buildKernelSolution(afw::math::KernelList const& basisList,
203  Eigen::MatrixXd const& hMat);
204  };
205 
206 
218  template <typename PixelT>
220  makeKernelCandidate(float const xCenter,
221  float const yCenter,
222  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
223  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& scienceMaskedImage,
224  pex::policy::Policy const& policy){
225 
227  templateMaskedImage,
228  scienceMaskedImage,
229  policy));
230  }
231 
243  template <typename PixelT>
246  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
247  std::shared_ptr<afw::image::MaskedImage<PixelT> > const& scienceMaskedImage,
248  pex::policy::Policy const& policy){
249 
251  templateMaskedImage,
252  scienceMaskedImage,
253  policy));
254  }
255 
256 
257 }}} // end of namespace lsst::ip::diffim
258 
259 #endif
double getBackground(CandidateSwitch cand) const
Class stored in SpatialCells for spatial Kernel fitting.
#define CONST_PTR(...)
A shared pointer to a const object.
Definition: base.h:47
double getCandidateRating() const
Return Candidate rating.
a container for holding hierarchical configuration data in memory.
Definition: Policy.h:169
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.
boost::shared_ptr< ImageT > getKernelImage(CandidateSwitch cand) const
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
A base class for image defects.
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
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:74
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
SourcePtr getSource() const
Return the original source.
boost::shared_ptr< ImageT const > getImage() const
Base class for candidate objects in a SpatialCell that are able to return an Image of some sort (e...
Definition: SpatialCell.h:126
#define PTR(...)
Definition: base.h:41
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
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:59
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.