LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
LSST Data Management Base Package
Loading...
Searching...
No Matches
_footprint.cc
Go to the documentation of this file.
1/*
2 * This file is part of afw.
3 *
4 * Developed for the LSST Data Management System.
5 * This product includes software developed by the LSST Project
6 * (https://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#include "pybind11/pybind11.h"
25#include "pybind11/stl.h"
26
27#include <cstdint>
28
29#include "ndarray/pybind11.h"
30
31#include "lsst/utils/python.h"
32
34#include "lsst/pex/exceptions.h"
35#include "lsst/afw/table/io/python.h" // for addPersistableMethods
37
38namespace py = pybind11;
39using namespace pybind11::literals;
40
41namespace lsst {
42namespace afw {
43namespace detection {
44
45using utils::python::WrapperCollection;
46
47namespace {
48
49template <typename MaskT>
50void declareMaskFromFootprintList(WrapperCollection &wrappers) {
51 auto maskSetter = [](lsst::afw::image::Mask<MaskT> *mask,
53 MaskT const bitmask, bool doClip) {
54 for (auto const &foot : footprints) {
55 try {
56 if (doClip) {
57 auto tmpSpan = foot->getSpans()->clippedTo(mask->getBBox());
58 tmpSpan->setMask(*mask, bitmask);
59 } else {
60 foot->getSpans()->setMask(*mask, bitmask);
61 }
64 "Bounds of a Footprint fall outside mask set doClip to force");
65 }
66 }
67 };
68
69 wrappers.wrap([&maskSetter](auto &mod) {
70 mod.def("setMaskFromFootprintList", std::move(maskSetter), "mask"_a, "footprints"_a, "bitmask"_a,
71 "doClip"_a = true);
72 });
73}
74
75} // end anonymous namespace
76
77void wrapFootprint(WrapperCollection &wrappers) {
78 wrappers.addInheritanceDependency("lsst.afw.table.io");
79 wrappers.addSignatureDependency("lsst.afw.geom");
80 wrappers.addSignatureDependency("lsst.afw.table");
81
82 wrappers.wrapType(
83 py::class_<Footprint, std::shared_ptr<Footprint>>(wrappers.module, "Footprint"),
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());
87
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<>());
93
94 table::io::python::addPersistableMethods<Footprint>(cls);
95
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);
114 cls.def("transform",
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);
120 cls.def("transform",
121 (std::shared_ptr<Footprint>(Footprint::*)(lsst::geom::LinearTransform const &,
122 lsst::geom::Box2I const &, bool) const) &
123 Footprint::transform);
124 cls.def("transform",
125 (std::shared_ptr<Footprint>(Footprint::*)(lsst::geom::AffineTransform const &,
126 lsst::geom::Box2I const &, bool) const) &
127 Footprint::transform);
128 cls.def("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=);
146
147 cls.def("split", [](Footprint const &self) -> py::list {
148 /* This is a work around for pybind not properly
149 * handling converting a vector of unique pointers
150 * to python lists of shared pointers */
151 py::list l;
152 for (auto &ptr : self.split()) {
153 l.append(py::cast(std::shared_ptr<Footprint>(std::move(ptr))));
154 }
155 return l;
156 });
157
158 cls.def_property("spans", &Footprint::getSpans, &Footprint::setSpans);
159 cls.def_property_readonly("peaks", (PeakCatalog & (Footprint::*)()) & Footprint::getPeaks,
160 py::return_value_policy::reference_internal);
161
162 cls.def("__contains__", [](Footprint const &self, lsst::geom::Point2I const &point) -> bool {
163 return self.contains(point);
164 });
165 cls.def(
166 "__eq__",
167 [](Footprint const &self, Footprint const &other) -> bool { return self == other; },
168 py::is_operator());
169 utils::python::addOutputOp(cls, "__repr__");
170 });
171
172 declareMaskFromFootprintList<lsst::afw::image::MaskPixel>(wrappers);
173
174 wrappers.wrap([](auto &mod) {
175 mod.def("mergeFootprints", &mergeFootprints);
176 mod.def("footprintToBBoxList", &footprintToBBoxList);
177 });
178}
179
180} // namespace detection
181} // namespace afw
182} // namespace lsst
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
afw::table::Key< afw::table::Array< MaskPixelT > > mask
Class to describe the properties of a detected object from an image.
Definition Footprint.h:63
std::shared_ptr< geom::SpanSet > getSpans() const
Return a shared pointer to the SpanSet.
Definition Footprint.h:115
PeakCatalog & getPeaks()
Return the Peaks contained in this Footprint.
Definition Footprint.h:129
void setSpans(std::shared_ptr< geom::SpanSet > otherSpanSet)
Sets the shared pointer to the SpanSet in the Footprint.
Definition Footprint.cc:45
Represent a 2-dimensional array of bitmask pixels.
Definition Mask.h:77
Reports attempts to access elements outside a valid range of indices.
Definition Runtime.h:89
T move(T... args)
void wrapFootprint(WrapperCollection &)
Definition _footprint.cc:77
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.
Definition Footprint.cc:341