23 #include "pybind11/pybind11.h"
35 using namespace pybind11::literals;
43 using PyShapeControl = py::class_<SdssShapeControl>;
46 using PyShapeResultKey = py::class_<SdssShapeResultKey, std::shared_ptr<SdssShapeResultKey>>;
47 using PyShapeResult = py::class_<SdssShapeResult, std::shared_ptr<SdssShapeResult>, ShapeResult,
48 CentroidResult, FluxResult>;
49 using PyShapeAlgorithm = py::class_<SdssShapeAlgorithm, std::shared_ptr<SdssShapeAlgorithm>, SimpleAlgorithm>;
50 using PyShapeTransform = py::class_<SdssShapeTransform, std::shared_ptr<SdssShapeTransform>,
BaseTransform>;
52 PyShapeControl declareShapeControl(
py::module &mod) {
53 PyShapeControl
cls(mod,
"SdssShapeControl");
62 cls.def(py::init<>());
68 PyShapeResultKey
cls(mod,
"SdssShapeResultKey");
71 cls.def(py::init<afw::table::SubSchema const &>(),
"subSchema"_a);
73 cls.def_static(
"addFields", &FluxResultKey::addFields,
"schema"_a,
"name"_a,
"doMeasurePsf"_a);
75 cls.def(
"__eq__", &SdssShapeResultKey::operator==, py::is_operator());
76 cls.def(
"__ne__", &SdssShapeResultKey::operator!=, py::is_operator());
78 cls.def(
"get", &SdssShapeResultKey::get,
"record"_a);
80 cls.def(
"getPsfShape", &SdssShapeResultKey::getPsfShape,
"record"_a);
81 cls.def(
"setPsfShape", &SdssShapeResultKey::setPsfShape,
"record"_a,
"value"_a);
83 cls.def(
"getFlagHandler", &SdssShapeResultKey::getFlagHandler);
86 template <
typename ImageT>
87 static void declareComputeMethods(PyShapeAlgorithm &
cls) {
89 "computeAdaptiveMoments",
90 (SdssShapeResult(*)(ImageT
const &,
geom::Point2D const &,
bool, SdssShapeControl
const &)) &
91 SdssShapeAlgorithm::computeAdaptiveMoments,
92 "image"_a,
"position"_a,
"negative"_a =
false,
"ctrl"_a = SdssShapeControl());
94 "computeFixedMomentsFlux",
95 (FluxResult(*)(ImageT
const &, afw::geom::ellipses::Quadrupole
const &,
geom::Point2D const &)) &
96 SdssShapeAlgorithm::computeFixedMomentsFlux,
97 "image"_a,
"shape"_a,
"position"_a);
100 PyShapeAlgorithm declareShapeAlgorithm(
py::module &mod) {
101 PyShapeAlgorithm
cls(mod,
"SdssShapeAlgorithm");
103 cls.attr(
"FAILURE") = py::cast(SdssShapeAlgorithm::FAILURE);
104 cls.attr(
"UNWEIGHTED_BAD") = py::cast(SdssShapeAlgorithm::UNWEIGHTED_BAD);
105 cls.attr(
"UNWEIGHTED") = py::cast(SdssShapeAlgorithm::UNWEIGHTED);
106 cls.attr(
"SHIFT") = py::cast(SdssShapeAlgorithm::SHIFT);
107 cls.attr(
"MAXITER") = py::cast(SdssShapeAlgorithm::MAXITER);
108 cls.attr(
"PSF_SHAPE_BAD") = py::cast(SdssShapeAlgorithm::PSF_SHAPE_BAD);
110 cls.def(py::init<SdssShapeAlgorithm::Control const &, std::string const &, afw::table::Schema &>(),
111 "ctrl"_a,
"name"_a,
"schema"_a);
113 declareComputeMethods<afw::image::Image<int>>(
cls);
114 declareComputeMethods<afw::image::Image<float>>(
cls);
115 declareComputeMethods<afw::image::Image<double>>(
cls);
116 declareComputeMethods<afw::image::MaskedImage<int>>(
cls);
117 declareComputeMethods<afw::image::MaskedImage<float>>(
cls);
118 declareComputeMethods<afw::image::MaskedImage<double>>(
cls);
121 cls.def(
"fail", &SdssShapeAlgorithm::fail,
"measRecord"_a,
"error"_a =
nullptr);
127 PyShapeResult
cls(mod,
"SdssShapeResult");
129 cls.def(py::init<>());
131 cls.def_readwrite(
"instFlux_xx_Cov", &SdssShapeResult::instFlux_xx_Cov);
132 cls.def_readwrite(
"instFlux_yy_Cov", &SdssShapeResult::instFlux_yy_Cov);
133 cls.def_readwrite(
"instFlux_xy_Cov", &SdssShapeResult::instFlux_xy_Cov);
134 cls.def_readwrite(
"flags", &SdssShapeResult::flags);
137 cls.def(
"getFlag", (
bool (SdssShapeResult::*)(
unsigned int)
const) & SdssShapeResult::getFlag,
"index"_a);
138 cls.def(
"getFlag", (
bool (SdssShapeResult::*)(
std::string const &
name)
const) & SdssShapeResult::getFlag,
142 PyShapeTransform declareShapeTransform(
py::module &mod) {
143 PyShapeTransform
cls(mod,
"SdssShapeTransform");
145 cls.def(py::init<SdssShapeTransform::Control const &, std::string const &, afw::table::SchemaMapper &>(),
146 "ctrl"_a,
"name"_a,
"mapper"_a);
148 cls.def(
"__call__", &SdssShapeTransform::operator(),
"inputCatalog"_a,
"outputCatalog"_a,
"wcs"_a,
157 py::module::import(
"lsst.afw.geom");
158 py::module::import(
"lsst.afw.table");
159 py::module::import(
"lsst.meas.base.algorithm");
160 py::module::import(
"lsst.meas.base.flagHandler");
161 py::module::import(
"lsst.meas.base.centroidUtilities");
162 py::module::import(
"lsst.meas.base.fluxUtilities");
163 py::module::import(
"lsst.meas.base.shapeUtilities");
164 py::module::import(
"lsst.meas.base.transform");
166 auto clsShapeControl = declareShapeControl(mod);
167 declareShapeResultKey(mod);
168 auto clsShapeAlgorithm = declareShapeAlgorithm(mod);
169 declareShapeResult(mod);
170 auto clsShapeTransform = declareShapeTransform(mod);
172 clsShapeAlgorithm.attr(
"Control") = clsShapeControl;
173 clsShapeTransform.attr(
"Control") = clsShapeControl;
175 python::declareAlgorithm<SdssShapeAlgorithm, SdssShapeControl, SdssShapeTransform>(
176 clsShapeAlgorithm, clsShapeControl, clsShapeTransform);