LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+b2075782a9,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g3ddfee87b4+a60788ef87,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+a60788ef87,g591dd9f2cf+ba8caea58f,g5ec818987f+864ee9cddb,g858d7b2824+9ee1ab4172,g876c692160+a40945ebb7,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+5e309b7bc6,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+aa12a14d27,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+d0da15e3be,gba4ed39666+1ac82b564f,gbb8dafda3b+5dfd9c994b,gbeb006f7da+97157f9740,gc28159a63d+c6dfa2ddaf,gc86a011abf+9ee1ab4172,gcf0d15dbbd+a60788ef87,gdaeeff99f8+1cafcb7cd4,gdc0c513512+9ee1ab4172,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,geb961e4c1e+f9439d1e6f,gee10cc3b42+90ebb246c7,gf1cff7945b+9ee1ab4172,w.2024.12
LSST Data Management Base Package
Loading...
Searching...
No Matches
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()

template<typename PixelT >
lsst::ip::diffim::detail::KernelPcaVisitor< PixelT >::KernelPcaVisitor ( std::shared_ptr< KernelPca< ImageT > > imagePca)
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()

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);
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(
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:95
std::vector< std::shared_ptr< ImageT > > ImageList
Definition ImagePca.h:47

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