23 #include "pybind11/pybind11.h"
24 #include "pybind11/stl.h"
35 using namespace pybind11::literals;
43 using PyFluxAlgorithm =
44 py::class_<ApertureFluxAlgorithm, std::shared_ptr<ApertureFluxAlgorithm>, SimpleAlgorithm>;
45 using PyFluxControl = py::class_<ApertureFluxControl>;
46 using PyFluxResult = py::class_<ApertureFluxResult, std::shared_ptr<ApertureFluxResult>, FluxResult>;
47 using PyFluxTransform =
48 py::class_<ApertureFluxTransform, std::shared_ptr<ApertureFluxTransform>,
BaseTransform>;
50 PyFluxControl declareFluxControl(
py::module &mod) {
51 PyFluxControl
cls(mod,
"ApertureFluxControl");
57 cls.def(py::init<>());
62 template <
typename Image,
class PyClass>
65 using Result = ApertureFluxAlgorithm::Result;
67 cls.def_static(
"computeSincFlux",
68 (Result(*)(Image
const &, afw::geom::ellipses::Ellipse
const &,
Control const &)) &
69 ApertureFluxAlgorithm::computeSincFlux,
70 "image"_a,
"ellipse"_a,
"ctrl"_a =
Control());
71 cls.def_static(
"computeNaiveFlux",
72 (Result(*)(Image
const &, afw::geom::ellipses::Ellipse
const &,
Control const &)) &
73 ApertureFluxAlgorithm::computeNaiveFlux,
74 "image"_a,
"ellipse"_a,
"ctrl"_a =
Control());
75 cls.def_static(
"computeFlux",
76 (Result(*)(Image
const &, afw::geom::ellipses::Ellipse
const &,
Control const &)) &
77 ApertureFluxAlgorithm::computeFlux,
78 "image"_a,
"ellipse"_a,
"ctrl"_a =
Control());
81 PyFluxAlgorithm declareFluxAlgorithm(
py::module &mod) {
82 PyFluxAlgorithm
cls(mod,
"ApertureFluxAlgorithm");
84 cls.attr(
"FAILURE") = py::cast(ApertureFluxAlgorithm::FAILURE);
85 cls.attr(
"APERTURE_TRUNCATED") = py::cast(ApertureFluxAlgorithm::APERTURE_TRUNCATED);
86 cls.attr(
"SINC_COEFFS_TRUNCATED") = py::cast(ApertureFluxAlgorithm::SINC_COEFFS_TRUNCATED);
90 declareComputeFluxes<afw::image::Image<double>>(
cls);
91 declareComputeFluxes<afw::image::MaskedImage<double>>(
cls);
92 declareComputeFluxes<afw::image::Image<float>>(
cls);
93 declareComputeFluxes<afw::image::MaskedImage<float>>(
cls);
96 cls.def(
"fail", &ApertureFluxAlgorithm::fail,
"measRecord"_a,
"error"_a =
nullptr);
97 cls.def_static(
"makeFieldPrefix", &ApertureFluxAlgorithm::makeFieldPrefix,
"name"_a,
"radius"_a);
103 PyFluxResult
cls(mod,
"ApertureFluxResult");
105 cls.def(
"getFlag", (
bool (ApertureFluxResult::*)(
unsigned int)
const) & ApertureFluxResult::getFlag,
108 (
bool (ApertureFluxResult::*)(
std::string const &
name)
const) & ApertureFluxResult::getFlag,
110 cls.def(
"setFlag", &ApertureFluxResult::setFlag,
"index"_a,
"value"_a);
111 cls.def(
"unsetFlag", &ApertureFluxResult::unsetFlag,
"index"_a);
114 PyFluxTransform declareFluxTransform(
py::module &mod) {
115 PyFluxTransform
cls(mod,
"ApertureFluxTransform");
118 afw::table::SchemaMapper &>(),
119 "ctrl"_a,
"name"_a,
"mapper"_a);
121 cls.def(
"__call__", &ApertureFluxTransform::operator(),
"inputCatalog"_a,
"outputCatalog"_a,
"wcs"_a,
130 py::module::import(
"lsst.afw.geom");
131 py::module::import(
"lsst.afw.image");
132 py::module::import(
"lsst.afw.table");
133 py::module::import(
"lsst.meas.base.algorithm");
134 py::module::import(
"lsst.meas.base.flagHandler");
135 py::module::import(
"lsst.meas.base.fluxUtilities");
136 py::module::import(
"lsst.meas.base.transform");
138 auto clsFluxControl = declareFluxControl(mod);
139 auto clsFluxAlgorithm = declareFluxAlgorithm(mod);
140 declareFluxResult(mod);
141 auto clsFluxTransform = declareFluxTransform(mod);
143 clsFluxAlgorithm.attr(
"Control") = clsFluxControl;
145 clsFluxTransform.attr(
"Control") = clsFluxControl;
147 python::declareAlgorithm<ApertureFluxAlgorithm, ApertureFluxControl, ApertureFluxTransform>(
148 clsFluxAlgorithm, clsFluxControl, clsFluxTransform);