23 #include "pybind11/pybind11.h"
24 #include "pybind11/stl.h"
28 #include "lsst/pex/config/python.h"
29 #include "lsst/afw/geom/Point.h"
30 #include "lsst/afw/geom/ellipses.h"
31 #include "lsst/afw/geom/AffineTransform.h"
32 #include "lsst/afw/image/MaskedImage.h"
33 #include "lsst/afw/table/Source.h"
34 #include "lsst/meas/base/Algorithm.h"
37 namespace py = pybind11;
38 using namespace pybind11::literals;
42 namespace extensions {
43 namespace photometryKron {
47 void declareKronFluxControl(py::module &mod) {
48 py::class_<KronFluxControl> cls(mod,
"KronFluxControl");
50 cls.def(py::init<>());
52 LSST_DECLARE_CONTROL_FIELD(cls, KronFluxControl, fixed);
53 LSST_DECLARE_CONTROL_FIELD(cls, KronFluxControl, nSigmaForRadius);
54 LSST_DECLARE_CONTROL_FIELD(cls, KronFluxControl, nIterForRadius);
55 LSST_DECLARE_CONTROL_FIELD(cls, KronFluxControl, nRadiusForFlux);
56 LSST_DECLARE_CONTROL_FIELD(cls, KronFluxControl, maxSincRadius);
57 LSST_DECLARE_CONTROL_FIELD(cls, KronFluxControl, minimumRadius);
58 LSST_DECLARE_CONTROL_FIELD(cls, KronFluxControl, enforceMinimumRadius);
59 LSST_DECLARE_CONTROL_FIELD(cls, KronFluxControl, useFootprintRadius);
60 LSST_DECLARE_CONTROL_FIELD(cls, KronFluxControl, smoothingSigma);
61 LSST_DECLARE_CONTROL_FIELD(cls, KronFluxControl, refRadiusName);
64 void declareKronFluxAlgorithm(py::module &mod) {
65 py::class_<KronFluxAlgorithm, std::shared_ptr<KronFluxAlgorithm>, base::SimpleAlgorithm> cls(
66 mod,
"KronFluxAlgorithm");
68 cls.def_static(
"getFlagDefinitions", &KronFluxAlgorithm::getFlagDefinitions,
69 py::return_value_policy::copy);
70 cls.attr(
"FAILURE") = py::cast(KronFluxAlgorithm::FAILURE);
71 cls.attr(
"EDGE") = py::cast(KronFluxAlgorithm::EDGE);
72 cls.attr(
"BAD_SHAPE_NO_PSF") = py::cast(KronFluxAlgorithm::BAD_SHAPE_NO_PSF);
73 cls.attr(
"NO_MINIMUM_RADIUS") = py::cast(KronFluxAlgorithm::NO_MINIMUM_RADIUS);
74 cls.attr(
"NO_FALLBACK_RADIUS") = py::cast(KronFluxAlgorithm::NO_FALLBACK_RADIUS);
75 cls.attr(
"BAD_RADIUS") = py::cast(KronFluxAlgorithm::BAD_RADIUS);
76 cls.attr(
"USED_MINIMUM_RADIUS") = py::cast(KronFluxAlgorithm::USED_MINIMUM_RADIUS);
77 cls.attr(
"USED_PSF_RADIUS") = py::cast(KronFluxAlgorithm::USED_PSF_RADIUS);
78 cls.attr(
"SMALL_RADIUS") = py::cast(KronFluxAlgorithm::SMALL_RADIUS);
79 cls.attr(
"BAD_SHAPE") = py::cast(KronFluxAlgorithm::BAD_SHAPE);
82 daf::base::PropertySet &>(),
83 "ctrl"_a,
"name"_a,
"schema"_a,
"metadata"_a);
85 cls.def(
"measure", &KronFluxAlgorithm::measure,
"measRecord"_a,
"exposure"_a);
86 cls.def(
"measureForced", &KronFluxAlgorithm::measureForced,
"measRecord"_a,
"exposure"_a,
"refRecord"_a,
88 cls.def(
"fail", &KronFluxAlgorithm::fail,
"measRecord"_a,
"error"_a = NULL);
91 using PyKronAperture = py::class_<KronAperture>;
99 template <
typename ImageT>
100 void declareKronApertureTemplatedMethods(PyKronAperture &cls) {
101 cls.def_static(
"determineRadius", &KronAperture::determineRadius<ImageT>,
"image"_a,
"axes"_a,
"center"_a,
103 cls.def(
"measureFlux", &KronAperture::measureFlux<ImageT>,
"image"_a,
"nRadiusForFlux"_a,
107 void declareKronAperture(py::module &mod) {
108 PyKronAperture cls(mod,
"KronAperture");
110 cls.def(py::init<afw::geom::Point2D const &, afw::geom::ellipses::BaseCore const &, float>(),
"center"_a,
111 "core"_a,
"radiusForRadius"_a = std::nanf(
""));
112 cls.def(py::init<afw::table::SourceRecord const &, float>(),
"source"_a,
113 "radiusForRadius"_a = std::nanf(
""));
114 cls.def(py::init<afw::table::SourceRecord const &, afw::geom::AffineTransform const &, double, float>(),
115 "reference"_a,
"refToMeas"_a,
"radius"_a,
"radiusForRadius"_a = std::nanf(
""));
117 cls.def_static(
"getKronAxes", &KronAperture::getKronAxes,
"shape"_a,
"transformation"_a,
"radius"_a);
119 cls.def(
"getX", &KronAperture::getX);
120 cls.def(
"getY", &KronAperture::getY);
121 cls.def(
"getRadiusForRadius", &KronAperture::getRadiusForRadius);
122 cls.def(
"getCenter", &KronAperture::getCenter);
123 cls.def(
"getAxes", (afw::geom::ellipses::Axes & (KronAperture::*)()) & KronAperture::getAxes,
124 py::return_value_policy::reference_internal);
125 cls.def(
"transform", &KronAperture::transform,
"trans"_a);
127 declareKronApertureTemplatedMethods<afw::image::MaskedImage<float>>(cls);
133 py::module::import(
"lsst.afw.geom");
134 py::module::import(
"lsst.afw.image");
135 py::module::import(
"lsst.afw.table");
136 py::module::import(
"lsst.daf.base");
138 py::module mod(
"photometryKron");
140 declareKronFluxControl(mod);
141 declareKronFluxAlgorithm(mod);
142 declareKronAperture(mod);
PYBIND11_PLUGIN(photometryKron)