24#include "pybind11/pybind11.h"
33using namespace pybind11::literals;
41 using Control = DoubleShapeletPsfApproxControl;
42 using Algorithm = DoubleShapeletPsfApproxAlgorithm;
44 using PyControl = py::class_<Control, std::shared_ptr<Control>>;
45 using PyAlgorithm = py::class_<Algorithm, std::shared_ptr<Algorithm>, meas::base::SimpleAlgorithm>;
47 static auto clsControl =
48 wrappers.
wrapType(PyControl(wrappers.module,
"DoubleShapeletPsfApproxControl"), [](
auto &mod,
auto &cls) {
49 cls.def(py::init<>());
50 LSST_DECLARE_CONTROL_FIELD(cls, Control, innerOrder);
51 LSST_DECLARE_CONTROL_FIELD(cls, Control, outerOrder);
52 LSST_DECLARE_CONTROL_FIELD(cls, Control, radiusRatio);
53 LSST_DECLARE_CONTROL_FIELD(cls, Control, peakRatio);
54 LSST_DECLARE_CONTROL_FIELD(cls, Control, minRadius);
55 LSST_DECLARE_CONTROL_FIELD(cls, Control, minRadiusDiff);
56 LSST_DECLARE_CONTROL_FIELD(cls, Control, maxRadiusBoxFraction);
57 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, Control, optimizer);
60 wrappers.
wrapType(PyAlgorithm(wrappers.module,
"DoubleShapeletPsfApproxAlgorithm"), [](
auto &mod,
auto &cls) {
62 cls.attr(
"Control") = clsControl;
63 cls.attr(
"FAILURE") = py::cast(Algorithm::FAILURE);
64 cls.attr(
"INVALID_POINT_FOR_PSF") = py::cast(Algorithm::INVALID_POINT_FOR_PSF);
65 cls.attr(
"INVALID_MOMENTS") = py::cast(Algorithm::INVALID_MOMENTS);
66 cls.attr(
"MAX_ITERATIONS") = py::cast(Algorithm::MAX_ITERATIONS);
68 cls.def(py::init<Control const &, std::string const &, afw::table::Schema &>(),
"ctrl"_a,
69 "name"_a,
"schema"_a);
70 cls.def_static(
"initializeResult", &Algorithm::initializeResult,
"ctrl"_a);
71 cls.def_static(
"fitMoments", &Algorithm::fitMoments,
"result"_a,
"ctrl"_a,
"psfImage"_a);
72 cls.def_static(
"makeObjective", &Algorithm::makeObjective,
"moments"_a,
"ctrl"_a,
"psfImage"_a);
73 cls.def_static(
"fitProfile", &Algorithm::fitProfile,
"result"_a,
"ctrl"_a,
"psfImage"_a);
74 cls.def_static(
"fitShapelets", &Algorithm::fitShapelets,
"result"_a,
"ctrl"_a,
"psfImage"_a);
75 cls.def(
"measure", &Algorithm::measure,
"measRecord"_a,
"exposure"_a);
76 cls.def(
"fail", &Algorithm::fail,
"measRecord"_a,
"error"_a = nullptr);
81 using ComponentControl = GeneralPsfFitterComponentControl;
82 using Control = GeneralPsfFitterControl;
83 using Fitter = GeneralPsfFitter;
84 using Algorithm = GeneralPsfFitterAlgorithm;
86 using PyComponentControl = py::class_<ComponentControl, std::shared_ptr<ComponentControl>>;
87 using PyControl = py::class_<Control, std::shared_ptr<Control>>;
88 using PyFitter = py::class_<Fitter, std::shared_ptr<Fitter>>;
89 using PyAlgorithm = py::class_<Algorithm, std::shared_ptr<Algorithm>, Fitter>;
91 wrappers.
wrapType(PyComponentControl(wrappers.module,
"GeneralPsfFitterComponentControl"), [](
auto &mod,
auto &cls) {
92 cls.def(py::init<int, double>(),
"order"_a = 0,
"radius"_a = 1.0);
93 LSST_DECLARE_CONTROL_FIELD(cls, ComponentControl, order);
94 LSST_DECLARE_CONTROL_FIELD(cls, ComponentControl, positionPriorSigma);
95 LSST_DECLARE_CONTROL_FIELD(cls ,ComponentControl, ellipticityPriorSigma);
96 LSST_DECLARE_CONTROL_FIELD(cls, ComponentControl, radiusFactor);
97 LSST_DECLARE_CONTROL_FIELD(cls, ComponentControl, radiusPriorSigma);
100 static auto clsControl =
101 wrappers.
wrapType(PyControl(wrappers.module,
"GeneralPsfFitterControl"), [](
auto &mod,
auto &cls) {
102 cls.def(py::init<>());
103 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, Control, inner);
104 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, Control, primary);
105 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, Control, wings);
106 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, Control, outer);
107 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, Control, optimizer);
108 LSST_DECLARE_CONTROL_FIELD(cls, Control, defaultNoiseSigma);
111 wrappers.
wrapType(PyFitter(wrappers.module,
"GeneralPsfFitter"), [](
auto &mod,
auto &cls) {
112 cls.def(py::init<Control const &>(),
"ctrl"_a);
113 cls.def(
"addFields", &Fitter::addFields,
"schema"_a,
"prefix"_a);
114 cls.def(
"getModel", &Fitter::getModel);
115 cls.def(
"getPrior", &Fitter::getPrior);
116 cls.def(
"adapt", &Fitter::adapt,
"previousFit"_a,
"previousModel"_a);
119 cls.def(
"apply", [](Fitter const &self, afw::image::Image<Pixel> const &image,
120 afw::geom::ellipses::Quadrupole const &moments,
121 Scalar noiseSigma) { return self.apply(image, moments, noiseSigma); },
122 "image"_a,
"moments"_a,
"noiseSigma"_a = -1);
123 cls.def(
"apply", [](Fitter
const &self, afw::image::Image<double>
const &
image,
124 afw::geom::ellipses::Quadrupole
const &
moments,
126 "image"_a,
"moments"_a,
"noiseSigma"_a = -1);
127 cls.def(
"apply", [](Fitter
const &self, afw::image::Image<Pixel>
const &
image,
128 shapelet::MultiShapeletFunction
const &initial,
129 Scalar noiseSigma) {
return self.apply(
image, initial, noiseSigma); },
130 "image"_a,
"initial"_a,
"noiseSigma"_a = -1);
131 cls.def(
"apply", [](Fitter
const &self, afw::image::Image<double>
const &
image,
132 shapelet::MultiShapeletFunction
const &initial,
133 Scalar noiseSigma) {
return self.apply(
image, initial, noiseSigma); },
134 "image"_a,
"initial"_a,
"noiseSigma"_a = -1);
137 wrappers.
wrapType(PyAlgorithm(wrappers.module,
"GeneralPsfFitterAlgorithm"), [](
auto &mod,
auto &cls) {
138 cls.attr(
"Control") = clsControl;
139 cls.attr(
"FAILURE") = py::cast(Algorithm::FAILURE);
140 cls.attr(
"MAX_INNER_ITERATIONS") = py::cast(Algorithm::MAX_INNER_ITERATIONS);
141 cls.attr(
"MAX_OUTER_ITERATIONS") = py::cast(Algorithm::MAX_OUTER_ITERATIONS);
142 cls.attr(
"EXCEPTION") = py::cast(Algorithm::EXCEPTION);
143 cls.attr(
"CONTAINS_NAN") = py::cast(Algorithm::CONTAINS_NAN);
144 cls.def(py::init<Control const &, afw::table::Schema &, std::string const &>(),
"ctrl"_a,
145 "schema"_a,
"prefix"_a);
146 cls.def(
"getKey", &Algorithm::getKey);
148 (
void (Algorithm::*)(
afw::table::SourceRecord &,
afw::
image::Image<double> const &,
149 shapelet::MultiShapeletFunction const &) const) &
151 "measRecord"_a,
"image"_a,
"initial"_a);
153 (
void (Algorithm::*)(
afw::table::SourceRecord &,
afw::
image::Image<double> const &,
154 afw::
geom::ellipses::Quadrupole const &) const) &
156 "measRecord"_a,
"image"_a,
"moments"_a);
157 cls.def(
"fail", &Algorithm::fail,
"measRecord"_a,
"error"_a =
nullptr);
165 declareDoubleShapelet(wrappers);
166 declareGeneral(wrappers);
A helper class for subdividing pybind11 module across multiple translation units (i....
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
double Scalar
Typedefs to be used for probability and parameter values.