23#include "pybind11/pybind11.h"
24#include "pybind11/stl.h"
36using namespace pybind11::literals;
43using PyFluxAlgorithm =
44 py::class_<ApertureFluxAlgorithm, std::shared_ptr<ApertureFluxAlgorithm>,
SimpleAlgorithm>;
45using PyFluxControl = py::class_<ApertureFluxControl>;
46using PyFluxResult = py::class_<ApertureFluxResult, std::shared_ptr<ApertureFluxResult>,
FluxResult>;
47using PyFluxTransform =
48 py::class_<ApertureFluxTransform, std::shared_ptr<ApertureFluxTransform>,
BaseTransform>;
50PyFluxControl declareFluxControl(lsst::cpputils::python::WrapperCollection &
wrappers) {
51 return wrappers.wrapType(PyFluxControl(
wrappers.module,
"ApertureFluxControl"), [](
auto &mod,
auto &cls) {
52 LSST_DECLARE_CONTROL_FIELD(cls, ApertureFluxControl, radii);
53 LSST_DECLARE_CONTROL_FIELD(cls, ApertureFluxControl, maxSincRadius);
54 LSST_DECLARE_CONTROL_FIELD(cls, ApertureFluxControl, shiftKernel);
56 cls.def(py::init<>());
60template <
typename Image,
class PyClass>
61void declareComputeFluxes(PyClass &cls) {
64 cls.def_static(
"computeSincFlux",
65 (Result(*)(
Image const &, afw::geom::ellipses::Ellipse
const &,
Control const &)) &
67 "image"_a,
"ellipse"_a,
"ctrl"_a =
Control());
68 cls.def_static(
"computeNaiveFlux",
69 (Result(*)(
Image const &, afw::geom::ellipses::Ellipse
const &,
Control const &)) &
71 "image"_a,
"ellipse"_a,
"ctrl"_a =
Control());
72 cls.def_static(
"computeFlux",
73 (Result(*)(
Image const &, afw::geom::ellipses::Ellipse
const &,
Control const &)) &
75 "image"_a,
"ellipse"_a,
"ctrl"_a =
Control());
78PyFluxAlgorithm declareFluxAlgorithm(lsst::cpputils::python::WrapperCollection &
wrappers) {
79 return wrappers.wrapType(PyFluxAlgorithm(
wrappers.module,
"ApertureFluxAlgorithm"), [](
auto &mod,
auto &cls) {
80 cls.attr(
"FAILURE") = py::cast(ApertureFluxAlgorithm::FAILURE);
81 cls.attr(
"APERTURE_TRUNCATED") = py::cast(ApertureFluxAlgorithm::APERTURE_TRUNCATED);
82 cls.attr(
"SINC_COEFFS_TRUNCATED") = py::cast(ApertureFluxAlgorithm::SINC_COEFFS_TRUNCATED);
86 declareComputeFluxes<afw::image::Image<double>>(cls);
87 declareComputeFluxes<afw::image::MaskedImage<double>>(cls);
88 declareComputeFluxes<afw::image::Image<float>>(cls);
89 declareComputeFluxes<afw::image::MaskedImage<float>>(cls);
91 cls.def(
"measure", &ApertureFluxAlgorithm::measure,
"measRecord"_a,
"exposure"_a);
92 cls.def(
"fail", &ApertureFluxAlgorithm::fail,
"measRecord"_a,
"error"_a = nullptr);
93 cls.def_static(
"makeFieldPrefix", &ApertureFluxAlgorithm::makeFieldPrefix,
"name"_a,
"radius"_a);
97void declareFluxResult(lsst::cpputils::python::WrapperCollection &
wrappers) {
98 wrappers.wrapType(PyFluxResult(
wrappers.module,
"ApertureFluxResult"), [](
auto &mod,
auto &cls) {
99 cls.def(
"getFlag", (bool (ApertureFluxResult::*)(unsigned int) const) &ApertureFluxResult::getFlag,
102 (bool (ApertureFluxResult::*)(std::string const &name) const) &ApertureFluxResult::getFlag,
104 cls.def(
"setFlag", &ApertureFluxResult::setFlag,
"index"_a,
"value"_a);
105 cls.def(
"unsetFlag", &ApertureFluxResult::unsetFlag,
"index"_a);
109PyFluxTransform declareFluxTransform(lsst::cpputils::python::WrapperCollection &
wrappers) {
110 return wrappers.wrapType(PyFluxTransform(
wrappers.module,
"ApertureFluxTransform"), [](
auto &mod,
auto &cls) {
111 cls.def(py::init<ApertureFluxTransform::Control const &, std::string const &,
112 afw::table::SchemaMapper &>(),
113 "ctrl"_a,
"name"_a,
"mapper"_a);
115 cls.def(
"__call__", &ApertureFluxTransform::operator(),
"inputCatalog"_a,
"outputCatalog"_a,
"wcs"_a,
123 auto clsFluxControl = declareFluxControl(
wrappers);
124 auto clsFluxAlgorithm = declareFluxAlgorithm(
wrappers);
126 auto clsFluxTransform = declareFluxTransform(
wrappers);
128 clsFluxAlgorithm.attr(
"Control") = clsFluxControl;
130 clsFluxTransform.attr(
"Control") = clsFluxControl;
133 clsFluxAlgorithm, clsFluxControl, clsFluxTransform);
A helper class for subdividing pybind11 module across multiple translation units (i....
ApertureFluxControl Control
static Result computeSincFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
Compute the instFlux (and optionally, uncertanties) within an aperture using Sinc photometry.
static Result computeFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
Compute the instFlux (and optionally, uncertanties) within an aperture using the algorithm determined...
ApertureFluxResult Result
Result object returned by static methods.
static Result computeNaiveFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
Compute the instFlux (and optionally, uncertanties) within an aperture using naive photometry.
An abstract base classes for which the same implementation can be used for both SingleFrameAlgorithm ...
void declareAlgorithm(PyAlg &clsAlgorithm)
Wrap the implicit API used by meas_base's algorithms.
void wrapApertureFlow(WrapperCollection &)
A reusable result struct for instFlux measurements.
g2d::python::Image< double > Image