26 #include <pybind11/pybind11.h> 27 #include <pybind11/stl.h> 32 namespace py = pybind11;
41 using CandidateList = std::vector<std::shared_ptr<SpatialCellCandidate>>;
44 void wrapSpatialCellCandidate(py::module &mod) {
45 py::class_<SpatialCellCandidate, std::shared_ptr<SpatialCellCandidate>>
cls(mod,
"SpatialCellCandidate");
47 py::enum_<SpatialCellCandidate::Status>(
cls,
"Status")
48 .value(
"BAD", SpatialCellCandidate::Status::BAD)
49 .value(
"GOOD", SpatialCellCandidate::Status::GOOD)
53 cls.def(
"getXCenter", &SpatialCellCandidate::getXCenter);
54 cls.def(
"getYCenter", &SpatialCellCandidate::getYCenter);
55 cls.def(
"instantiate", &SpatialCellCandidate::instantiate);
56 cls.def(
"getCandidateRating", &SpatialCellCandidate::getCandidateRating);
57 cls.def(
"setCandidateRating", &SpatialCellCandidate::setCandidateRating);
58 cls.def(
"getId", &SpatialCellCandidate::getId);
59 cls.def(
"getStatus", &SpatialCellCandidate::getStatus);
60 cls.def(
"setStatus", &SpatialCellCandidate::setStatus);
61 cls.def(
"isBad", &SpatialCellCandidate::isBad);
65 void wrapSpatialCellCandidateIterator(py::module &mod) {
66 py::class_<SpatialCellCandidateIterator>
cls(mod,
"SpatialCellCandidateIterator");
67 cls.def(
"__incr__", &SpatialCellCandidateIterator::operator++, py::is_operator());
69 [](SpatialCellCandidateIterator &it) -> std::shared_ptr<SpatialCellCandidate> {
return *it; },
71 cls.def(
"__eq__", &SpatialCellCandidateIterator::operator==, py::is_operator());
72 cls.def(
"__ne__", &SpatialCellCandidateIterator::operator!=, py::is_operator());
73 cls.def(
"__sub__", &SpatialCellCandidateIterator::operator-, py::is_operator());
77 void wrapSpatialCell(py::module &mod) {
78 py::class_<SpatialCell, std::shared_ptr<SpatialCell>>
cls(mod,
"SpatialCell");
80 cls.def(py::init<std::string const &, geom::Box2I const &, CandidateList const &>(),
"label"_a,
81 "bbox"_a = geom::Box2I(),
"candidateList"_a = CandidateList());
83 cls.def(
"empty", &SpatialCell::empty);
84 cls.def(
"size", &SpatialCell::size);
85 cls.def(
"__len__", &SpatialCell::size);
86 cls.def(
"getLabel", &SpatialCell::getLabel);
87 cls.def(
"begin", (SpatialCellCandidateIterator (SpatialCell::*)()) & SpatialCell::begin);
88 cls.def(
"begin", (SpatialCellCandidateIterator (SpatialCell::*)(
bool)) & SpatialCell::begin);
89 cls.def(
"end", (SpatialCellCandidateIterator (SpatialCell::*)()) &
SpatialCell::end);
90 cls.def(
"end", (SpatialCellCandidateIterator (SpatialCell::*)(
bool)) &
SpatialCell::end);
91 cls.def(
"insertCandidate", &SpatialCell::insertCandidate);
92 cls.def(
"removeCandidate", &SpatialCell::removeCandidate);
93 cls.def(
"setIgnoreBad", &SpatialCell::setIgnoreBad,
"ignoreBad"_a);
94 cls.def(
"getIgnoreBad", &SpatialCell::getIgnoreBad);
95 cls.def(
"getCandidateById", &SpatialCell::getCandidateById,
"id"_a,
"noThrow"_a =
false);
96 cls.def(
"getLabel", &SpatialCell::getLabel);
97 cls.def(
"getBBox", &SpatialCell::getBBox);
98 cls.def(
"sortCandidates", &SpatialCell::sortCandidates);
99 cls.def(
"visitCandidates",
100 (
void (SpatialCell::*)(CandidateVisitor *,
int const,
bool const,
bool const)) &
101 SpatialCell::visitCandidates,
102 "visitor"_a,
"nMaxPerCell"_a = -1,
"ignoreExceptions"_a =
false,
"reset"_a =
true);
103 cls.def(
"visitAllCandidates", (
void (SpatialCell::*)(CandidateVisitor *,
bool const,
bool const)) &
104 SpatialCell::visitAllCandidates,
105 "visitor"_a,
"ignoreExceptions"_a =
false,
"reset"_a =
true);
109 void wrapSpatialCellSet(py::module &mod) {
110 py::class_<SpatialCellSet, std::shared_ptr<SpatialCellSet>>
cls(mod,
"SpatialCellSet");
112 cls.def(py::init<geom::Box2I const &, int, int>(),
"region"_a,
"xSize"_a,
"ySize"_a = 0);
114 cls.def(
"getCellList", &SpatialCellSet::getCellList);
115 cls.def(
"getBBox", &SpatialCellSet::getBBox);
116 cls.def(
"insertCandidate", &SpatialCellSet::insertCandidate);
117 cls.def(
"sortCandidates", &SpatialCellSet::sortCandidates);
118 cls.def(
"visitCandidates", (
void (SpatialCellSet::*)(CandidateVisitor *,
int const,
bool const)) &
119 SpatialCellSet::visitCandidates,
120 "visitor"_a,
"nMaxPerCell"_a = -1,
"ignoreExceptions"_a =
false);
121 cls.def(
"visitAllCandidates",
122 (
void (SpatialCellSet::*)(CandidateVisitor *,
bool const)) & SpatialCellSet::visitAllCandidates,
123 "visitor"_a,
"ignoreExceptions"_a =
false);
124 cls.def(
"getCandidateById", &SpatialCellSet::getCandidateById,
"id"_a,
"noThrow"_a =
false);
125 cls.def(
"setIgnoreBad", &SpatialCellSet::setIgnoreBad,
"ignoreBad"_a);
129 void wrapCandidateVisitor(py::module &mod) {
130 py::class_<CandidateVisitor, std::shared_ptr<CandidateVisitor>>
cls(mod,
"CandidateVisitor");
132 cls.def(py::init<>());
134 cls.def(
"reset", &CandidateVisitor::reset);
135 cls.def(
"processCandidate", &CandidateVisitor::processCandidate);
139 void wrapSpatialCellImageCandidate(py::module &mod) {
140 py::class_<SpatialCellImageCandidate, std::shared_ptr<SpatialCellImageCandidate>, SpatialCellCandidate>
141 cls(mod,
"SpatialCellImageCandidate");
143 cls.def_static(
"setWidth", &SpatialCellImageCandidate::setWidth,
"width"_a);
144 cls.def_static(
"getWidth", &SpatialCellImageCandidate::getWidth);
145 cls.def_static(
"setHeight", &SpatialCellImageCandidate::setHeight,
"height"_a);
146 cls.def_static(
"getHeight", &SpatialCellImageCandidate::getHeight);
147 cls.def(
"setChi2", &SpatialCellImageCandidate::setChi2,
"chi2"_a);
148 cls.def(
"getChi2", &SpatialCellImageCandidate::getChi2);
161 TestCandidate(
float const xCenter,
168 virtual double getCandidateRating()
const {
return _flux; }
169 virtual void setCandidateRating(
double flux) { _flux = flux; }
181 void reset() { _n = 0; }
186 int getN()
const {
return _n; }
196 TestImageCandidate(
float const xCenter,
203 double getCandidateRating()
const {
return _flux; }
206 std::shared_ptr<MaskedImageT const> getMaskedImage()
const {
208 _image = std::make_shared<MaskedImageT>(
geom::ExtentI(getWidth(), getHeight()));
209 *_image->getImage() = _flux;
215 mutable std::shared_ptr<MaskedImageT> _image;
219 py::class_<TestCandidate, std::shared_ptr<TestCandidate>,
SpatialCellCandidate> clsTestCandidate(
220 mod, (
"TestCandidate"));
221 clsTestCandidate.def(py::init<float const, float const, float const>());
222 clsTestCandidate.def(
"getCandidateRating", &TestCandidate::getCandidateRating);
223 clsTestCandidate.def(
"setCandidateRating", &TestCandidate::setCandidateRating);
225 py::class_<TestCandidateVisitor, std::shared_ptr<TestCandidateVisitor>,
CandidateVisitor>
226 clsTestCandidateVisitor(mod, (
"TestCandidateVisitor"));
227 clsTestCandidateVisitor.def(py::init<>());
228 clsTestCandidateVisitor.def(
"getN", &TestCandidateVisitor::getN);
231 clsTestImageCandidate(mod,
"TestImageCandidate");
232 clsTestImageCandidate.def(py::init<float const, float const, float const>(),
"xCenter"_a,
"yCenter"_a,
234 clsTestImageCandidate.def(
"getCandidateRating", &TestImageCandidate::getCandidateRating);
235 clsTestImageCandidate.def(
"getMaskedImage", &TestImageCandidate::getMaskedImage);
239 py::module mod(
"_spatialCell",
"Python wrapper for afw _spatialCell library");
241 wrapSpatialCellCandidate(mod);
242 wrapSpatialCellCandidateIterator(mod);
243 wrapSpatialCell(mod);
244 wrapSpatialCellSet(mod);
245 wrapCandidateVisitor(mod);
246 wrapSpatialCellImageCandidate(mod);
A base class for image defects.
PYBIND11_PLUGIN(_spatialCell)
A class to manipulate images, masks, and variance as a single object.
void wrapTestClasses(py::module &mod)
Base class for candidate objects in a SpatialCell that are able to return an Image of some sort (e...
Base class for candidate objects in a SpatialCell.