LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Private Attributes | 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::Pixel
ImageT
 
typedef boost::shared_ptr
< KernelPcaVisitor< PixelT > > 
Ptr
 

Public Member Functions

 KernelPcaVisitor (boost::shared_ptr< KernelPca< ImageT > > imagePca)
 
virtual ~KernelPcaVisitor ()
 
lsst::afw::math::KernelList getEigenKernels ()
 
void processCandidate (lsst::afw::math::SpatialCellCandidate *candidate)
 
void subtractMean ()
 
boost::shared_ptr< ImageTreturnMean ()
 
- Public Member Functions inherited from lsst::afw::math::CandidateVisitor
 CandidateVisitor ()
 
virtual ~CandidateVisitor ()
 
virtual void reset ()
 

Private Attributes

boost::shared_ptr< KernelPca
< ImageT > > 
_imagePca
 Structure to fill with images. More...
 
boost::shared_ptr< ImageT_mean
 Mean image calculated before Pca. More...
 

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

Definition at line 42 of file KernelPca.h.

template<typename PixelT >
typedef boost::shared_ptr<KernelPcaVisitor<PixelT> > lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::Ptr

Definition at line 43 of file KernelPca.h.

Constructor & Destructor Documentation

template<typename PixelT >
lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::KernelPcaVisitor ( boost::shared_ptr< KernelPca< ImageT > >  imagePca)
Parameters
imagePcaSet of Images to initialise

Definition at line 57 of file KernelPca.cc.

59  :
61  _imagePca(imagePca),
62  _mean()
63  {};
boost::shared_ptr< ImageT > _mean
Mean image calculated before Pca.
Definition: KernelPca.h:54
boost::shared_ptr< KernelPca< ImageT > > _imagePca
Structure to fill with images.
Definition: KernelPca.h:53
template<typename PixelT >
virtual lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::~KernelPcaVisitor ( )
inlinevirtual

Definition at line 46 of file KernelPca.h.

46 {};

Member Function Documentation

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

Definition at line 66 of file KernelPca.cc.

66  {
67  afwMath::KernelList kernelList;
68 
69  std::vector<typename ImageT::Ptr> eigenImages = _imagePca->getEigenImages();
70  int ncomp = eigenImages.size();
71 
72  if (_mean) {
73  kernelList.push_back(afwMath::Kernel::Ptr(
76  (*_mean, true))));
77  }
78  for (int i = 0; i < ncomp; i++) {
80  afwImage::Image<afwMath::Kernel::Pixel>(*eigenImages[i], true);
81  kernelList.push_back(afwMath::Kernel::Ptr(
82  new afwMath::FixedKernel(img)
83  ));
84  }
85 
86  return kernelList;
87  }
boost::shared_ptr< ImageT > _mean
Mean image calculated before Pca.
Definition: KernelPca.h:54
boost::shared_ptr< Kernel > Ptr
Definition: Kernel.h:141
boost::shared_ptr< KernelPca< ImageT > > _imagePca
Structure to fill with images.
Definition: KernelPca.h:53
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415
A kernel created from an Image.
Definition: Kernel.h:551
std::vector< boost::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:542
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 90 of file KernelPca.cc.

90  {
91 
92  KernelCandidate<PixelT> *kCandidate = dynamic_cast<KernelCandidate<PixelT> *>(candidate);
93  if (kCandidate == NULL) {
94  throw LSST_EXCEPT(pexExcept::LogicError,
95  "Failed to cast SpatialCellCandidate to KernelCandidate");
96  }
97  pexLogging::TTrace<6>("lsst.ip.diffim.SetPcaImageVisitor.processCandidate",
98  "Processing candidate %d", kCandidate->getId());
99 
100  try {
101  /* Normalize to unit sum */
102  PTR(ImageT) kImage = kCandidate->getKernelSolution(
103  KernelCandidate<PixelT>::ORIG)->makeKernelImage();
104  *kImage /= kCandidate->getKernelSolution(
105  KernelCandidate<PixelT>::ORIG)->getKsum();
106  /* Tell imagePca they have the same weighting in the Pca */
107  _imagePca->addImage(kImage, 1.0);
108  } catch(pexExcept::Exception &e) {
109  return;
110  }
111  }
#define PTR(...)
Definition: base.h:41
boost::shared_ptr< KernelPca< ImageT > > _imagePca
Structure to fill with images.
Definition: KernelPca.h:53
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > ImageT
Definition: KernelPca.h:42
template<typename PixelT >
boost::shared_ptr< ImageT > lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::returnMean ( )
inline

Definition at line 51 of file KernelPca.h.

51 {return _mean;}
boost::shared_ptr< ImageT > _mean
Mean image calculated before Pca.
Definition: KernelPca.h:54
template<typename PixelT >
void lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::subtractMean ( )

Definition at line 114 of file KernelPca.cc.

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

Member Data Documentation

template<typename PixelT >
boost::shared_ptr<KernelPca<ImageT> > lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::_imagePca
private

Structure to fill with images.

Definition at line 53 of file KernelPca.h.

template<typename PixelT >
boost::shared_ptr< ImageT > lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::_mean
private

Mean image calculated before Pca.

Definition at line 54 of file KernelPca.h.


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