LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
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
bool contains(lsst::geom::Point2I const &pix) const
Tests if a pixel postion falls inside the Footprint.
Definition: Footprint.cc:79
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