22 #include "pybind11/pybind11.h"
24 #include "numpy/arrayobject.h"
25 #include "ndarray/pybind11.h"
28 #include "lsst/pex/config/python.h"
30 namespace py = pybind11;
31 using namespace pybind11::literals;
35 namespace extensions {
36 namespace simpleShape {
40 template <
typename T,
typename PyClass>
41 static void declareMoments(PyClass cls) {
42 cls.def_static(
"computeMoments", (SimpleShapeResult(*)(afw::geom::ellipses::Ellipse
const &,
43 afw::image::MaskedImage<T>
const &,
double)) &
44 SimpleShape::computeMoments,
45 "weight"_a,
"image"_a,
"nSigmaRegion"_a = 3.0);
51 py::module::import(
"lsst.afw.geom");
52 py::module::import(
"lsst.afw.image");
53 py::module::import(
"lsst.afw.table");
54 py::module::import(
"lsst.meas.base");
56 py::module mod(
"simpleShape");
58 if (_import_array() < 0) {
59 PyErr_SetString(PyExc_ImportError,
"numpy.core.multiarray failed to import");
64 py::class_<SimpleShape, std::shared_ptr<SimpleShape>, base::SimpleAlgorithm> clsSimpleShape(
66 py::class_<SimpleShapeControl> clsSimpleShapeControl(mod,
"SimpleShapeControl");
67 py::class_<SimpleShapeResult> clsSimpleShapeResult(mod,
"SimpleShapeResult");
68 py::class_<SimpleShapeResultKey> clsSimpleShapeResultKey(mod,
"SimpleShapeResultKey");
71 clsSimpleShape.def(py::init<SimpleShape::Control const &, std::string const &, afw::table::Schema &>(),
72 "ctrl"_a,
"name"_a,
"schema"_a);
73 clsSimpleShapeControl.def(py::init<>());
75 clsSimpleShapeResultKey.def(py::init<afw::table::SubSchema const &>(),
"s"_a);
81 declareMoments<float>(clsSimpleShape);
82 declareMoments<double>(clsSimpleShape);
83 clsSimpleShape.def_static(
"correctWeightedMoments", &SimpleShape::correctWeightedMoments,
"weight"_a,
84 "ellipse"_a,
"center"_a);
86 clsSimpleShapeResult.def_readwrite(
"ellipse", &SimpleShapeResult::ellipse);
87 clsSimpleShapeResult.def_readwrite(
"center", &SimpleShapeResult::center);
89 clsSimpleShapeResult.def(
"getFlag", &SimpleShapeResult::getFlag);
91 clsSimpleShapeResultKey.def(
"get", &SimpleShapeResultKey::get,
"record"_a);
PYBIND11_PLUGIN(simpleShape)
A C++ control class to handle SdssShapeAlgorithm's configuration.