LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | List of all members
lsst::ip::diffim::detail::KernelPcaVisitor< PixelT > Class Template Reference

A class to run a PCA on all candidate kernels (represented as Images). More...

#include <KernelPca.h>

Inheritance diagram for lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >:
lsst::afw::math::CandidateVisitor

Public Types

typedef lsst::afw::image::Image< lsst::afw::math::Kernel::PixelImageT
 
typedef std::shared_ptr< KernelPcaVisitor< PixelT > > Ptr
 

Public Member Functions

 KernelPcaVisitor (std::shared_ptr< KernelPca< ImageT > > imagePca)
 
virtual ~KernelPcaVisitor ()
 
lsst::afw::math::KernelList getEigenKernels ()
 
void processCandidate (lsst::afw::math::SpatialCellCandidate *candidate)
 
void subtractMean ()
 
std::shared_ptr< ImageTreturnMean ()
 
virtual void reset ()
 

Detailed Description

template<typename PixelT>
class lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >

A class to run a PCA on all candidate kernels (represented as Images).

Note
Templated on the pixel types of the MaskedImages it will be visiting (typically float).
Works in concert with a afwMath::SpatialCellSet and ip::Diffim KernelPca to create a Karhunen-Loeve basis from all the good KernelCandidates. This class adds the extra functionality to subtract off the mean kernel from all entries, which makes the resulting basis more compact. The user needs to manually add this mean image into the resulting basis list after imagePca.analyze() is called.
KernelPca (and base class afwImage::ImagePca) weight objects of different brightness differently. However we don't necessarily want images with larger kernel sums to have more weight. Each kernel should have constant weight in the Pca. For simplicity we scale them to have the same kernel sum, 1.0, and send to ImagePca that the flux (weight) is 1.0.

Definition at line 40 of file KernelPca.h.

Member Typedef Documentation

◆ ImageT

Definition at line 42 of file KernelPca.h.

◆ Ptr

Definition at line 43 of file KernelPca.h.

Constructor & Destructor Documentation

◆ KernelPcaVisitor()

Parameters
imagePcaSet of Images to initialise

Definition at line 56 of file KernelPca.cc.

58  :
60  _imagePca(imagePca),
61  _mean()
62  {};

◆ ~KernelPcaVisitor()

template<typename PixelT >
virtual lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::~KernelPcaVisitor ( )
inlinevirtual

Definition at line 46 of file KernelPca.h.

46 {};

Member Function Documentation

◆ getEigenKernels()

template<typename PixelT >
lsst::afw::math::KernelList lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::getEigenKernels

Definition at line 65 of file KernelPca.cc.

65  {
66  afwMath::KernelList kernelList;
67 
68  std::vector<std::shared_ptr<ImageT>> eigenImages = _imagePca->getEigenImages();
69  int ncomp = eigenImages.size();
70 
71  if (_mean) {
75  (*_mean, true))));
76  }
77  for (int i = 0; i < ncomp; i++) {
79  afwImage::Image<afwMath::Kernel::Pixel>(*eigenImages[i], true);
81  new afwMath::FixedKernel(img)
82  ));
83  }
84 
85  return kernelList;
86  }
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:51
A kernel created from an Image.
Definition: Kernel.h:471
T push_back(T... args)
T size(T... args)

◆ processCandidate()

template<typename PixelT >
void lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::processCandidate ( lsst::afw::math::SpatialCellCandidate candidate)
virtual

Reimplemented from lsst::afw::math::CandidateVisitor.

Definition at line 89 of file KernelPca.cc.

89  {
90 
91  KernelCandidate<PixelT> *kCandidate = dynamic_cast<KernelCandidate<PixelT> *>(candidate);
92  if (kCandidate == NULL) {
94  "Failed to cast SpatialCellCandidate to KernelCandidate");
95  }
96  LOGL_DEBUG("TRACE5.ip.diffim.SetPcaImageVisitor.processCandidate",
97  "Processing candidate %d", kCandidate->getId());
98 
99  try {
100  /* Normalize to unit sum */
101  std::shared_ptr<ImageT> kImage = kCandidate->getKernelSolution(
102  KernelCandidate<PixelT>::ORIG)->makeKernelImage();
103  *kImage /= kCandidate->getKernelSolution(
104  KernelCandidate<PixelT>::ORIG)->getKsum();
105  /* Tell imagePca they have the same weighting in the Pca */
106  _imagePca->addImage(kImage, 1.0);
107  } catch(pexExcept::Exception &e) {
108  return;
109  }
110  }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:515
Provides consistent interface for LSST exceptions.
Definition: Exception.h:107
Reports errors in the logical structure of the program.
Definition: Runtime.h:46

◆ reset()

virtual void lsst::afw::math::CandidateVisitor::reset ( )
inlinevirtualinherited

◆ returnMean()

template<typename PixelT >
std::shared_ptr<ImageT> lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::returnMean ( )
inline

Definition at line 51 of file KernelPca.h.

51 {return _mean;}

◆ subtractMean()

template<typename PixelT >
void lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::subtractMean

Definition at line 113 of file KernelPca.cc.

113  {
114  /*
115  If we don't subtract off the mean before we do the Pca, the
116  subsequent terms carry less of the power than if you do subtract
117  off the mean. Explicit example:
118 
119  With mean subtraction:
120  DEBUG: Eigenvalue 0 : 0.010953 (0.373870 %)
121  DEBUG: Eigenvalue 1 : 0.007927 (0.270604 %)
122  DEBUG: Eigenvalue 2 : 0.001393 (0.047542 %)
123  DEBUG: Eigenvalue 3 : 0.001092 (0.037261 %)
124  DEBUG: Eigenvalue 4 : 0.000829 (0.028283 %)
125 
126  Without mean subtraction:
127  DEBUG: Eigenvalue 0 : 0.168627 (0.876046 %)
128  DEBUG: Eigenvalue 1 : 0.007935 (0.041223 %)
129  DEBUG: Eigenvalue 2 : 0.006049 (0.031424 %)
130  DEBUG: Eigenvalue 3 : 0.001188 (0.006173 %)
131  DEBUG: Eigenvalue 4 : 0.001050 (0.005452 %)
132 
133  After the first term above, which basically represents the mean,
134  the remaining terms carry less of the power than if you do
135  subtract off the mean. (0.041223/(1-0.876046) < 0.373870).
136  */
137  LOGL_DEBUG("TRACE5.ip.diffim.KernelPcaVisitor.subtractMean",
138  "Subtracting mean feature before Pca");
139 
140  _mean = _imagePca->getMean();
141  KernelPca<ImageT>::ImageList imageList = _imagePca->getImageList();
142  for (typename KernelPca<ImageT>::ImageList::const_iterator ptr = imageList.begin(),
143  end = imageList.end(); ptr != end; ++ptr) {
144  **ptr -= *_mean;
145  }
146  }
int end
uint64_t * ptr
Definition: RangeSet.cc:88
std::vector< std::shared_ptr< ImageT > > ImageList
Definition: ImagePca.h:47

The documentation for this class was generated from the following files: