24#include "pybind11/pybind11.h"
25#include "pybind11/stl.h"
29#include "ndarray/pybind11.h"
39using namespace pybind11::literals;
45using utils::python::WrapperCollection;
49template <
typename MaskT>
50void declareMaskFromFootprintList(WrapperCollection &wrappers) {
53 MaskT
const bitmask,
bool doClip) {
54 for (
auto const &foot : footprints) {
57 auto tmpSpan = foot->getSpans()->clippedTo(
mask->getBBox());
58 tmpSpan->setMask(*
mask, bitmask);
60 foot->getSpans()->setMask(*
mask, bitmask);
64 "Bounds of a Footprint fall outside mask set doClip to force");
69 wrappers.wrap([&maskSetter](
auto &mod) {
70 mod.def(
"setMaskFromFootprintList",
std::move(maskSetter),
"mask"_a,
"footprints"_a,
"bitmask"_a,
78 wrappers.addInheritanceDependency(
"lsst.afw.table.io");
79 wrappers.addSignatureDependency(
"lsst.afw.geom");
80 wrappers.addSignatureDependency(
"lsst.afw.table");
84 [](
auto &mod,
auto &cls) {
85 cls.def(py::init<std::shared_ptr<geom::SpanSet>, lsst::geom::Box2I const &>(),
"inputSpans"_a,
86 "region"_a = lsst::geom::Box2I());
88 cls.def(py::init<std::shared_ptr<geom::SpanSet>, afw::table::Schema const &,
89 lsst::geom::Box2I const &>(),
90 "inputSpans"_a,
"peakSchema"_a,
"region"_a = lsst::geom::Box2I());
91 cls.def(py::init<Footprint const &>());
92 cls.def(py::init<>());
94 table::io::python::addPersistableMethods<Footprint>(cls);
96 cls.def(
"getSpans", &Footprint::getSpans);
97 cls.def(
"setSpans", &Footprint::setSpans);
98 cls.def(
"getPeaks", (PeakCatalog & (Footprint::*)()) & Footprint::getPeaks,
99 py::return_value_policy::reference_internal);
100 cls.def(
"addPeak", &Footprint::addPeak);
101 cls.def(
"sortPeaks", &Footprint::sortPeaks,
"key"_a = afw::table::Key<float>());
102 cls.def(
"setPeakSchema", &Footprint::setPeakSchema);
103 cls.def(
"setPeakCatalog", &Footprint::setPeakCatalog,
"otherPeaks"_a);
104 cls.def(
"getArea", &Footprint::getArea);
105 cls.def(
"getCentroid", &Footprint::getCentroid);
106 cls.def(
"getShape", &Footprint::getShape);
107 cls.def(
"shift", (void (Footprint::*)(int, int)) & Footprint::shift);
108 cls.def(
"shift", (void (Footprint::*)(lsst::geom::ExtentI const &)) & Footprint::shift);
109 cls.def(
"getBBox", &Footprint::getBBox);
110 cls.def(
"getRegion", &Footprint::getRegion);
111 cls.def(
"setRegion", &Footprint::setRegion);
112 cls.def(
"clipTo", &Footprint::clipTo);
113 cls.def(
"contains", &Footprint::contains);
115 (std::shared_ptr<Footprint>(Footprint::*)(std::shared_ptr<geom::SkyWcs>,
116 std::shared_ptr<geom::SkyWcs>,
117 lsst::geom::Box2I const &, bool) const) &
118 Footprint::transform,
119 "source"_a,
"target"_a,
"region"_a,
"doClip"_a = true);
121 (std::shared_ptr<Footprint>(Footprint::*)(lsst::geom::LinearTransform const &,
122 lsst::geom::Box2I const &, bool) const) &
123 Footprint::transform);
125 (std::shared_ptr<Footprint>(Footprint::*)(lsst::geom::AffineTransform const &,
126 lsst::geom::Box2I const &, bool) const) &
127 Footprint::transform);
129 (std::shared_ptr<Footprint>(Footprint::*)(geom::TransformPoint2ToPoint2 const &,
130 lsst::geom::Box2I const &, bool) const) &
131 Footprint::transform);
132 cls.def(
"dilate", (void (Footprint::*)(int, geom::Stencil)) & Footprint::dilate,
"r"_a,
133 "stencil"_a = geom::Stencil::CIRCLE);
134 cls.def(
"dilate", (void (Footprint::*)(geom::SpanSet const &)) & Footprint::dilate);
135 cls.def(
"erode", (void (Footprint::*)(int, geom::Stencil)) & Footprint::erode,
"r"_a,
136 "stencil"_a = geom::Stencil::CIRCLE);
137 cls.def(
"erode", (void (Footprint::*)(geom::SpanSet const &)) & Footprint::erode);
138 cls.def(
"removeOrphanPeaks", &Footprint::removeOrphanPeaks);
139 cls.def(
"updatePeakSignificance",
140 py::overload_cast<double>(&Footprint::updatePeakSignificance));
141 cls.def(
"updatePeakSignificance", py::overload_cast<image::Image<float> const &, int>(
142 &Footprint::updatePeakSignificance));
143 cls.def(
"isContiguous", &Footprint::isContiguous);
144 cls.def(
"isHeavy", &Footprint::isHeavy);
145 cls.def(
"assign", (Footprint & (Footprint::*)(Footprint const &)) & Footprint::operator=);
147 cls.def(
"split", [](Footprint const &self) -> py::list {
152 for (auto &ptr : self.split()) {
153 l.append(py::cast(std::shared_ptr<Footprint>(std::move(ptr))));
160 py::return_value_policy::reference_internal);
163 return self.contains(point);
172 declareMaskFromFootprintList<lsst::afw::image::MaskPixel>(wrappers);
174 wrappers.wrap([](
auto &mod) {
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Represent a 2-dimensional array of bitmask pixels.
Reports attempts to access elements outside a valid range of indices.
std::vector< lsst::geom::Box2I > footprintToBBoxList(Footprint const &footprint)
Return a list of BBoxs, whose union contains exactly the pixels in the footprint, neither more nor le...
void wrapFootprint(WrapperCollection &)
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.
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
A base class for image defects.