lsst.ip.diffim  13.0-22-g3839dbb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
buildSpatialKernelVisitor.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 <Eigen/Core>
29 #include "numpy/arrayobject.h"
30 #include "ndarray/pybind11.h"
31 
32 #include "lsst/afw/math.h"
34 #include "lsst/pex/policy/Policy.h"
35 
36 namespace py = pybind11;
37 using namespace pybind11::literals;
38 
39 namespace lsst {
40 namespace ip {
41 namespace diffim {
42 namespace detail {
43 
44 namespace {
45 
53 template <typename PixelT>
54 void declareBuildSpatialKernelVisitor(py::module& mod, std::string const& suffix) {
55  py::class_<BuildSpatialKernelVisitor<PixelT>, std::shared_ptr<BuildSpatialKernelVisitor<PixelT>>,
56  afw::math::CandidateVisitor>
57  cls(mod, ("BuildSpatialKernelVisitor" + suffix).c_str());
58 
59  cls.def(py::init<afw::math::KernelList, afw::geom::Box2I const&, pex::policy::Policy>(), "basisList"_a,
60  "regionBBox"_a, "policy"_a);
61 
62  cls.def("getNCandidates", &BuildSpatialKernelVisitor<PixelT>::getNCandidates);
63  cls.def("processCandidate", &BuildSpatialKernelVisitor<PixelT>::processCandidate, "candidate"_a);
64  cls.def("solveLinearEquation", &BuildSpatialKernelVisitor<PixelT>::solveLinearEquation);
65  cls.def("getKernelSolution", &BuildSpatialKernelVisitor<PixelT>::getKernelSolution);
66  cls.def("getSolutionPair", &BuildSpatialKernelVisitor<PixelT>::getSolutionPair);
67 
68  mod.def("makeBuildSpatialKernelVisitor", &makeBuildSpatialKernelVisitor<PixelT>, "basisList"_a,
69  "regionBBox"_a, "policy"_a);
70 }
71 
72 } // namespace lsst::ip::diffim::detail::<anonymous>
73 
74 PYBIND11_PLUGIN(buildSpatialKernelVisitor) {
75  py::module::import("lsst.afw.math");
76  py::module::import("lsst.afw.geom");
77  py::module::import("lsst.pex.policy");
78 
79  py::module mod("buildSpatialKernelVisitor");
80 
81  // Need to import numpy for ndarray and eigen conversions
82  if (_import_array() < 0) {
83  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
84  return nullptr;
85  }
86 
87  declareBuildSpatialKernelVisitor<float>(mod, "F");
88 
89  return mod.ptr();
90 }
91 
92 } // detail
93 } // diffim
94 } // ip
95 } // lsst
Declaration of BuildSpatialKernelVisitor.
PYBIND11_PLUGIN(basisLists)
Definition: basisLists.cc:39