24 #include "pybind11/pybind11.h"
25 #include "pybind11/stl.h"
29 #include "numpy/arrayobject.h"
30 #include "ndarray/pybind11.h"
32 #include "lsst/pex/exceptions.h"
37 namespace py = pybind11;
38 using namespace pybind11::literals;
46 template <
typename MaskT>
47 void declareMaskFromFootprintList(py::module &mod) {
49 std::vector<std::shared_ptr<lsst::afw::detection::Footprint>>
const &footprints,
50 MaskT
const bitmask,
bool doClip) {
51 for (
auto const &foot : footprints) {
54 auto tmpSpan = foot->getSpans()->clippedTo(mask->
getBBox());
55 tmpSpan->setMask(*mask, bitmask);
57 foot->getSpans()->setMask(*mask, bitmask);
59 }
catch (lsst::pex::exceptions::OutOfRangeError e) {
60 throw LSST_EXCEPT(lsst::pex::exceptions::OutOfRangeError,
61 "Bounds of a Footprint fall outside mask set doClip to force");
65 mod.def(
"setMaskFromFootprintList", std::move(maskSetter),
"mask"_a,
"footprints"_a,
"bitmask"_a,
72 py::module mod(
"_footprint",
"Python wrapper for afw Footprint library");
73 table::io::python::declarePersistableFacade<Footprint>(mod,
"Footprint");
75 if (_import_array() < 0) {
76 PyErr_SetString(PyExc_ImportError,
"numpy.core.multiarray failed to import");
83 clsFootprint(mod,
"Footprint");
84 clsFootprint.def(py::init<std::shared_ptr<geom::SpanSet>,
geom::Box2I const &>(),
"inputSpans"_a,
90 clsFootprint.def(py::init<Footprint const &>());
91 clsFootprint.def(py::init<>());
94 clsFootprint.def(
"getSpans", &Footprint::getSpans);
95 clsFootprint.def(
"setSpans", &Footprint::setSpans);
97 py::return_value_policy::reference_internal);
98 clsFootprint.def(
"addPeak", &Footprint::addPeak);
100 clsFootprint.def(
"setPeakSchema", &Footprint::setPeakSchema);
101 clsFootprint.def(
"getArea", &Footprint::getArea);
102 clsFootprint.def(
"getCentroid", &Footprint::getCentroid);
103 clsFootprint.def(
"getShape", &Footprint::getShape);
104 clsFootprint.def(
"shift", (
void (
Footprint::*)(
int,
int)) & Footprint::shift);
106 clsFootprint.def(
"getBBox", &Footprint::getBBox);
107 clsFootprint.def(
"getRegion", &Footprint::getRegion);
108 clsFootprint.def(
"setRegion", &Footprint::setRegion);
109 clsFootprint.def(
"clipTo", &Footprint::clipTo);
110 clsFootprint.def(
"contains", &Footprint::contains);
111 clsFootprint.def(
"transform", (std::shared_ptr<Footprint> (
Footprint::*)(
112 std::shared_ptr<image::Wcs>, std::shared_ptr<image::Wcs>,
114 Footprint::transform,
115 "source"_a,
"target"_a,
"region"_a,
"doClip"_a =
true);
116 clsFootprint.def(
"transform", (std::shared_ptr<Footprint> (
Footprint::*)(
118 Footprint::transform);
119 clsFootprint.def(
"transform", (std::shared_ptr<Footprint> (
Footprint::*)(
121 Footprint::transform);
122 clsFootprint.def(
"transform", (std::shared_ptr<Footprint> (
Footprint::*)(
124 Footprint::transform);
126 "stencil"_a = geom::Stencil::CIRCLE);
129 "stencil"_a = geom::Stencil::CIRCLE);
131 clsFootprint.def(
"removeOrphanPeaks", &Footprint::removeOrphanPeaks);
132 clsFootprint.def(
"isContiguous", &Footprint::isContiguous);
133 clsFootprint.def(
"isHeavy", &Footprint::isHeavy);
135 clsFootprint.def(
"split", [](
Footprint const &
self) -> py::list {
140 for (
auto &ptr :
self.split()) {
141 l.append(py::cast(std::shared_ptr<Footprint>(std::move(ptr))));
147 clsFootprint.def_property(
"spans", &Footprint::getSpans, &Footprint::setSpans);
148 clsFootprint.def_property_readonly(
"peaks", (
PeakCatalog & (
Footprint::*)()) & Footprint::getPeaks,
149 py::return_value_policy::reference);
153 return self.contains(point);
155 clsFootprint.def(
"__eq__",
159 declareMaskFromFootprintList<lsst::afw::image::MaskPixel>(mod);
Defines the fields and offsets for a table.
Stencil
An enumeration class which describes the shapes.
A compact representation of a collection of pixels.
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
An integer coordinate rectangle.
A base class for objects that can be persisted via afw::table::io Archive classes.
PYBIND11_PLUGIN(_cameraPoint)
Represent a 2-dimensional array of bitmask pixels.
std::shared_ptr< Footprint > mergeFootprints(Footprint const &footprint1, Footprint const &footprint2)
Merges two Footprints – appends their peaks, and unions their spans, returning a new Footprint...
std::vector< lsst::afw::geom::Box2I > footprintToBBoxList(Footprint const &footprint)
Return a list of BBoxs, whose union contains exactly the pixels in the footprint, neither more nor le...
A CRTP facade class for subclasses of Persistable.