24#include "pybind11/pybind11.h"
27#include "ndarray/pybind11.h"
33using namespace pybind11::literals;
40using PyCModelStageControl = py::class_<CModelStageControl, std::shared_ptr<CModelStageControl>>;
41using PyCModelControl = py::class_<CModelControl, std::shared_ptr<CModelControl>>;
42using PyCModelStageResult = py::class_<CModelStageResult, std::shared_ptr<CModelStageResult>>;
43using PyCModelResult = py::class_<CModelResult, std::shared_ptr<CModelResult>>;
44using PyCModelAlgorithm = py::class_<CModelAlgorithm, std::shared_ptr<CModelAlgorithm>>;
47 return wrappers.
wrapType(PyCModelStageControl(wrappers.module,
"CModelStageControl"), [](
auto &mod,
auto &cls) {
48 cls.def(py::init<>());
49 cls.def(
"getProfile", &CModelStageControl::getProfile);
50 cls.def(
"getModel", &CModelStageControl::getModel);
51 cls.def(
"getPrior", &CModelStageControl::getPrior);
52 LSST_DECLARE_CONTROL_FIELD(cls, CModelStageControl, profileName);
53 LSST_DECLARE_CONTROL_FIELD(cls, CModelStageControl, priorSource);
54 LSST_DECLARE_CONTROL_FIELD(cls, CModelStageControl, priorName);
55 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, CModelStageControl, linearPriorConfig);
56 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, CModelStageControl, empiricalPriorConfig);
57 LSST_DECLARE_CONTROL_FIELD(cls, CModelStageControl, nComponents);
58 LSST_DECLARE_CONTROL_FIELD(cls, CModelStageControl, maxRadius);
59 LSST_DECLARE_CONTROL_FIELD(cls, CModelStageControl, usePixelWeights);
60 LSST_DECLARE_CONTROL_FIELD(cls, CModelStageControl, weightsMultiplier);
61 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, CModelStageControl, optimizer);
62 LSST_DECLARE_CONTROL_FIELD(cls, CModelStageControl, doRecordHistory);
63 LSST_DECLARE_CONTROL_FIELD(cls, CModelStageControl, doRecordTime);
68 return wrappers.
wrapType(PyCModelControl(wrappers.module,
"CModelControl"), [](
auto &mod,
auto &cls) {
69 cls.def(py::init<>());
70 LSST_DECLARE_CONTROL_FIELD(cls, CModelControl, psfName);
71 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, CModelControl, region);
72 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, CModelControl, initial);
73 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, CModelControl, exp);
74 LSST_DECLARE_NESTED_CONTROL_FIELD(cls, CModelControl, dev);
75 LSST_DECLARE_CONTROL_FIELD(cls, CModelControl, minInitialRadius);
76 LSST_DECLARE_CONTROL_FIELD(cls, CModelControl, fallbackInitialMomentsPsfFactor);
86 bool operator[](
int i)
const {
return (*_target)[i]; }
90 template <
typename PyParent>
91 static void declare(PyParent &parent) {
92 py::class_<BitSetView<N>> cls(parent, (
"BitSetView" +
std::to_string(N)).c_str());
93 cls.def(
"__getitem__", &BitSetView<N>::operator[]);
94 cls.def(
"__len__", &BitSetView<N>::size);
102 return wrappers.
wrapType(PyCModelStageResult(wrappers.module,
"CModelStageResult"), [](
auto &mod,
auto &cls) {
103 cls.def(py::init<>());
104 cls.attr(
"FAILED") = py::cast(int(CModelStageResult::FAILED));
105 cls.attr(
"TR_SMALL") = py::cast(int(CModelStageResult::TR_SMALL));
106 cls.attr(
"MAX_ITERATIONS") = py::cast(int(CModelStageResult::MAX_ITERATIONS));
107 cls.attr(
"NUMERIC_ERROR") = py::cast(int(CModelStageResult::NUMERIC_ERROR));
108 cls.attr(
"BAD_REFERENCE") = py::cast(int(CModelStageResult::BAD_REFERENCE));
109 cls.attr(
"NO_FLUX") = py::cast(int(CModelStageResult::NO_FLUX));
110 cls.attr(
"N_FLAGS") = py::cast(int(CModelStageResult::N_FLAGS));
115 cls.def_readonly(
"model", &CModelStageResult::model);
116 cls.def_readonly(
"prior", &CModelStageResult::prior);
117 cls.def_readonly(
"objfunc", &CModelStageResult::objfunc);
118 cls.def_readonly(
"likelihood", &CModelStageResult::likelihood);
119 cls.def_readonly(
"instFlux", &CModelStageResult::instFlux);
120 cls.def_readonly(
"instFluxErr", &CModelStageResult::instFluxErr);
121 cls.def_readonly(
"instFluxInner", &CModelStageResult::instFluxInner);
122 cls.def_readonly(
"objective", &CModelStageResult::objective);
123 cls.def_readonly(
"time", &CModelStageResult::time);
124 cls.def_readonly(
"ellipse", &CModelStageResult::ellipse);
125 cls.def_readonly(
"nonlinear", &CModelStageResult::nonlinear);
126 cls.def_readonly(
"amplitudes", &CModelStageResult::amplitudes);
127 cls.def_readonly(
"fixed", &CModelStageResult::fixed);
130 BitSetView<CModelStageResult::N_FLAGS>::declare(cls);
132 cls.def_property_readonly(
134 [](CModelStageResult const &self) { return BitSetView<CModelStageResult::N_FLAGS>(&self.flags); },
135 py::return_value_policy::reference_internal);
140 return wrappers.
wrapType(PyCModelResult(wrappers.module,
"CModelResult"), [](
auto &mod,
auto &cls) {
141 cls.def(py::init<>());
143 cls.attr(
"FAILED") = py::cast(int(CModelResult::FAILED));
144 cls.attr(
"REGION_MAX_AREA") = py::cast(int(CModelResult::REGION_MAX_AREA));
145 cls.attr(
"REGION_MAX_BAD_PIXEL_FRACTION") = py::cast(int(CModelResult::REGION_MAX_BAD_PIXEL_FRACTION));
146 cls.attr(
"REGION_USED_FOOTPRINT_AREA") = py::cast(int(CModelResult::REGION_USED_FOOTPRINT_AREA));
147 cls.attr(
"REGION_USED_PSF_AREA") = py::cast(int(CModelResult::REGION_USED_PSF_AREA));
148 cls.attr(
"REGION_USED_INITIAL_ELLIPSE_MIN") =
149 py::cast(int(CModelResult::REGION_USED_INITIAL_ELLIPSE_MIN));
150 cls.attr(
"REGION_USED_INITIAL_ELLIPSE_MAX") =
151 py::cast(int(CModelResult::REGION_USED_INITIAL_ELLIPSE_MAX));
152 cls.attr(
"NO_FLUX") = py::cast(int(CModelResult::NO_FLUX));
157 cls.def_readonly(
"instFlux", &CModelResult::instFlux);
158 cls.def_readonly(
"instFluxErr", &CModelResult::instFluxErr);
159 cls.def_readonly(
"instFluxInner", &CModelResult::instFluxInner);
160 cls.def_readonly(
"fracDev", &CModelResult::fracDev);
161 cls.def_readonly(
"objective", &CModelResult::objective);
162 cls.def_readonly(
"initial", &CModelResult::initial);
163 cls.def_readonly(
"exp", &CModelResult::exp);
164 cls.def_readonly(
"dev", &CModelResult::dev);
165 cls.def_readonly(
"initialFitRegion", &CModelResult::initialFitRegion);
166 cls.def_readonly(
"finalFitRegion", &CModelResult::finalFitRegion);
167 cls.def_readonly(
"fitSysToMeasSys", &CModelResult::fitSysToMeasSys);
170 BitSetView<CModelResult::N_FLAGS>::declare(cls);
172 cls.def_property_readonly(
173 "flags", [](CModelResult const &self) { return BitSetView<CModelResult::N_FLAGS>(&self.flags); },
174 py::return_value_policy::reference_internal);
179 return wrappers.
wrapType(PyCModelAlgorithm(wrappers.module,
"CModelAlgorithm"), [](
auto &mod,
auto &cls) {
180 cls.def(py::init<std::string const &, CModelControl const &, afw::table::Schema &>(),
"name"_a,
"ctrl"_a,
182 cls.def(py::init<std::string const &, CModelControl const &, afw::table::SchemaMapper &>(),
"name"_a,
183 "ctrl"_a,
"schemaMapper"_a);
184 cls.def(py::init<CModelControl const &>(),
"ctrl"_a);
185 cls.def(
"getControl", &CModelAlgorithm::getControl);
186 cls.def(
"apply", &CModelAlgorithm::apply,
"exposure"_a,
"psf"_a,
"center"_a,
"moments"_a,
187 "approxFlux"_a = -1,
"kronRadius"_a = -1,
"footprintArea"_a = -1);
188 cls.def(
"applyForced", &CModelAlgorithm::applyForced,
"exposure"_a,
"psf"_a,
"center"_a,
"reference"_a,
189 "approxFlux"_a = -1);
190 cls.def(
"measure", (void (CModelAlgorithm::*)(afw::table::SourceRecord &,
191 afw::image::Exposure<Pixel> const &) const) &
192 CModelAlgorithm::measure,
193 "measRecord"_a,
"exposure"_a);
195 (void (CModelAlgorithm::*)(afw::table::SourceRecord &, afw::image::Exposure<Pixel> const &,
196 afw::table::SourceRecord const &) const) &
197 CModelAlgorithm::measure,
198 "measRecord"_a,
"exposure"_a,
"refRecord"_a);
199 cls.def(
"fail", &CModelAlgorithm::fail,
"measRecord"_a,
"error"_a);
200 cls.def(
"writeResultToRecord", &CModelAlgorithm::writeResultToRecord,
"result"_a,
"record"_a);
206 declareCModelStageControl(wrappers);
207 auto clsControl = declareCModelControl(wrappers);
208 declareCModelStageResult(wrappers);
209 auto clsResult = declareCModelResult(wrappers);
210 auto clsAlgorithm = declareCModelAlgorithm(wrappers);
211 clsAlgorithm.attr(
"Control") = clsControl;
212 clsAlgorithm.attr(
"Result") = clsResult;
Key< Flag > const & target
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...
void wrapCmodel(lsst::cpputils::python::WrapperCollection &wrappers)
declare(module, exception_name, base, wrapped_class)