22#include "pybind11/pybind11.h"
23#include "pybind11/eigen.h"
28#include "ndarray/pybind11.h"
34using 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)
66 cls.def(
"solve", (
void (KernelSolution::*)(Eigen::MatrixXd
const &, Eigen::VectorXd
const &)) &
73 cls.def(
"getConditionNumber",
76 "mMat"_a,
"conditionType"_a);
92template <
typename InputT>
95 cls(mod, (
"StaticKernelSolution" + suffix).c_str());
97 cls.def(py::init<lsst::afw::math::KernelList const &, bool>(),
"basisList"_a,
"fitForBackground"_a);
101 "varianceEstimate"_a);
116template <
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);
125 "varianceEstimate"_a,
"pixelMask"_a);
127 "scienceImage"_a,
"varianceEstimate"_a,
"pixelMask"_a);
129 "scienceImage"_a,
"varianceEstimate"_a,
"maskBox"_a);
139template <
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);
159void 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);
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);
Declaration of classes to store the solution for convolution kernels.
virtual double getConditionNumber(ConditionNumberType conditionType)
Eigen::MatrixXd const & getM()
Eigen::VectorXd const & getB()
KernelSolvedBy getSolvedBy()
virtual void buildWithMask(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate, lsst::afw::image::Mask< lsst::afw::image::MaskPixel > const &pixelMask)
virtual void buildSingleMaskOrig(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate, lsst::geom::Box2I maskBox)
virtual void buildOrig(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate, lsst::afw::image::Mask< lsst::afw::image::MaskPixel > pixelMask)
double estimateRisk(double maxCond)
std::pair< std::shared_ptr< lsst::afw::math::LinearCombinationKernel >, lsst::afw::math::Kernel::SpatialFunctionPtr > getSolutionPair()
std::shared_ptr< lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > > makeKernelImage(lsst::geom::Point2D const &pos)
void addConstraint(float xCenter, float yCenter, Eigen::MatrixXd const &qMat, Eigen::VectorXd const &wVec)
virtual std::pair< std::shared_ptr< lsst::afw::math::Kernel >, double > getSolutionPair()
virtual double getBackground()
virtual std::shared_ptr< lsst::afw::math::Kernel > getKernel()
virtual std::shared_ptr< lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > > makeKernelImage()
virtual void build(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate)
PYBIND11_MODULE(basisLists, mod)
A base class for image defects.