lsst.ip.diffim  13.0-22-g3839dbb+16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
buildSingleKernelVisitor.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/Kernel.h"
33 #include "lsst/afw/math/SpatialCell.h"
35 #include "lsst/pex/policy/Policy.h"
36 
37 namespace py = pybind11;
38 using namespace pybind11::literals;
39 
40 namespace lsst {
41 namespace ip {
42 namespace diffim {
43 namespace detail {
44 
45 namespace {
46 
54 template <typename PixelT>
55 void declareBuildSingleKernelVisitor(py::module& mod, std::string const& suffix) {
56  py::class_<BuildSingleKernelVisitor<PixelT>, std::shared_ptr<BuildSingleKernelVisitor<PixelT>>,
57  afw::math::CandidateVisitor>
58  cls(mod, ("BuildSingleKernelVisitor" + suffix).c_str());
59 
60  cls.def(py::init<afw::math::KernelList, pex::policy::Policy>(), "basisList"_a, "policy"_a);
61  cls.def(py::init<afw::math::KernelList, pex::policy::Policy, Eigen::MatrixXd const&>(), "basisList"_a,
62  "policy"_a, "hMat"_a);
63 
64  cls.def("setSkipBuilt", &BuildSingleKernelVisitor<PixelT>::setSkipBuilt, "skip"_a);
65  cls.def("getNRejected", &BuildSingleKernelVisitor<PixelT>::getNRejected);
66  cls.def("getNProcessed", &BuildSingleKernelVisitor<PixelT>::getNProcessed);
67  cls.def("reset", &BuildSingleKernelVisitor<PixelT>::reset);
68  cls.def("processCandidate", &BuildSingleKernelVisitor<PixelT>::processCandidate, "candidate"_a);
69 
70  mod.def("makeBuildSingleKernelVisitor",
71  (std::shared_ptr<BuildSingleKernelVisitor<PixelT>>(*)(afw::math::KernelList const&,
72  pex::policy::Policy const&)) &
74  "basisList"_a, "policy"_a);
75  mod.def("makeBuildSingleKernelVisitor",
76  (std::shared_ptr<BuildSingleKernelVisitor<PixelT>>(*)(
77  afw::math::KernelList const&, pex::policy::Policy const&, Eigen::MatrixXd const&)) &
78  makeBuildSingleKernelVisitor<PixelT>,
79  "basisList"_a, "policy"_a, "hMat"_a);
80 }
81 
82 } // namespace lsst::ip::diffim::detail::<anonymous>
83 
84 PYBIND11_PLUGIN(buildSingleKernelVisitor) {
85  py::module::import("lsst.afw.math");
86  py::module::import("lsst.pex.policy");
87 
88  py::module mod("buildSingleKernelVisitor");
89 
90  // Need to import numpy for ndarray and eigen conversions
91  if (_import_array() < 0) {
92  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
93  return nullptr;
94  }
95 
96  declareBuildSingleKernelVisitor<float>(mod, "F");
97 
98  return mod.ptr();
99 }
100 
101 } // detail
102 } // diffim
103 } // ip
104 } // lsst
template std::shared_ptr< BuildSingleKernelVisitor< PixelT > > makeBuildSingleKernelVisitor< PixelT >(lsst::afw::math::KernelList const &, lsst::pex::policy::Policy const &)
Declaration of BuildSingleKernelVisitor.
PYBIND11_PLUGIN(basisLists)
Definition: basisLists.cc:39