12 #include "lsst/afw/math.h"
13 #include "lsst/afw/image.h"
14 #include "lsst/log/Log.h"
15 #include "lsst/pex/exceptions/Runtime.h"
20 namespace afwMath = lsst::afw::math;
21 namespace afwImage = lsst::afw::image;
22 namespace pexExcept = lsst::pex::exceptions;
55 template<
typename PixelT>
59 afwMath::CandidateVisitor(),
64 template<
typename PixelT>
66 afwMath::KernelList kernelList;
68 std::vector<std::shared_ptr<ImageT>> eigenImages = _imagePca->getEigenImages();
69 int ncomp = eigenImages.size();
72 kernelList.push_back(std::shared_ptr<afwMath::Kernel>(
73 new afwMath::FixedKernel(
74 afwImage::Image<afwMath::Kernel::Pixel>
77 for (
int i = 0; i < ncomp; i++) {
78 afwImage::Image<afwMath::Kernel::Pixel> img =
79 afwImage::Image<afwMath::Kernel::Pixel>(*eigenImages[i],
true);
80 kernelList.push_back(std::shared_ptr<afwMath::Kernel>(
81 new afwMath::FixedKernel(img)
88 template<
typename PixelT>
92 if (kCandidate == NULL) {
93 throw LSST_EXCEPT(pexExcept::LogicError,
94 "Failed to cast SpatialCellCandidate to KernelCandidate");
96 LOGL_DEBUG(
"TRACE5.ip.diffim.SetPcaImageVisitor.processCandidate",
97 "Processing candidate %d", kCandidate->getId());
106 _imagePca->addImage(kImage, 1.0);
107 }
catch(pexExcept::Exception &e) {
112 template<
typename PixelT>
137 LOGL_DEBUG(
"TRACE5.ip.diffim.KernelPcaVisitor.subtractMean",
138 "Subtracting mean feature before Pca");
140 _mean = _imagePca->getMean();
143 end = imageList.end(); ptr != end; ++ptr) {
162 template <
typename ImageT>
167 typename Super::ImageList
const &eImageList = this->getEigenImages();
168 typename Super::ImageList::const_iterator iter = eImageList.begin(), end = eImageList.end();
169 for (
size_t i = 0; iter != end; ++i, ++iter) {
170 PTR(ImageT) eImage = *iter;
176 afwMath::Statistics stats = afwMath::makeStatistics(*eImage, (afwMath::MIN | afwMath::MAX));
177 double const min = stats.getValue(afwMath::MIN);
178 double const max = stats.getValue(afwMath::MAX);
180 double const extreme = (fabs(min) > max) ? min :max;
181 if (extreme != 0.0) {
Class stored in SpatialCells for spatial Kernel fitting.
KernelPcaVisitor(std::shared_ptr< KernelPca< ImageT > > imagePca)
std::shared_ptr< StaticKernelSolution< PixelT > > getKernelSolution(CandidateSwitch cand) const
A class to run a PCA on all candidate kernels (represented as Images).
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate)
lsst::afw::math::KernelList getEigenKernels()
Overrides the analyze method of base class afwImage::ImagePca.
Declaration of KernelPca and KernelPcaVisitor.
Class used by SpatialModelCell for spatial Kernel fitting.
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > ImageT
virtual void analyze()
Generate eigenimages that are normalised.