22 #include "pybind11/pybind11.h"
23 #include "pybind11/stl.h"
26 #include "numpy/arrayobject.h"
27 #include "ndarray/pybind11.h"
32 #include "lsst/afw/math/SpatialCell.h"
35 namespace py = pybind11;
36 using namespace pybind11::literals;
51 template <
typename PixelT>
52 void declareKernelCandidate(py::module &mod, std::string
const &suffix) {
53 py::class_<KernelCandidate<PixelT>, std::shared_ptr<KernelCandidate<PixelT>>,
54 afw::math::SpatialCellImageCandidate>
55 cls(mod, (
"KernelCandidate" + suffix).c_str());
57 using CandidateSwitch =
typename KernelCandidate<PixelT>::CandidateSwitch;
59 py::enum_<CandidateSwitch>(cls,
"CandidateSwitch")
60 .value(
"ORIG", CandidateSwitch::ORIG)
61 .value(
"PCA", CandidateSwitch::PCA)
62 .value(
"RECENT", CandidateSwitch::RECENT)
65 cls.def(py::init<
float const,
float const, std::shared_ptr<afw::image::MaskedImage<PixelT>>
const &,
66 std::shared_ptr<afw::image::MaskedImage<PixelT>>
const &, pex::policy::Policy
const &>(),
67 "xCenter"_a,
"yCenter"_a,
"templateMaskedImage"_a,
"scienceMaskedImage"_a,
"policy"_a);
68 cls.def(py::init<std::shared_ptr<afw::table::SourceRecord>
const &,
69 std::shared_ptr<afw::image::MaskedImage<PixelT>>
const &,
70 std::shared_ptr<afw::image::MaskedImage<PixelT>>
const &, pex::policy::Policy
const &>(),
71 "source"_a,
"templateMaskedImage"_a,
"scienceMaskedImage"_a,
"policy"_a);
73 cls.def(
"getCandidateRating", &KernelCandidate<PixelT>::getCandidateRating);
74 cls.def(
"getSource", &KernelCandidate<PixelT>::getSource);
75 cls.def(
"getTemplateMaskedImage", &KernelCandidate<PixelT>::getTemplateMaskedImage);
76 cls.def(
"getScienceMaskedImage", &KernelCandidate<PixelT>::getScienceMaskedImage);
77 cls.def(
"getKernel", &KernelCandidate<PixelT>::getKernel,
"cand"_a);
78 cls.def(
"getBackground", &KernelCandidate<PixelT>::getBackground,
"cand"_a);
79 cls.def(
"getKsum", &KernelCandidate<PixelT>::getKsum,
"cand"_a);
80 cls.def(
"getKernelImage", &KernelCandidate<PixelT>::getKernelImage,
"cand"_a);
81 cls.def(
"getImage", &KernelCandidate<PixelT>::getImage);
82 cls.def(
"getKernelSolution", &KernelCandidate<PixelT>::getKernelSolution,
"cand"_a);
83 cls.def(
"getDifferenceImage",
84 (afw::image::MaskedImage<PixelT> (KernelCandidate<PixelT>::*)(CandidateSwitch)) &
85 KernelCandidate<PixelT>::getDifferenceImage,
87 cls.def(
"getDifferenceImage", (afw::image::MaskedImage<PixelT> (KernelCandidate<PixelT>::*)(
88 std::shared_ptr<afw::math::Kernel>,
double)) &
89 KernelCandidate<PixelT>::getDifferenceImage,
90 "kernel"_a,
"background"_a);
91 cls.def(
"isInitialized", &KernelCandidate<PixelT>::isInitialized);
92 cls.def(
"build", (
void (KernelCandidate<PixelT>::*)(afw::math::KernelList
const &)) &
93 KernelCandidate<PixelT>::build,
96 (
void (KernelCandidate<PixelT>::*)(afw::math::KernelList
const &, Eigen::MatrixXd
const &)) &
97 KernelCandidate<PixelT>::build,
98 "basisList"_a,
"hMat"_a);
99 mod.def(
"makeKernelCandidate",
100 (std::shared_ptr<KernelCandidate<PixelT>>(*)(
101 float const,
float const, std::shared_ptr<afw::image::MaskedImage<PixelT>>
const &,
102 std::shared_ptr<afw::image::MaskedImage<PixelT>>
const &, pex::policy::Policy
const &)) &
104 "xCenter"_a,
"yCenter"_a,
"templateMaskedImage"_a,
"scienceMaskedImage"_a,
"policy"_a);
105 mod.def(
"makeKernelCandidate",
106 (std::shared_ptr<KernelCandidate<PixelT>>(*)(
107 std::shared_ptr<afw::table::SourceRecord>
const &,
108 std::shared_ptr<afw::image::MaskedImage<PixelT>>
const &,
109 std::shared_ptr<afw::image::MaskedImage<PixelT>>
const &, pex::policy::Policy
const &)) &
111 "source"_a,
"templateMaskedImage"_a,
"scienceMaskedImage"_a,
"policy"_a);
117 py::module::import(
"lsst.afw.image");
118 py::module::import(
"lsst.afw.math");
119 py::module::import(
"lsst.afw.table");
120 py::module::import(
"lsst.pex.policy");
122 py::module mod(
"kernelCandidate");
125 if (_import_array() < 0) {
126 PyErr_SetString(PyExc_ImportError,
"numpy.core.multiarray failed to import");
130 declareKernelCandidate<float>(mod,
"F");
Class used by SpatialModelCell for spatial Kernel fitting.
PYBIND11_PLUGIN(basisLists)
std::shared_ptr< KernelCandidate< PixelT > > makeKernelCandidate(float const xCenter, float const yCenter, std::shared_ptr< afw::image::MaskedImage< PixelT > > const &templateMaskedImage, std::shared_ptr< afw::image::MaskedImage< PixelT > > const &scienceMaskedImage, pex::policy::Policy const &policy)
Return a KernelCandidate pointer of the right sort.