23#include "pybind11/pybind11.h"
36using namespace pybind11::literals;
44using PyShapeControl = py::class_<SdssShapeControl>;
47using PyShapeResultKey = py::class_<SdssShapeResultKey, std::shared_ptr<SdssShapeResultKey>>;
48using PyShapeResult = py::class_<SdssShapeResult, std::shared_ptr<SdssShapeResult>, ShapeResult,
49 CentroidResult, FluxResult>;
50using PyShapeAlgorithm = py::class_<SdssShapeAlgorithm, std::shared_ptr<SdssShapeAlgorithm>, SimpleAlgorithm>;
51using PyShapeTransform = py::class_<SdssShapeTransform, std::shared_ptr<SdssShapeTransform>, BaseTransform>;
54 return wrappers.
wrapType(PyShapeControl(wrappers.module,
"SdssShapeControl"), [](
auto &mod,
auto &cls) {
56 LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, background);
57 LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, maxIter);
58 LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, maxShift);
59 LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, tol1);
60 LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, tol2);
61 LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, doMeasurePsf);
68 wrappers.
wrapType(PyShapeResultKey(wrappers.module,
"SdssShapeResultKey"), [](
auto &mod,
auto &cls) {
70 cls.def(py::init<afw::table::SubSchema const &>(),
"subSchema"_a);
72 cls.def_static(
"addFields", &FluxResultKey::addFields,
"schema"_a,
"name"_a,
"doMeasurePsf"_a);
74 cls.def(
"__eq__", &SdssShapeResultKey::operator==, py::is_operator());
75 cls.def(
"__ne__", &SdssShapeResultKey::operator!=, py::is_operator());
77 cls.def(
"get", &SdssShapeResultKey::get,
"record"_a);
78 cls.def(
"set", &SdssShapeResultKey::set,
"record"_a,
"value"_a);
79 cls.def(
"getPsfShape", &SdssShapeResultKey::getPsfShape,
"record"_a);
80 cls.def(
"setPsfShape", &SdssShapeResultKey::setPsfShape,
"record"_a,
"value"_a);
81 cls.def(
"isValid", &SdssShapeResultKey::isValid);
82 cls.def(
"getFlagHandler", &SdssShapeResultKey::getFlagHandler);
86template <
typename ImageT>
87void declareComputeMethods(PyShapeAlgorithm &cls) {
88 cls.def_static(
"computeAdaptiveMoments",(SdssShapeResult(*)(ImageT
const &,
geom::Point2D const &,
bool, SdssShapeControl
const &)) &
90 "image"_a,
"position"_a,
"negative"_a =
false,
"ctrl"_a = SdssShapeControl());
91 cls.def_static(
"computeFixedMomentsFlux",(FluxResult(*)(ImageT
const &, afw::geom::ellipses::Quadrupole
const &,
geom::Point2D const &)) &
93 "image"_a,
"shape"_a,
"position"_a);
97 return wrappers.
wrapType(PyShapeAlgorithm(wrappers.module,
"SdssShapeAlgorithm"), [](
auto &mod,
auto &cls) {
98 cls.attr(
"FAILURE") = py::cast(SdssShapeAlgorithm::FAILURE);
99 cls.attr(
"UNWEIGHTED_BAD") = py::cast(SdssShapeAlgorithm::UNWEIGHTED_BAD);
100 cls.attr(
"UNWEIGHTED") = py::cast(SdssShapeAlgorithm::UNWEIGHTED);
101 cls.attr(
"SHIFT") = py::cast(SdssShapeAlgorithm::SHIFT);
102 cls.attr(
"MAXITER") = py::cast(SdssShapeAlgorithm::MAXITER);
103 cls.attr(
"PSF_SHAPE_BAD") = py::cast(SdssShapeAlgorithm::PSF_SHAPE_BAD);
105 cls.def(py::init<SdssShapeAlgorithm::Control const &, std::string const &, afw::table::Schema &>(),
106 "ctrl"_a,
"name"_a,
"schema"_a);
108 declareComputeMethods<afw::image::Image<int>>(cls);
109 declareComputeMethods<afw::image::Image<float>>(cls);
110 declareComputeMethods<afw::image::Image<double>>(cls);
111 declareComputeMethods<afw::image::MaskedImage<int>>(cls);
112 declareComputeMethods<afw::image::MaskedImage<float>>(cls);
113 declareComputeMethods<afw::image::MaskedImage<double>>(cls);
115 cls.def(
"measure", &SdssShapeAlgorithm::measure,
"measRecord"_a,
"exposure"_a);
116 cls.def(
"fail", &SdssShapeAlgorithm::fail,
"measRecord"_a,
"error"_a = nullptr);
121 wrappers.
wrapType(PyShapeResult(wrappers.module,
"SdssShapeResult"), [](
auto &mod,
auto &cls) {
122 cls.def(py::init<>());
123 cls.def_readwrite(
"instFlux_xx_Cov", &SdssShapeResult::instFlux_xx_Cov);
124 cls.def_readwrite(
"instFlux_yy_Cov", &SdssShapeResult::instFlux_yy_Cov);
125 cls.def_readwrite(
"instFlux_xy_Cov", &SdssShapeResult::instFlux_xy_Cov);
126 cls.def_readwrite(
"flags", &SdssShapeResult::flags);
129 cls.def(
"getFlag", (bool (SdssShapeResult::*)(unsigned int) const) &SdssShapeResult::getFlag,
131 cls.def(
"getFlag", (bool (SdssShapeResult::*)(std::string const &name) const) &SdssShapeResult::getFlag,
137 return wrappers.
wrapType(PyShapeTransform(wrappers.module,
"SdssShapeTransform"), [](
auto &mod,
auto &cls) {
138 cls.def(py::init<SdssShapeTransform::Control const &, std::string const &, afw::table::SchemaMapper &>(),
139 "ctrl"_a,
"name"_a,
"mapper"_a);
141 cls.def(
"__call__", &SdssShapeTransform::operator(),
"inputCatalog"_a,
"outputCatalog"_a,
"wcs"_a,
149 auto clsShapeControl = declareShapeControl(wrappers);
150 declareShapeResultKey(wrappers);
151 auto clsShapeAlgorithm = declareShapeAlgorithm(wrappers);
152 declareShapeResult(wrappers);
153 auto clsShapeTransform = declareShapeTransform(wrappers);
155 clsShapeAlgorithm.attr(
"Control") = clsShapeControl;
156 clsShapeTransform.attr(
"Control") = clsShapeControl;
158 python::declareAlgorithm<SdssShapeAlgorithm, SdssShapeControl, SdssShapeTransform>(
159 clsShapeAlgorithm, clsShapeControl, clsShapeTransform);
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...
static Result computeAdaptiveMoments(ImageT const &image, geom::Point2D const &position, bool negative=false, Control const &ctrl=Control())
Compute the adaptive Gaussian-weighted moments of an image.
static FluxResult computeFixedMomentsFlux(ImageT const &image, afw::geom::ellipses::Quadrupole const &shape, geom::Point2D const &position)
Compute the instFlux within a fixed Gaussian aperture.
void wrapSsdsShape(WrapperCollection &)