24 #include "pybind11/pybind11.h"
25 #include "pybind11/stl.h"
29 #include "ndarray/pybind11.h"
38 using namespace pybind11::literals;
44 using utils::python::WrapperCollection;
48 template <
typename MaskT>
49 void declareMaskFromFootprintList(WrapperCollection &wrappers) {
52 MaskT
const bitmask,
bool doClip) {
53 for (
auto const &foot : footprints) {
56 auto tmpSpan = foot->getSpans()->clippedTo(
mask->getBBox());
57 tmpSpan->setMask(*
mask, bitmask);
59 foot->getSpans()->setMask(*
mask, bitmask);
63 "Bounds of a Footprint fall outside mask set doClip to force");
68 wrappers.wrap([&maskSetter](
auto &mod) {
69 mod.def(
"setMaskFromFootprintList",
std::move(maskSetter),
"mask"_a,
"footprints"_a,
"bitmask"_a,
77 wrappers.addInheritanceDependency(
"lsst.afw.table.io");
78 wrappers.addSignatureDependency(
"lsst.afw.geom");
79 wrappers.addSignatureDependency(
"lsst.afw.table");
83 [](
auto &mod,
auto &cls) {
84 cls.def(py::init<std::shared_ptr<geom::SpanSet>, lsst::geom::Box2I const &>(),
"inputSpans"_a,
85 "region"_a = lsst::geom::Box2I());
87 cls.def(py::init<std::shared_ptr<geom::SpanSet>, afw::table::Schema const &,
88 lsst::geom::Box2I const &>(),
89 "inputSpans"_a,
"peakSchema"_a,
"region"_a = lsst::geom::Box2I());
90 cls.def(py::init<Footprint const &>());
91 cls.def(py::init<>());
93 table::io::python::addPersistableMethods<Footprint>(cls);
95 cls.def(
"getSpans", &Footprint::getSpans);
96 cls.def(
"setSpans", &Footprint::setSpans);
97 cls.def(
"getPeaks", (PeakCatalog & (Footprint::*)()) & Footprint::getPeaks,
98 py::return_value_policy::reference_internal);
99 cls.def(
"addPeak", &Footprint::addPeak);
100 cls.def(
"sortPeaks", &Footprint::sortPeaks,
"key"_a = afw::table::Key<float>());
101 cls.def(
"setPeakSchema", &Footprint::setPeakSchema);
102 cls.def(
"setPeakCatalog", &Footprint::setPeakCatalog,
"otherPeaks"_a);
103 cls.def(
"getArea", &Footprint::getArea);
104 cls.def(
"getCentroid", &Footprint::getCentroid);
105 cls.def(
"getShape", &Footprint::getShape);
106 cls.def(
"shift", (void (Footprint::*)(int, int)) & Footprint::shift);
107 cls.def(
"shift", (void (Footprint::*)(lsst::geom::ExtentI const &)) & Footprint::shift);
108 cls.def(
"getBBox", &Footprint::getBBox);
109 cls.def(
"getRegion", &Footprint::getRegion);
110 cls.def(
"setRegion", &Footprint::setRegion);
111 cls.def(
"clipTo", &Footprint::clipTo);
112 cls.def(
"contains", &Footprint::contains);
114 (std::shared_ptr<Footprint>(Footprint::*)(std::shared_ptr<geom::SkyWcs>,
115 std::shared_ptr<geom::SkyWcs>,
116 lsst::geom::Box2I const &, bool) const) &
117 Footprint::transform,
118 "source"_a,
"target"_a,
"region"_a,
"doClip"_a = true);
120 (std::shared_ptr<Footprint>(Footprint::*)(lsst::geom::LinearTransform const &,
121 lsst::geom::Box2I const &, bool) const) &
122 Footprint::transform);
124 (std::shared_ptr<Footprint>(Footprint::*)(lsst::geom::AffineTransform const &,
125 lsst::geom::Box2I const &, bool) const) &
126 Footprint::transform);
128 (std::shared_ptr<Footprint>(Footprint::*)(geom::TransformPoint2ToPoint2 const &,
129 lsst::geom::Box2I const &, bool) const) &
130 Footprint::transform);
131 cls.def(
"dilate", (void (Footprint::*)(int, geom::Stencil)) & Footprint::dilate,
"r"_a,
132 "stencil"_a = geom::Stencil::CIRCLE);
133 cls.def(
"dilate", (void (Footprint::*)(geom::SpanSet const &)) & Footprint::dilate);
134 cls.def(
"erode", (void (Footprint::*)(int, geom::Stencil)) & Footprint::erode,
"r"_a,
135 "stencil"_a = geom::Stencil::CIRCLE);
136 cls.def(
"erode", (void (Footprint::*)(geom::SpanSet const &)) & Footprint::erode);
137 cls.def(
"removeOrphanPeaks", &Footprint::removeOrphanPeaks);
138 cls.def(
"isContiguous", &Footprint::isContiguous);
139 cls.def(
"isHeavy", &Footprint::isHeavy);
140 cls.def(
"assign", (Footprint & (Footprint::*)(Footprint const &)) & Footprint::operator=);
142 cls.def(
"split", [](Footprint const &self) -> py::list {
147 for (auto &ptr : self.split()) {
148 l.append(py::cast(std::shared_ptr<Footprint>(std::move(ptr))));
153 cls.def_property(
"spans", &Footprint::getSpans, &Footprint::setSpans);
155 py::return_value_policy::reference_internal);
158 return self.contains(point);
165 declareMaskFromFootprintList<lsst::afw::image::MaskPixel>(wrappers);
167 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.
A base class for image defects.