lsst.ip.diffim  13.0-22-g3839dbb+23
kernelPca.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  *
4  * This product includes software developed by the
5  * LSST Project (http://www.lsst.org/).
6  * See the COPYRIGHT file
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 #include "pybind11/pybind11.h"
23 #include "pybind11/stl.h"
24 
25 #include <memory>
26 #include <string>
27 
28 #include "lsst/afw/image/ImagePca.h"
29 #include "lsst/afw/math/Kernel.h"
30 #include "lsst/afw/math/SpatialCell.h"
32 
33 namespace py = pybind11;
34 using namespace pybind11::literals;
35 
36 namespace lsst {
37 namespace ip {
38 namespace diffim {
39 namespace detail {
40 
41 namespace {
42 
50 template <typename PixelT>
51 void declareKernelPca(py::module& mod, std::string const& suffix) {
52  using ImageT = afw::image::Image<PixelT>;
53  py::class_<KernelPca<ImageT>, std::shared_ptr<KernelPca<ImageT>>, afw::image::ImagePca<ImageT>> cls(
54  mod, ("KernelPca" + suffix).c_str());
55 
56  cls.def(py::init<bool>(), "constantWeight"_a = true);
57 
58  cls.def("analyze", &KernelPca<ImageT>::analyze);
59 }
60 
68 template <typename PixelT>
69 void declareKernelPcaVisitor(py::module& mod, std::string const& suffix) {
70  py::class_<KernelPcaVisitor<PixelT>, std::shared_ptr<KernelPcaVisitor<PixelT>>,
71  afw::math::CandidateVisitor>
72  cls(mod, ("KernelPcaVisitor" + suffix).c_str());
73 
74  // note that KernelPcaVisitor<PixelT>::ImageT
75  // is always the same (pixels of type lsst::afw::math::Kernel::Pixel, not PixelT)
76  using KernelImageT = typename KernelPcaVisitor<PixelT>::ImageT;
77  cls.def(py::init<std::shared_ptr<KernelPca<KernelImageT>>>(), "imagePca"_a);
78 
79  cls.def("getEigenKernels", &KernelPcaVisitor<PixelT>::getEigenKernels);
80  cls.def("processCandidate", &KernelPcaVisitor<PixelT>::processCandidate, "candidate"_a);
81  cls.def("subtractMean", &KernelPcaVisitor<PixelT>::subtractMean);
82  cls.def("returnMean", &KernelPcaVisitor<PixelT>::returnMean);
83 
84  mod.def("makeKernelPcaVisitor", &makeKernelPcaVisitor<PixelT>, "imagePca"_a);
85 }
86 
87 } // namespace lsst::ip::diffim::detail::<anonymous>
88 
90  py::module::import("lsst.afw.image");
91  py::module::import("lsst.afw.math");
92 
93  py::module mod("kernelPca");
94 
95  declareKernelPca<afw::math::Kernel::Pixel>(mod, "D");
96  declareKernelPcaVisitor<float>(mod, "F");
97 
98  return mod.ptr();
99 }
100 
101 } // detail
102 } // diffim
103 } // ip
104 } // lsst::ip::diffim::detail
PYBIND11_PLUGIN(kernelPca)
Definition: kernelPca.cc:89
Declaration of KernelPca and KernelPcaVisitor.