LSST Applications g180d380827+78227d2bc4,g2079a07aa2+86d27d4dc4,g2305ad1205+bdd7851fe3,g2bbee38e9b+c6a8a0fb72,g337abbeb29+c6a8a0fb72,g33d1c0ed96+c6a8a0fb72,g3a166c0a6a+c6a8a0fb72,g3d1719c13e+260d7c3927,g3ddfee87b4+723a6db5f3,g487adcacf7+29e55ea757,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+9443c4b912,g62aa8f1a4b+7e2ea9cd42,g858d7b2824+260d7c3927,g864b0138d7+8498d97249,g95921f966b+dffe86973d,g991b906543+260d7c3927,g99cad8db69+4809d78dd9,g9c22b2923f+e2510deafe,g9ddcbc5298+9a081db1e4,ga1e77700b3+03d07e1c1f,gb0e22166c9+60f28cb32d,gb23b769143+260d7c3927,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e22341fd87,gbd998247f1+585e252eca,gc120e1dc64+713f94b854,gc28159a63d+c6a8a0fb72,gc3e9b769f7+385ea95214,gcf0d15dbbd+723a6db5f3,gdaeeff99f8+f9a426f77a,ge6526c86ff+fde82a80b9,ge79ae78c31+c6a8a0fb72,gee10cc3b42+585e252eca,w.2024.18
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