24 #include "pybind11/pybind11.h" 26 #include "ndarray/pybind11.h" 39 using PyCModelStageControl = py::class_<CModelStageControl, std::shared_ptr<CModelStageControl>>;
40 using PyCModelControl = py::class_<CModelControl, std::shared_ptr<CModelControl>>;
41 using PyCModelStageResult = py::class_<CModelStageResult, std::shared_ptr<CModelStageResult>>;
42 using PyCModelResult = py::class_<CModelResult, std::shared_ptr<CModelResult>>;
43 using PyCModelAlgorithm = py::class_<CModelAlgorithm, std::shared_ptr<CModelAlgorithm>>;
45 static PyCModelStageControl declareCModelStageControl(
py::module &mod) {
46 PyCModelStageControl
cls(mod,
"CModelStageControl");
47 cls.def(py::init<>());
48 cls.def(
"getProfile", &CModelStageControl::getProfile);
49 cls.def(
"getModel", &CModelStageControl::getModel);
50 cls.def(
"getPrior", &CModelStageControl::getPrior);
66 static PyCModelControl declareCModelControl(
py::module &mod) {
67 PyCModelControl
cls(mod,
"CModelControl");
68 cls.def(py::init<>());
85 bool operator[](
int i)
const {
return (*_target)[i]; }
89 template <
typename PyParent>
90 static void declare(PyParent &parent) {
91 py::class_<BitSetView<N>>
cls(parent, (
"BitSetView" +
std::to_string(N)).c_str());
92 cls.def(
"__getitem__", &BitSetView<N>::operator[]);
93 cls.def(
"__len__", &BitSetView<N>::size);
100 static PyCModelStageResult declareCModelStageResult(
py::module &mod) {
101 PyCModelStageResult
cls(mod,
"CModelStageResult");
103 cls.def(py::init<>());
105 cls.attr(
"FAILED") = py::cast(
int(CModelStageResult::FAILED));
106 cls.attr(
"TR_SMALL") = py::cast(
int(CModelStageResult::TR_SMALL));
107 cls.attr(
"MAX_ITERATIONS") = py::cast(
int(CModelStageResult::MAX_ITERATIONS));
108 cls.attr(
"NUMERIC_ERROR") = py::cast(
int(CModelStageResult::NUMERIC_ERROR));
109 cls.attr(
"BAD_REFERENCE") = py::cast(
int(CModelStageResult::BAD_REFERENCE));
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);
127 cls.def_readonly(
"fixed", &CModelStageResult::fixed);
132 cls.def_property_readonly(
134 [](CModelStageResult
const &
self) {
return BitSetView<CModelStageResult::N_FLAGS>(&
self.flags); },
135 py::return_value_policy::reference_internal);
140 static PyCModelResult declareCModelResult(
py::module &mod) {
141 PyCModelResult
cls(mod,
"CModelResult");
143 cls.def(py::init<>());
145 cls.attr(
"FAILED") = py::cast(
int(CModelResult::FAILED));
146 cls.attr(
"REGION_MAX_AREA") = py::cast(
int(CModelResult::REGION_MAX_AREA));
147 cls.attr(
"REGION_MAX_BAD_PIXEL_FRACTION") = py::cast(
int(CModelResult::REGION_MAX_BAD_PIXEL_FRACTION));
148 cls.attr(
"REGION_USED_FOOTPRINT_AREA") = py::cast(
int(CModelResult::REGION_USED_FOOTPRINT_AREA));
149 cls.attr(
"REGION_USED_PSF_AREA") = py::cast(
int(CModelResult::REGION_USED_PSF_AREA));
150 cls.attr(
"REGION_USED_INITIAL_ELLIPSE_MIN") =
151 py::cast(
int(CModelResult::REGION_USED_INITIAL_ELLIPSE_MIN));
152 cls.attr(
"REGION_USED_INITIAL_ELLIPSE_MAX") =
153 py::cast(
int(CModelResult::REGION_USED_INITIAL_ELLIPSE_MAX));
158 cls.def_readonly(
"instFlux", &CModelResult::instFlux);
159 cls.def_readonly(
"instFluxErr", &CModelResult::instFluxErr);
160 cls.def_readonly(
"instFluxInner", &CModelResult::instFluxInner);
161 cls.def_readonly(
"fracDev", &CModelResult::fracDev);
162 cls.def_readonly(
"objective", &CModelResult::objective);
163 cls.def_readonly(
"initial", &CModelResult::initial);
164 cls.def_readonly(
"exp", &CModelResult::exp);
165 cls.def_readonly(
"dev", &CModelResult::dev);
166 cls.def_readonly(
"initialFitRegion", &CModelResult::initialFitRegion);
167 cls.def_readonly(
"finalFitRegion", &CModelResult::finalFitRegion);
168 cls.def_readonly(
"fitSysToMeasSys", &CModelResult::fitSysToMeasSys);
173 cls.def_property_readonly(
174 "flags", [](CModelResult
const &
self) {
return BitSetView<CModelResult::N_FLAGS>(&
self.flags); },
175 py::return_value_policy::reference_internal);
180 static PyCModelAlgorithm declareCModelAlgorithm(
py::module &mod) {
181 PyCModelAlgorithm
cls(mod,
"CModelAlgorithm");
182 cls.def(py::init<std::string const &, CModelControl const &, afw::table::Schema &>(),
"name"_a,
"ctrl"_a,
184 cls.def(py::init<std::string const &, CModelControl const &, afw::table::SchemaMapper &>(),
"name"_a,
185 "ctrl"_a,
"schemaMapper"_a);
186 cls.def(py::init<CModelControl const &>(),
"ctrl"_a);
187 cls.def(
"getControl", &CModelAlgorithm::getControl);
188 cls.def(
"apply", &CModelAlgorithm::apply,
"exposure"_a,
"psf"_a,
"center"_a,
"moments"_a,
189 "approxFlux"_a = -1,
"kronRadius"_a = -1,
"footprintArea"_a = -1);
190 cls.def(
"applyForced", &CModelAlgorithm::applyForced,
"exposure"_a,
"psf"_a,
"center"_a,
"reference"_a,
191 "approxFlux"_a = -1);
192 cls.def(
"measure", (
void (CModelAlgorithm::*)(afw::table::SourceRecord &,
193 afw::image::Exposure<Pixel>
const &)
const) &
195 "measRecord"_a,
"exposure"_a);
197 (
void (CModelAlgorithm::*)(afw::table::SourceRecord &, afw::image::Exposure<Pixel>
const &,
198 afw::table::SourceRecord
const &)
const) &
199 CModelAlgorithm::measure,
200 "measRecord"_a,
"exposure"_a,
"refRecord"_a);
201 cls.def(
"fail", &CModelAlgorithm::fail,
"measRecord"_a,
"error"_a);
202 cls.def(
"writeResultToRecord", &CModelAlgorithm::writeResultToRecord,
"result"_a,
"record"_a);
207 py::module::import(
"lsst.afw.geom.ellipses");
208 py::module::import(
"lsst.afw.detection");
209 py::module::import(
"lsst.meas.modelfit.model");
210 py::module::import(
"lsst.meas.modelfit.priors");
211 py::module::import(
"lsst.meas.modelfit.optimizer");
212 py::module::import(
"lsst.meas.modelfit.pixelFitRegion");
213 py::module::import(
"lsst.meas.modelfit.unitTransformedLikelihood");
215 declareCModelStageControl(mod);
216 auto clsControl = declareCModelControl(mod);
217 declareCModelStageResult(mod);
218 auto clsResult = declareCModelResult(mod);
219 auto clsAlgorithm = declareCModelAlgorithm(mod);
220 clsAlgorithm.attr(
"Control") = clsControl;
221 clsAlgorithm.attr(
"Result") = clsResult;
PYBIND11_MODULE(camera, mod)
table::Key< table::Array< double > > amplitudes
#define LSST_DECLARE_NESTED_CONTROL_FIELD(WRAPPER, CLASS, NAME)
Macro used to wrap fields declared by LSST_NESTED_CONTROL_FIELD using Pybind11.
A base class for image defects.
#define LSST_DECLARE_CONTROL_FIELD(WRAPPER, CLASS, NAME)
Macro used to wrap fields declared by LSST_CONTROL_FIELD using Pybind11.
Key< Flag > const & target
def declare(module, exception_name, base, wrapped_class)
def measure(mi, x, y, size, statistic, stats)