26 #include <pybind11/pybind11.h> 
   28 #include <pybind11/stl.h> 
   35 using namespace pybind11::literals;
 
   46 void declareSpatialCellCandidate(lsst::utils::python::WrapperCollection &wrappers) {
 
   47     using PyClass = py::class_<SpatialCellCandidate, std::shared_ptr<SpatialCellCandidate>>;
 
   48     auto clsSpatialCellCandidate =
 
   49             wrappers.wrapType(
PyClass(wrappers.module, 
"SpatialCellCandidate"), [](
auto &mod, 
auto &cls) {
 
   50                 cls.def(
"getXCenter", &SpatialCellCandidate::getXCenter);
 
   51                 cls.def(
"getYCenter", &SpatialCellCandidate::getYCenter);
 
   52                 cls.def(
"instantiate", &SpatialCellCandidate::instantiate);
 
   53                 cls.def(
"getCandidateRating", &SpatialCellCandidate::getCandidateRating);
 
   54                 cls.def(
"setCandidateRating", &SpatialCellCandidate::setCandidateRating);
 
   55                 cls.def(
"getId", &SpatialCellCandidate::getId);
 
   56                 cls.def(
"getStatus", &SpatialCellCandidate::getStatus);
 
   57                 cls.def(
"setStatus", &SpatialCellCandidate::setStatus);
 
   58                 cls.def(
"isBad", &SpatialCellCandidate::isBad);
 
   60     wrappers.wrapType(py::enum_<SpatialCellCandidate::Status>(clsSpatialCellCandidate, 
"Status"),
 
   61                       [](
auto &mod, 
auto &enm) {
 
   62                           enm.value(
"BAD", SpatialCellCandidate::Status::BAD);
 
   63                           enm.value(
"GOOD", SpatialCellCandidate::Status::GOOD);
 
   64                           enm.value(
"UNKNOWN", SpatialCellCandidate::Status::UNKNOWN);
 
   70 void declareSpatialCellCandidateIterator(lsst::utils::python::WrapperCollection &wrappers) {
 
   72             py::class_<SpatialCellCandidateIterator>(wrappers.module, 
"SpatialCellCandidateIterator"),
 
   73             [](
auto &mod, 
auto &cls) {
 
   74                 cls.def(
"__incr__", &SpatialCellCandidateIterator::operator++, py::is_operator());
 
   77                         [](SpatialCellCandidateIterator &it) -> std::shared_ptr<SpatialCellCandidate> {
 
   81                 cls.def(
"__eq__", &SpatialCellCandidateIterator::operator==, py::is_operator());
 
   82                 cls.def(
"__ne__", &SpatialCellCandidateIterator::operator!=, py::is_operator());
 
   83                 cls.def(
"__sub__", &SpatialCellCandidateIterator::operator-, py::is_operator());
 
   88 void declareSpatialCell(lsst::utils::python::WrapperCollection &wrappers) {
 
   91             [](
auto &mod, 
auto &cls) {
 
   92                 cls.def(py::init<std::string const &, lsst::geom::Box2I const &, CandidateList const &>(),
 
   93                         "label"_a, 
"bbox"_a = lsst::geom::Box2I(), 
"candidateList"_a = CandidateList());
 
   95                 cls.def(
"empty", &SpatialCell::empty);
 
   96                 cls.def(
"size", &SpatialCell::size);
 
   97                 cls.def(
"__len__", &SpatialCell::size);
 
   98                 cls.def(
"getLabel", &SpatialCell::getLabel);
 
   99                 cls.def(
"begin", (SpatialCellCandidateIterator(SpatialCell::*)()) & SpatialCell::begin);
 
  100                 cls.def(
"begin", (SpatialCellCandidateIterator(SpatialCell::*)(bool)) & SpatialCell::begin);
 
  101                 cls.def(
"end", (SpatialCellCandidateIterator(SpatialCell::*)()) & SpatialCell::end);
 
  102                 cls.def(
"end", (SpatialCellCandidateIterator(SpatialCell::*)(bool)) & SpatialCell::end);
 
  103                 cls.def(
"insertCandidate", &SpatialCell::insertCandidate);
 
  104                 cls.def(
"removeCandidate", &SpatialCell::removeCandidate);
 
  105                 cls.def(
"setIgnoreBad", &SpatialCell::setIgnoreBad, 
"ignoreBad"_a);
 
  106                 cls.def(
"getIgnoreBad", &SpatialCell::getIgnoreBad);
 
  107                 cls.def(
"getCandidateById", &SpatialCell::getCandidateById, 
"id"_a, 
"noThrow"_a = false);
 
  108                 cls.def(
"getLabel", &SpatialCell::getLabel);
 
  109                 cls.def(
"getBBox", &SpatialCell::getBBox);
 
  110                 cls.def(
"sortCandidates", &SpatialCell::sortCandidates);
 
  111                 cls.def(
"visitCandidates",
 
  112                         (void (SpatialCell::*)(CandidateVisitor *, int const, bool const, bool const)) &
 
  113                                 SpatialCell::visitCandidates,
 
  114                         "visitor"_a, 
"nMaxPerCell"_a = -1, 
"ignoreExceptions"_a = false, 
"reset"_a = true);
 
  115                 cls.def(
"visitAllCandidates",
 
  116                         (void (SpatialCell::*)(CandidateVisitor *, bool const, bool const)) &
 
  117                                 SpatialCell::visitAllCandidates,
 
  118                         "visitor"_a, 
"ignoreExceptions"_a = false, 
"reset"_a = true);
 
  123 void declareSpatialCellSet(lsst::utils::python::WrapperCollection &wrappers) {
 
  126             [](
auto &mod, 
auto &cls) {
 
  127                 cls.def(py::init<lsst::geom::Box2I const &, int, int>(), 
"region"_a, 
"xSize"_a,
 
  130                 cls.def(
"getCellList", &SpatialCellSet::getCellList);
 
  131                 cls.def(
"getBBox", &SpatialCellSet::getBBox);
 
  132                 cls.def(
"insertCandidate", &SpatialCellSet::insertCandidate);
 
  133                 cls.def(
"sortCandidates", &SpatialCellSet::sortCandidates);
 
  134                 cls.def(
"visitCandidates",
 
  135                         (void (SpatialCellSet::*)(CandidateVisitor *, int const, bool const)) &
 
  136                                 SpatialCellSet::visitCandidates,
 
  137                         "visitor"_a, 
"nMaxPerCell"_a = -1, 
"ignoreExceptions"_a = false);
 
  138                 cls.def(
"visitAllCandidates",
 
  139                         (void (SpatialCellSet::*)(CandidateVisitor *, bool const)) &
 
  140                                 SpatialCellSet::visitAllCandidates,
 
  141                         "visitor"_a, 
"ignoreExceptions"_a = false);
 
  142                 cls.def(
"getCandidateById", &SpatialCellSet::getCandidateById, 
"id"_a, 
"noThrow"_a = false);
 
  143                 cls.def(
"setIgnoreBad", &SpatialCellSet::setIgnoreBad, 
"ignoreBad"_a);
 
  148 void declareCandidateVisitor(lsst::utils::python::WrapperCollection &wrappers) {
 
  151                       [](
auto &mod, 
auto &cls) {
 
  152                           cls.def(py::init<>());
 
  154                           cls.def(
"reset", &CandidateVisitor::reset);
 
  155                           cls.def(
"processCandidate", &CandidateVisitor::processCandidate);
 
  160 void declareSpatialCellImageCandidate(lsst::utils::python::WrapperCollection &wrappers) {
 
  162                                  SpatialCellCandidate>(wrappers.module, 
"SpatialCellImageCandidate"),
 
  163                       [](
auto &mod, 
auto &cls) {
 
  164                           cls.def_static(
"setWidth", &SpatialCellImageCandidate::setWidth, 
"width"_a);
 
  165                           cls.def_static(
"getWidth", &SpatialCellImageCandidate::getWidth);
 
  166                           cls.def_static(
"setHeight", &SpatialCellImageCandidate::setHeight, 
"height"_a);
 
  167                           cls.def_static(
"getHeight", &SpatialCellImageCandidate::getHeight);
 
  168                           cls.def(
"setChi2", &SpatialCellImageCandidate::setChi2, 
"chi2"_a);
 
  169                           cls.def(
"getChi2", &SpatialCellImageCandidate::getChi2);
 
  173 void declareTestClasses(lsst::utils::python::WrapperCollection &wrappers) {
 
  177     class TestCandidate : 
public SpatialCellCandidate {
 
  179         TestCandidate(
float const xCenter,  
 
  183                 : SpatialCellCandidate(xCenter, yCenter), _flux(flux) {}
 
  186         double getCandidateRating()
 const override { 
return _flux; }
 
  187         void setCandidateRating(
double flux)
 override { _flux = flux; }
 
  194     class TestCandidateVisitor : 
public CandidateVisitor {
 
  196         TestCandidateVisitor() : CandidateVisitor() {}
 
  199         void reset()
 override { _n = 0; }
 
  202         void processCandidate(SpatialCellCandidate *candidate)
 override { ++_n; }
 
  204         int getN()
 const { 
return _n; }
 
  210     class TestImageCandidate : 
public SpatialCellImageCandidate {
 
  214         TestImageCandidate(
float const xCenter,  
 
  218                 : SpatialCellImageCandidate(xCenter, yCenter), _flux(flux) {}
 
  221         double getCandidateRating()
 const override { 
return _flux; }
 
  227                 *_image->getImage() = _flux;
 
  238                               wrappers.module, 
"TestCandidate"),
 
  239                       [](
auto &mod, 
auto &cls) {
 
  240                           cls.def(py::init<float const, float const, float const>());
 
  241                           cls.def(
"getCandidateRating", &TestCandidate::getCandidateRating);
 
  242                           cls.def(
"setCandidateRating", &TestCandidate::setCandidateRating);
 
  246                     wrappers.module, 
"TestCandidateVisitor"),
 
  247             [](
auto &mod, 
auto &cls) {
 
  248                 cls.def(py::init<>());
 
  249                 cls.def(
"getN", &TestCandidateVisitor::getN);
 
  253                     wrappers.module, 
"TestImageCandidate"),
 
  254             [](
auto &mod, 
auto &cls) {
 
  255                 cls.def(py::init<float const, float const, float const>(), 
"xCenter"_a, 
"yCenter"_a,
 
  257                 cls.def(
"getCandidateRating", &TestImageCandidate::getCandidateRating);
 
  258                 cls.def(
"getMaskedImage", &TestImageCandidate::getMaskedImage);
 
  263     declareSpatialCellCandidate(wrappers);
 
  264     declareSpatialCellCandidateIterator(wrappers);
 
  265     declareSpatialCell(wrappers);
 
  266     declareSpatialCellSet(wrappers);
 
  267     declareCandidateVisitor(wrappers);
 
  268     declareSpatialCellImageCandidate(wrappers);
 
  270     declareTestClasses(wrappers);
 
A class to manipulate images, masks, and variance as a single object.
void wrapSpatialCell(lsst::utils::python::WrapperCollection &)
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass
A base class for image defects.