22 #include "pybind11/pybind11.h"
23 #include "pybind11/eigen.h"
28 #include "ndarray/pybind11.h"
34 using namespace pybind11::literals;
46 py::class_<KernelSolution, std::shared_ptr<KernelSolution>>
cls(mod,
"KernelSolution");
48 cls.def(py::init<Eigen::MatrixXd, Eigen::VectorXd, bool>(),
"mMat"_a,
"bVec"_a,
"fitForBackground"_a);
49 cls.def(py::init<bool>(),
"fitForBackground"_a);
50 cls.def(py::init<>());
52 py::enum_<KernelSolution::KernelSolvedBy>(
cls,
"KernelSolvedBy")
53 .value(
"NONE", KernelSolution::KernelSolvedBy::NONE)
54 .value(
"CHOLESKY_LDLT", KernelSolution::KernelSolvedBy::CHOLESKY_LDLT)
55 .value(
"CHOLESKY_LLT", KernelSolution::KernelSolvedBy::CHOLESKY_LLT)
56 .value(
"LU", KernelSolution::KernelSolvedBy::LU)
57 .value(
"EIGENVECTOR", KernelSolution::KernelSolvedBy::EIGENVECTOR)
60 py::enum_<KernelSolution::ConditionNumberType>(
cls,
"ConditionNumberType")
61 .value(
"EIGENVALUE", KernelSolution::ConditionNumberType::EIGENVALUE)
62 .value(
"SVD", KernelSolution::ConditionNumberType::SVD)
65 cls.def(
"solve", (
void (KernelSolution::*)()) & KernelSolution::solve);
66 cls.def(
"solve", (
void (KernelSolution::*)(Eigen::MatrixXd
const &, Eigen::VectorXd
const &)) &
67 KernelSolution::solve,
69 cls.def(
"getSolvedBy", &KernelSolution::getSolvedBy);
70 cls.def(
"getConditionNumber", (
double (KernelSolution::*)(KernelSolution::ConditionNumberType)) &
71 KernelSolution::getConditionNumber,
73 cls.def(
"getConditionNumber",
74 (
double (KernelSolution::*)(Eigen::MatrixXd
const &, KernelSolution::ConditionNumberType)) &
75 KernelSolution::getConditionNumber,
76 "mMat"_a,
"conditionType"_a);
77 cls.def(
"getM", &KernelSolution::getM, py::return_value_policy::copy);
78 cls.def(
"getB", &KernelSolution::getB, py::return_value_policy::copy);
79 cls.def(
"printM", &KernelSolution::printM);
80 cls.def(
"printB", &KernelSolution::printB);
81 cls.def(
"printA", &KernelSolution::printA);
82 cls.def(
"getId", &KernelSolution::getId);
92 template <
typename InputT>
95 cls(mod, (
"StaticKernelSolution" + suffix).c_str());
97 cls.def(py::init<lsst::afw::math::KernelList const &, bool>(),
"basisList"_a,
"fitForBackground"_a);
99 cls.def(
"solve", (
void (StaticKernelSolution<InputT>::*)()) & StaticKernelSolution<InputT>::solve);
100 cls.def(
"build", &StaticKernelSolution<InputT>::build,
"templateImage"_a,
"scienceImage"_a,
101 "varianceEstimate"_a);
102 cls.def(
"getKernel", &StaticKernelSolution<InputT>::getKernel);
103 cls.def(
"makeKernelImage", &StaticKernelSolution<InputT>::makeKernelImage);
104 cls.def(
"getBackground", &StaticKernelSolution<InputT>::getBackground);
105 cls.def(
"getKsum", &StaticKernelSolution<InputT>::getKsum);
106 cls.def(
"getSolutionPair", &StaticKernelSolution<InputT>::getSolutionPair);
116 template <
typename InputT>
119 StaticKernelSolution<InputT>>
120 cls(mod, (
"MaskedKernelSolution" + suffix).c_str());
122 cls.def(py::init<lsst::afw::math::KernelList const &, bool>(),
"basisList"_a,
"fitForBackground"_a);
124 cls.def(
"buildOrig", &MaskedKernelSolution<InputT>::buildOrig,
"templateImage"_a,
"scienceImage"_a,
125 "varianceEstimate"_a,
"pixelMask"_a);
126 cls.def(
"buildWithMask", &MaskedKernelSolution<InputT>::buildWithMask,
"templateImage"_a,
127 "scienceImage"_a,
"varianceEstimate"_a,
"pixelMask"_a);
128 cls.def(
"buildSingleMaskOrig", &MaskedKernelSolution<InputT>::buildSingleMaskOrig,
"templateImage"_a,
129 "scienceImage"_a,
"varianceEstimate"_a,
"maskBox"_a);
139 template <
typename InputT>
142 StaticKernelSolution<InputT>>
143 cls(mod, (
"RegularizedKernelSolution" + suffix).c_str());
146 daf::base::PropertySet
const&>(),
147 "basisList"_a,
"fitForBackground"_a,
"hMat"_a,
"ps"_a);
150 (
void (RegularizedKernelSolution<InputT>::*)()) & RegularizedKernelSolution<InputT>::solve);
151 cls.def(
"getLambda", &RegularizedKernelSolution<InputT>::getLambda);
152 cls.def(
"estimateRisk", &RegularizedKernelSolution<InputT>::estimateRisk,
"maxCond"_a);
153 cls.def(
"getM", &RegularizedKernelSolution<InputT>::getM);
159 void declareSpatialKernelSolution(
py::module &mod) {
160 py::class_<SpatialKernelSolution, std::shared_ptr<SpatialKernelSolution>, KernelSolution>
cls(
161 mod,
"SpatialKernelSolution");
165 "basisList"_a,
"spatialKernelFunction"_a,
"background"_a,
"ps"_a);
167 cls.def(
"solve", (
void (SpatialKernelSolution::*)()) & SpatialKernelSolution::solve);
168 cls.def(
"addConstraint", &SpatialKernelSolution::addConstraint,
"xCenter"_a,
"yCenter"_a,
"qMat"_a,
170 cls.def(
"makeKernelImage", &SpatialKernelSolution::makeKernelImage,
"pos"_a);
171 cls.def(
"getSolutionPair", &SpatialKernelSolution::getSolutionPair);
177 py::module::import(
"lsst.afw.geom");
178 py::module::import(
"lsst.afw.image");
179 py::module::import(
"lsst.afw.math");
180 py::module::import(
"lsst.daf.base");
182 declareKernelSolution(mod);
183 declareStaticKernelSolution<float>(mod,
"F");
184 declareMaskedKernelSolution<float>(mod,
"F");
185 declareRegularizedKernelSolution<float>(mod,
"F");
186 declareSpatialKernelSolution(mod);