LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
Namespaces | Classes | Typedefs | Functions
lsst::afw::detection Namespace Reference

Namespaces

namespace  _footprintMerge
 
namespace  _heavyFootprintContinued
 
namespace  _peak
 
namespace  detail
 
namespace  multiband
 
namespace  utils
 

Classes

class  Footprint
 Class to describe the properties of a detected object from an image. More...
 
class  FootprintControl
 A Control Object for Footprints, controlling e.g. More...
 
class  FootprintFactory
 
class  FootprintMerge
 
class  FootprintMergeList
 List of Merged Footprints. More...
 
class  FootprintSet
 A set of Footprints, associated with a MaskedImage. More...
 
class  GaussianPsf
 A circularly symmetric Gaussian Psf class with no spatial variation, intended mostly for testing purposes. More...
 
class  HeavyFootprint
 A set of pixels in an Image, including those pixels' actual values. More...
 
class  HeavyFootprintCtrl
 A control object for HeavyFootprints. More...
 
class  IdSpan
 run-length code for part of object More...
 
struct  IdSpanCompar
 comparison functor; sort by ID, then by row (y), then by column range start (x0) More...
 
class  PeakRecord
 Record class that represents a peak in a Footprint. More...
 
class  PeakTable
 Table class for Peaks in Footprints. More...
 
class  Psf
 A polymorphic base class for representing an image's Point Spread Function. More...
 
class  PsfTrampoline
 "Trampoline" for Psf to let it be used as a base class in Python. More...
 
class  Threshold
 A Threshold is used to pass a threshold value to detection algorithms. More...
 

Typedefs

using FootprintIdPixel = std::uint64_t
 Pixel type for FootprintSet::insertIntoImage() More...
 
using PeakColumnView = afw::table::ColumnViewT< PeakRecord >
 
using PeakCatalog = afw::table::CatalogT< PeakRecord >
 
using ConstPeakCatalog = afw::table::CatalogT< const PeakRecord >
 

Functions

std::ostreamoperator<< (std::ostream &os, Footprint const &rhs)
 Print a Footprint to the stream. More...
 
std::shared_ptr< FootprintmergeFootprints (Footprint const &footprint1, Footprint const &footprint2)
 Merges two Footprints – appends their peaks, and unions their spans, returning a new Footprint. More...
 
std::vector< lsst::geom::Box2IfootprintToBBoxList (Footprint const &footprint)
 Return a list of BBoxs, whose union contains exactly the pixels in the footprint, neither more nor less. More...
 
std::ostreamoperator<< (std::ostream &os, FootprintSet const &rhs)
 Print a FootprintSet to the stream. More...
 
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > makeHeavyFootprint (Footprint const &foot, lsst::afw::image::MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > const &img, HeavyFootprintCtrl const *ctrl=nullptr)
 Create a HeavyFootprint with footprint defined by the given Footprint and pixel values from the given MaskedImage. More...
 
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
std::shared_ptr< HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > > mergeHeavyFootprints (HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > const &h1, HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > const &h2)
 Sum the two given HeavyFootprints h1 and h2, returning a HeavyFootprint with the union footprint, and summed pixels where they overlap. More...
 
std::ostreamoperator<< (std::ostream &os, PeakRecord const &record)
 
Threshold createThreshold (const double value, const std::string type="value", const bool polarity=true)
 Factory method for creating Threshold objects. More...
 
void wrapFootprint (WrapperCollection &)
 
void wrapFootprintCtrl (WrapperCollection &)
 
void wrapFootprintMerge (WrapperCollection &)
 
void wrapFootprintSet (WrapperCollection &)
 
void wrapGaussianPsf (WrapperCollection &)
 
void wrapHeavyFootprint (WrapperCollection &)
 
void wrapPeak (WrapperCollection &)
 
void wrapPsf (WrapperCollection &)
 
void wrapThreshold (WrapperCollection &)
 
 PYBIND11_MODULE (_detection, mod)
 
void wrapFootprintCtrl (utils::python::WrapperCollection &wrappers)
 
void wrapFootprintMerge (utils::python::WrapperCollection &wrappers)
 
void wrapFootprintSet (utils::python::WrapperCollection &wrappers)
 
void wrapGaussianPsf (utils::python::WrapperCollection &wrappers)
 
void wrapPeak (utils::python::WrapperCollection &wrappers)
 
void wrapPsf (utils::python::WrapperCollection &wrappers)
 
void wrapThreshold (utils::python::WrapperCollection &wrappers)
 
int resolve_alias (const std::vector< int > &aliases, int id)
 Follow a chain of aliases, returning the final resolved value. More...
 

Typedef Documentation

◆ ConstPeakCatalog

Definition at line 245 of file Peak.h.

◆ FootprintIdPixel

Pixel type for FootprintSet::insertIntoImage()

This is independent of the template parameters for FootprintSet, and including it within FootprintSet makes it difficult for SWIG to interpret the type.

Definition at line 50 of file FootprintSet.h.

◆ PeakCatalog

Definition at line 244 of file Peak.h.

◆ PeakColumnView

Definition at line 243 of file Peak.h.

Function Documentation

◆ createThreshold()

Threshold lsst::afw::detection::createThreshold ( const double  value,
const std::string  type = "value",
const bool  polarity = true 
)

Factory method for creating Threshold objects.

Parameters
valuevalue of threshold
typestring representation of a ThresholdType. This parameter is optional. Allowed values are: "variance", "value", "stdev", "pixel_stdev"
polarityIf true detect positive objects, false for negative
Returns
desired Threshold

Definition at line 109 of file Threshold.cc.

109 {
110 return Threshold(value, Threshold::parseTypeString(typeStr), polarity);
111}
A Threshold is used to pass a threshold value to detection algorithms.
Definition: Threshold.h:43

◆ footprintToBBoxList()

std::vector< lsst::geom::Box2I > lsst::afw::detection::footprintToBBoxList ( Footprint const &  footprint)

Return a list of BBoxs, whose union contains exactly the pixels in the footprint, neither more nor less.

Useful in generating sets of meas::algorithms::Defects for the ISR

Parameters
footprintFootprint to turn into bounding box list

Definition at line 366 of file Footprint.cc.

366 {
367 using PixelT = std::uint16_t;
368 lsst::geom::Box2I fpBBox = footprint.getBBox();
370 *idImage = 0;
371 int const height = fpBBox.getHeight();
372 lsst::geom::Extent2I shift(fpBBox.getMinX(), fpBBox.getMinY());
373 footprint.getSpans()->setImage(*idImage, static_cast<PixelT>(1), fpBBox, true);
374
376 /*
377 * Our strategy is to find a row of pixels in the Footprint and interpret it as the first
378 * row of a rectangular set of pixels. We then extend this rectangle upwards as far as it
379 * will go, and define that as a BBox. We clear all those pixels, and repeat until there
380 * are none left. I.e. a Footprint will get cut up like this:
381 *
382 * .555...
383 * 22.3314
384 * 22.331.
385 * .000.1.
386 * (as shown in Footprint_1.py)
387 */
388
389 int y0 = 0; // the first row with non-zero pixels in it
390 while (y0 < height) {
391 lsst::geom::Box2I bbox; // our next BBox
392 for (int y = y0; y < height; ++y) {
393 // Look for a set pixel in this row
394 image::Image<PixelT>::x_iterator begin = idImage->row_begin(y), end = idImage->row_end(y);
396
397 if (first != end) { // A pixel is set in this row
399 int const x0 = first - begin;
400 int const x1 = last - begin;
401 int const x_size = 1 + x1 - x0;
402
403 std::fill(first, last + 1, 0); // clear pixels; we don't want to see them again
404
405 bbox.include(lsst::geom::Point2I(x0, y)); // the LLC
406 bbox.include(lsst::geom::Point2I(x1, y)); // the LRC; initial guess for URC
407
408 // we found at least one pixel so extend the BBox upwards
409 for (++y; y < height; ++y) {
410 if (std::find(idImage->at(x0, y), idImage->at(x0, y) + x_size, 0) !=
411 idImage->at(x0, y) + x_size) {
412 break; // some pixels weren't set, so the BBox stops here, (actually in previous row)
413 }
414 std::fill(idImage->at(x0, y), idImage->at(x0, y) + x_size, 0);
415
416 bbox.include(lsst::geom::Point2I(x1, y)); // the new URC
417 }
418
419 bbox.shift(shift);
420 bboxes.push_back(bbox);
421 } else {
422 y0 = y + 1;
423 }
424 break;
425 }
426 }
427
428 return bboxes;
429}
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
int end
int y
Definition: SpanSet.cc:48
typename _view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: ImageBase.h:133
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:51
An integer coordinate rectangle.
Definition: Box.h:55
int getMinY() const noexcept
Definition: Box.h:158
int getHeight() const noexcept
Definition: Box.h:188
int getMinX() const noexcept
Definition: Box.h:157
T fill(T... args)
T find(T... args)
T push_back(T... args)

◆ makeHeavyFootprint()

template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > lsst::afw::detection::makeHeavyFootprint ( Footprint const &  foot,
lsst::afw::image::MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > const &  img,
HeavyFootprintCtrl const *  ctrl = nullptr 
)

Create a HeavyFootprint with footprint defined by the given Footprint and pixel values from the given MaskedImage.

Definition at line 148 of file HeavyFootprint.h.

151 {
153}
A set of pixels in an Image, including those pixels' actual values.

◆ mergeFootprints()

std::shared_ptr< Footprint > lsst::afw::detection::mergeFootprints ( Footprint const &  footprint1,
Footprint const &  footprint2 
)

Merges two Footprints – appends their peaks, and unions their spans, returning a new Footprint.

Region is not preserved, and is set to an empty lsst::geom::Box2I object.

Definition at line 341 of file Footprint.cc.

341 {
342 // Bail out early if the schemas are not the same
343 if (footprint1.getPeaks().getSchema() != footprint2.getPeaks().getSchema()) {
345 "Cannot merge Footprints with different Schemas");
346 }
347
348 // Merge the SpanSets
349 auto unionedSpanSet = footprint1.getSpans()->union_(*(footprint2.getSpans()));
350
351 // Construct merged Footprint
352 auto mergedFootprint = std::make_shared<Footprint>(unionedSpanSet, footprint1.getPeaks().getSchema());
353 // Copy over the peaks from both footprints
354 mergedFootprint->setPeakCatalog(PeakCatalog(footprint1.getPeaks().getTable()));
355 PeakCatalog& peaks = mergedFootprint->getPeaks();
356 peaks.reserve(footprint1.getPeaks().size() + footprint2.getPeaks().size());
357 peaks.insert(peaks.end(), footprint1.getPeaks().begin(), footprint1.getPeaks().end(), true);
358 peaks.insert(peaks.end(), footprint2.getPeaks().begin(), footprint2.getPeaks().end(), true);
359
360 // Sort the PeaksCatalog according to value
361 mergedFootprint->sortPeaks();
362
363 return mergedFootprint;
364}
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
Definition: Catalog.h:433
Reports invalid arguments.
Definition: Runtime.h:66
afw::table::CatalogT< PeakRecord > PeakCatalog
Definition: Peak.h:244

◆ mergeHeavyFootprints()

template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
std::shared_ptr< HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > > lsst::afw::detection::mergeHeavyFootprints ( HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > const &  h1,
HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > const &  h2 
)

Sum the two given HeavyFootprints h1 and h2, returning a HeavyFootprint with the union footprint, and summed pixels where they overlap.

The peak list is the union of the two inputs.

Definition at line 128 of file HeavyFootprint.cc.

130 {
131 // Merge the Footprints (by merging the Spans)
133
134 // Find the union bounding-box
136 bbox.include(h2.getBBox());
137
138 // Create union-bb-sized images and insert the heavies
141 h1.insert(im1);
142 h2.insert(im2);
143 // Add the pixels
144 im1 += im2;
145
146 // Build new HeavyFootprint from the merged spans and summed pixels.
147 return std::make_shared<HeavyFootprint<ImagePixelT, MaskPixelT, VariancePixelT>>(*foot, im1);
148}
lsst::geom::Box2I getBBox() const
Return the Footprint's bounding box.
Definition: Footprint.h:208
void insert(lsst::afw::image::MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage) const
Replace all the pixels in the image with the values in the HeavyFootprint.
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
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

◆ operator<<() [1/3]

std::ostream & lsst::afw::detection::operator<< ( std::ostream os,
Footprint const &  rhs 
)

Print a Footprint to the stream.

Parameters
osStream to print to.
rhsFootprint to print.

Definition at line 443 of file Footprint.cc.

443 {
444 os << rhs.getPeaks().size() << " peaks, area=" << rhs.getArea() << ", centroid=" << rhs.getCentroid();
445 return os;
446}
std::ostream * os
Definition: Schema.cc:557

◆ operator<<() [2/3]

std::ostream & lsst::afw::detection::operator<< ( std::ostream os,
FootprintSet const &  rhs 
)

Print a FootprintSet to the stream.

Parameters
osStream to print to.
rhsFootprintSet to print.

◆ operator<<() [3/3]

std::ostream & lsst::afw::detection::operator<< ( std::ostream os,
PeakRecord const &  record 
)

Definition at line 91 of file Peak.cc.

91 {
92 return os << (boost::format("%d: (%d,%d) (%.3f,%.3f)") % record.getId() % record.getIx() %
93 record.getIy() % record.getFx() % record.getFy());
94}
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ PYBIND11_MODULE()

lsst::afw::detection::PYBIND11_MODULE ( _detection  ,
mod   
)

Definition at line 47 of file _detection.cc.

47 {
48 WrapperCollection wrappers(mod, "lsst.afw.detection");
49 wrapPsf(wrappers);
50 wrapFootprintCtrl(wrappers);
51 wrapFootprint(wrappers);
52 wrapThreshold(wrappers);
53 wrapFootprintSet(wrappers);
54 wrapFootprintMerge(wrappers);
55 wrapPeak(wrappers);
56 wrapGaussianPsf(wrappers);
57 wrapHeavyFootprint(wrappers);
58 wrappers.finish();
59}
void wrapPsf(WrapperCollection &)
void wrapThreshold(WrapperCollection &)
void wrapFootprintCtrl(WrapperCollection &)
void wrapFootprint(WrapperCollection &)
Definition: _footprint.cc:77
void wrapGaussianPsf(WrapperCollection &)
void wrapFootprintSet(WrapperCollection &)
void wrapHeavyFootprint(WrapperCollection &)
void wrapPeak(WrapperCollection &)
void wrapFootprintMerge(WrapperCollection &)

◆ resolve_alias()

int lsst::afw::detection::resolve_alias ( const std::vector< int > &  aliases,
int  id 
)

Follow a chain of aliases, returning the final resolved value.

Definition at line 96 of file CR.cc.

97 { /* alias to look up */
98 int resolved = id; /* resolved alias */
99
100 while (id != aliases[id]) {
101 resolved = id = aliases[id];
102 }
103
104 return (resolved);
105}
int id
Definition: CR.cc:143

◆ wrapFootprint()

void lsst::afw::detection::wrapFootprint ( WrapperCollection &  wrappers)

Definition at line 77 of file _footprint.cc.

77 {
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}
Class to describe the properties of a detected object from an image.
Definition: Footprint.h:63
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...
Definition: Footprint.cc:366
lsst::afw::detection::Footprint Footprint
Definition: Source.h:57
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
Definition: python.h:87

◆ wrapFootprintCtrl() [1/2]

void lsst::afw::detection::wrapFootprintCtrl ( utils::python::WrapperCollection &  wrappers)

Definition at line 39 of file _footprintCtrl.cc.

39 {
40 wrappers.wrapType(py::class_<FootprintControl>(wrappers.module, "FootprintControl"),
41 [](auto& mod, auto& cls) {
42 cls.def(py::init<>());
43 cls.def(py::init<bool, bool>(), "circular"_a, "isotropic"_a = false);
44 cls.def(py::init<bool, bool, bool, bool>(), "left"_a, "right"_a, "up"_a, "down"_a);
45
46 cls.def("growCircular", &FootprintControl::growCircular);
47 cls.def("growIsotropic", &FootprintControl::growIsotropic);
48 cls.def("growLeft", &FootprintControl::growLeft);
49 cls.def("growRight", &FootprintControl::growRight);
50 cls.def("growUp", &FootprintControl::growUp);
51 cls.def("growDown", &FootprintControl::growDown);
52
53 cls.def("isCircular", &FootprintControl::isCircular);
54 cls.def("isIsotropic", &FootprintControl::isIsotropic);
55 cls.def("isLeft", &FootprintControl::isLeft);
56 cls.def("isRight", &FootprintControl::isRight);
57 cls.def("isUp", &FootprintControl::isUp);
58 cls.def("isDown", &FootprintControl::isDown);
59 });
60
61 auto clsHeavyFootprintCtrl = wrappers.wrapType(
62 py::class_<HeavyFootprintCtrl>(wrappers.module, "HeavyFootprintCtrl"), [](auto& mod, auto& cls) {
63 cls.def(py::init<HeavyFootprintCtrl::ModifySource>(),
64 "modifySource"_a = HeavyFootprintCtrl::ModifySource::NONE);
65
66 cls.def("getModifySource", &HeavyFootprintCtrl::getModifySource);
67 cls.def("setModifySource", &HeavyFootprintCtrl::setModifySource);
68 cls.def("getImageVal", &HeavyFootprintCtrl::getImageVal);
69 cls.def("setImageVal", &HeavyFootprintCtrl::setImageVal);
70 cls.def("getMaskVal", &HeavyFootprintCtrl::getMaskVal);
71 cls.def("setMaskVal", &HeavyFootprintCtrl::setMaskVal);
72 cls.def("getVarianceVal", &HeavyFootprintCtrl::getVarianceVal);
73 cls.def("setVarianceVal", &HeavyFootprintCtrl::setVarianceVal);
74 });
75
76 wrappers.wrapType(py::enum_<HeavyFootprintCtrl::ModifySource>(clsHeavyFootprintCtrl, "ModifySource"),
77 [](auto& mod, auto& enm) {
78 enm.value("NONE", HeavyFootprintCtrl::ModifySource::NONE);
79 enm.value("SET", HeavyFootprintCtrl::ModifySource::SET);
80 enm.export_values();
81 });
82}

◆ wrapFootprintCtrl() [2/2]

void lsst::afw::detection::wrapFootprintCtrl ( WrapperCollection &  )

◆ wrapFootprintMerge() [1/2]

void lsst::afw::detection::wrapFootprintMerge ( utils::python::WrapperCollection &  wrappers)

Definition at line 38 of file _footprintMerge.cc.

38 {
39 wrappers.addSignatureDependency("lsst.afw.table");
40
41 wrappers.wrapType(
42 py::class_<FootprintMergeList>(wrappers.module, "FootprintMergeList"), [](auto &mod, auto &cls) {
43 cls.def(py::init<afw::table::Schema &, std::vector<std::string> const &,
44 afw::table::Schema const &>(),
45 "sourceSchema"_a, "filterList"_a, "initialPeakSchema"_a);
46 cls.def(py::init<afw::table::Schema &, std::vector<std::string> const &>(), "sourceSchema"_a,
47 "filterList"_a);
48
49 cls.def("getPeakSchema", &FootprintMergeList::getPeakSchema);
50 cls.def("addCatalog", &FootprintMergeList::addCatalog, "sourceTable"_a, "inputCat"_a,
51 "filter"_a, "minNewPeakDist"_a = -1., "doMerge"_a = true, "maxSamePeakDist"_a = -1.);
52 cls.def("clearCatalog", &FootprintMergeList::clearCatalog);
53 cls.def("getFinalSources", &FootprintMergeList::getFinalSources, "outputCat"_a);
54 });
55}

◆ wrapFootprintMerge() [2/2]

void lsst::afw::detection::wrapFootprintMerge ( WrapperCollection &  )

◆ wrapFootprintSet() [1/2]

void lsst::afw::detection::wrapFootprintSet ( utils::python::WrapperCollection &  wrappers)

Definition at line 86 of file _footprintSet.cc.

86 {
87 wrappers.addSignatureDependency("lsst.afw.image");
88 wrappers.addSignatureDependency("lsst.afw.table");
89
90 wrappers.wrapType(
91 py::class_<FootprintSet, std::shared_ptr<FootprintSet>>(wrappers.module, "FootprintSet"),
92 [](auto &mod, auto &cls) {
93 declareTemplatedMembers<std::uint16_t>(cls);
94 declareTemplatedMembers<int>(cls);
95 declareTemplatedMembers<float>(cls);
96 declareTemplatedMembers<double>(cls);
97
98 cls.def(py::init<image::Mask<image::MaskPixel> const &, Threshold const &, int const>(),
99 "img"_a, "threshold"_a, "npixMin"_a = 1);
100
101 cls.def(py::init<lsst::geom::Box2I>(), "region"_a);
102 cls.def(py::init<FootprintSet const &>(), "set"_a);
103 cls.def(py::init<FootprintSet const &, int, FootprintControl const &>(), "set"_a, "rGrow"_a,
104 "ctrl"_a);
105 cls.def(py::init<FootprintSet const &, int, bool>(), "set"_a, "rGrow"_a, "isotropic"_a);
106 cls.def(py::init<FootprintSet const &, FootprintSet const &, bool>(), "footprints1"_a,
107 "footprints2"_a, "includePeaks"_a);
108
109 cls.def("swap", &FootprintSet::swap);
110 // setFootprints takes shared_ptr<FootprintList> and getFootprints returns it,
111 // but pybind11 can't handle that type, so use a custom getter and setter
112 cls.def("setFootprints", [](FootprintSet &self, FootprintSet::FootprintList footList) {
113 self.setFootprints(std::make_shared<FootprintSet::FootprintList>(std::move(footList)));
114 });
115 cls.def("getFootprints", [](FootprintSet &self) { return *(self.getFootprints()); });
116 cls.def("makeSources", &FootprintSet::makeSources);
117 cls.def("setRegion", &FootprintSet::setRegion);
118 cls.def("getRegion", &FootprintSet::getRegion);
119 cls.def("insertIntoImage", &FootprintSet::insertIntoImage);
120 cls.def("setMask", (void (FootprintSet::*)(image::Mask<lsst::afw::image::MaskPixel> *,
121 std::string const &)) &
122 FootprintSet::setMask<lsst::afw::image::MaskPixel>);
123 cls.def("setMask",
125 std::string const &)) &
126 FootprintSet::setMask<lsst::afw::image::MaskPixel>);
127 cls.def("merge", &FootprintSet::merge, "rhs"_a, "tGrow"_a = 0, "rGrow"_a = 0,
128 "isotropic"_a = true);
129 utils::python::addOutputOp(cls, "__repr__");
130 });
131}
A set of Footprints, associated with a MaskedImage.
Definition: FootprintSet.h:55
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:77

◆ wrapFootprintSet() [2/2]

void lsst::afw::detection::wrapFootprintSet ( WrapperCollection &  )

◆ wrapGaussianPsf() [1/2]

void lsst::afw::detection::wrapGaussianPsf ( utils::python::WrapperCollection &  wrappers)

Definition at line 38 of file _gaussianPsf.cc.

38 {
39 wrappers.wrapType(
40 py::class_<GaussianPsf, std::shared_ptr<GaussianPsf>, Psf>(wrappers.module, "GaussianPsf"),
41 [](auto& mod, auto& cls) {
42 table::io::python::addPersistableMethods<GaussianPsf>(cls);
43
44 cls.def(py::init<int, int, double>(), "width"_a, "height"_a, "sigma"_a);
45 cls.def(py::init<lsst::geom::Extent2I const&, double>(), "dimensions"_a, "sigma"_a);
46
47 cls.def("clone", &GaussianPsf::clone);
48 cls.def("resized", &GaussianPsf::resized, "width"_a, "height"_a);
49 cls.def("getDimensions", &GaussianPsf::getDimensions);
50 cls.def("getSigma", &GaussianPsf::getSigma);
51 cls.def("isPersistable", &GaussianPsf::isPersistable);
52 });
53}
A circularly symmetric Gaussian Psf class with no spatial variation, intended mostly for testing purp...
Definition: GaussianPsf.h:42
A polymorphic base class for representing an image's Point Spread Function.
Definition: Psf.h:76

◆ wrapGaussianPsf() [2/2]

void lsst::afw::detection::wrapGaussianPsf ( WrapperCollection &  )

◆ wrapHeavyFootprint()

void lsst::afw::detection::wrapHeavyFootprint ( WrapperCollection &  wrappers)

Definition at line 88 of file _heavyFootprint.cc.

88 {
89 wrappers.addSignatureDependency("lsst.afw.image");
90
91 declareHeavyFootprint<int>(wrappers, "I");
92 declareHeavyFootprint<std::uint16_t>(wrappers, "U");
93 declareHeavyFootprint<float>(wrappers, "F");
94 declareHeavyFootprint<double>(wrappers, "D");
95}

◆ wrapPeak() [1/2]

void lsst::afw::detection::wrapPeak ( utils::python::WrapperCollection &  wrappers)

Definition at line 101 of file _peak.cc.

101 {
102 wrappers.addInheritanceDependency("lsst.afw.table");
103
104 auto clsPeakRecord = wrappers.wrapType(PyPeakRecord(wrappers.module, "PeakRecord"),
105 [](auto &mod, auto &cls) { declarePeakRecord(cls); });
106 auto clsPeakTable = wrappers.wrapType(PyPeakTable(wrappers.module, "PeakTable"),
107 [](auto &mod, auto &cls) { declarePeakTable(cls); });
108
109 auto clsPeakColumnView = table::python::declareColumnView<PeakRecord>(wrappers, "Peak");
110 auto clsPeakCatalog = table::python::declareCatalog<PeakRecord>(wrappers, "Peak");
111
112 clsPeakRecord.attr("Table") = clsPeakTable;
113 clsPeakRecord.attr("ColumnView") = clsPeakColumnView;
114 clsPeakRecord.attr("Catalog") = clsPeakCatalog;
115 clsPeakTable.attr("Record") = clsPeakRecord;
116 clsPeakTable.attr("ColumnView") = clsPeakColumnView;
117 clsPeakTable.attr("Catalog") = clsPeakCatalog;
118 clsPeakCatalog.attr("Record") = clsPeakRecord;
119 clsPeakCatalog.attr("Table") = clsPeakTable;
120 clsPeakCatalog.attr("ColumnView") = clsPeakColumnView;
121}

◆ wrapPeak() [2/2]

void lsst::afw::detection::wrapPeak ( WrapperCollection &  )

◆ wrapPsf() [1/2]

void lsst::afw::detection::wrapPsf ( utils::python::WrapperCollection &  wrappers)

Definition at line 48 of file _psf.cc.

48 {
49 wrappers.addInheritanceDependency("lsst.afw.typehandling");
50 wrappers.addSignatureDependency("lsst.afw.geom.ellipses");
51 wrappers.addSignatureDependency("lsst.afw.image");
52 wrappers.addSignatureDependency("lsst.afw.fits");
53
54 auto clsPsf = wrappers.wrapType(
55 py::class_<Psf, PySharedPtr<Psf>, typehandling::Storable, PsfTrampoline<>>(
56 wrappers.module, "Psf"
57 ),
58 [](auto& mod, auto& cls) {
59 table::io::python::addPersistableMethods<Psf>(cls);
60 cls.def(py::init<bool, size_t>(), "isFixed"_a=false, "capacity"_a=100); // Constructor for pure-Python subclasses
61 cls.def("clone", &Psf::clone);
62 cls.def("resized", &Psf::resized, "width"_a, "height"_a);
63
64 // Position-required overloads. Can (likely) remove overload_cast<> once deprecation period for
65 // default position argument ends.
66 cls.def("computeImage",
67 py::overload_cast<lsst::geom::Point2D, image::Color, Psf::ImageOwnerEnum>(&Psf::computeImage, py::const_),
68 "position"_a,
69 "color"_a = image::Color(),
70 "owner"_a = Psf::ImageOwnerEnum::COPY
71 );
72 cls.def("computeKernelImage",
73 py::overload_cast<lsst::geom::Point2D, image::Color, Psf::ImageOwnerEnum>(&Psf::computeKernelImage, py::const_),
74 "position"_a,
75 "color"_a = image::Color(),
76 "owner"_a = Psf::ImageOwnerEnum::COPY
77 );
78 cls.def("computePeak",
79 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::computePeak, py::const_),
80 "position"_a,
81 "color"_a = image::Color()
82 );
83 cls.def("computeApertureFlux",
84 py::overload_cast<double, lsst::geom::Point2D, image::Color>(&Psf::computeApertureFlux, py::const_),
85 "radius"_a,
86 "position"_a,
87 "color"_a = image::Color()
88 );
89 cls.def("computeShape",
90 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::computeShape, py::const_),
91 "position"_a,
92 "color"_a = image::Color()
93 );
94 cls.def("computeBBox",
95 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::computeBBox, py::const_),
96 "position"_a,
97 "color"_a = image::Color()
98 );
99 cls.def("computeImageBBox",
100 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::computeImageBBox, py::const_),
101 "position"_a,
102 "color"_a = image::Color()
103 );
104 cls.def("computeKernelBBox",
105 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::computeKernelBBox, py::const_),
106 "position"_a,
107 "color"_a = image::Color()
108 );
109 cls.def("getLocalKernel",
110 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::getLocalKernel, py::const_),
111 "position"_a,
112 "color"_a = image::Color()
113 );
114
115 // Deprecated default position argument overloads.
116 cls.def("computeImage",
117 [](const Psf& psf) {
118 py::gil_scoped_acquire gil;
119 auto warnings = py::module::import("warnings");
120 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
121 warnings.attr("warn")(
122 "Default position argument overload is deprecated and will be "
123 "removed in version 24.0. Please explicitly specify a position.",
124 "category"_a=FutureWarning
125 );
126 return psf.computeImage();
127 }
128 );
129 cls.def("computeKernelImage",
130 [](const Psf& psf) {
131 py::gil_scoped_acquire gil;
132 auto warnings = py::module::import("warnings");
133 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
134 warnings.attr("warn")(
135 "Default position argument overload is deprecated and will be "
136 "removed in version 24.0. Please explicitly specify a position.",
137 "category"_a=FutureWarning
138 );
139 return psf.computeKernelImage();
140 }
141 );
142 cls.def("computePeak",
143 [](const Psf& psf) {
144 py::gil_scoped_acquire gil;
145 auto warnings = py::module::import("warnings");
146 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
147 warnings.attr("warn")(
148 "Default position argument overload is deprecated and will be "
149 "removed in version 24.0. Please explicitly specify a position.",
150 "category"_a=FutureWarning
151 );
152 return psf.computePeak();
153 }
154 );
155 cls.def("computeApertureFlux",
156 [](const Psf& psf, double radius) {
157 py::gil_scoped_acquire gil;
158 auto warnings = py::module::import("warnings");
159 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
160 warnings.attr("warn")(
161 "Default position argument overload is deprecated and will be "
162 "removed in version 24.0. Please explicitly specify a position.",
163 "category"_a=FutureWarning
164 );
165 return psf.computeApertureFlux(radius);
166 },
167 "radius"_a
168 );
169 cls.def("computeShape",
170 [](const Psf& psf) {
171 py::gil_scoped_acquire gil;
172 auto warnings = py::module::import("warnings");
173 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
174 warnings.attr("warn")(
175 "Default position argument overload is deprecated and will be "
176 "removed in version 24.0. Please explicitly specify a position.",
177 "category"_a=FutureWarning
178 );
179 return psf.computeShape();
180 }
181 );
182 cls.def("computeBBox",
183 [](const Psf& psf) {
184 py::gil_scoped_acquire gil;
185 auto warnings = py::module::import("warnings");
186 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
187 warnings.attr("warn")(
188 "Default position argument overload is deprecated and will be "
189 "removed in version 24.0. Please explicitly specify a position.",
190 "category"_a=FutureWarning
191 );
192 return psf.computeBBox();
193 }
194 );
195 cls.def("computeImageBBox",
196 [](const Psf& psf) {
197 py::gil_scoped_acquire gil;
198 auto warnings = py::module::import("warnings");
199 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
200 warnings.attr("warn")(
201 "Default position argument overload is deprecated and will be "
202 "removed in version 24.0. Please explicitly specify a position.",
203 "category"_a=FutureWarning
204 );
205 return psf.computeImageBBox();
206 }
207 );
208 cls.def("computeKernelBBox",
209 [](const Psf& psf) {
210 py::gil_scoped_acquire gil;
211 auto warnings = py::module::import("warnings");
212 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
213 warnings.attr("warn")(
214 "Default position argument overload is deprecated and will be "
215 "removed in version 24.0. Please explicitly specify a position.",
216 "category"_a=FutureWarning
217 );
218 return psf.computeKernelBBox();
219 }
220 );
221 cls.def("getLocalKernel",
222 [](const Psf& psf) {
223 py::gil_scoped_acquire gil;
224 auto warnings = py::module::import("warnings");
225 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
226 warnings.attr("warn")(
227 "Default position argument overload is deprecated and will be "
228 "removed in version 24.0. Please explicitly specify a position.",
229 "category"_a=FutureWarning
230 );
231 return psf.getLocalKernel();
232 }
233 );
234 // End deprecated default position argument overloads.
235
236 cls.def("getAverageColor", &Psf::getAverageColor);
237 cls.def("getAveragePosition", &Psf::getAveragePosition);
238 cls.def_static("recenterKernelImage", &Psf::recenterKernelImage, "im"_a, "position"_a,
239 "warpAlgorithm"_a = "lanczos5", "warpBuffer"_a = 5);
240 cls.def("getCacheCapacity", &Psf::getCacheCapacity);
241 cls.def("setCacheCapacity", &Psf::setCacheCapacity);
242 }
243 );
244
245 wrappers.wrapType(py::enum_<Psf::ImageOwnerEnum>(clsPsf, "ImageOwnerEnum"), [](auto& mod, auto& enm) {
246 enm.value("COPY", Psf::ImageOwnerEnum::COPY);
247 enm.value("INTERNAL", Psf::ImageOwnerEnum::INTERNAL);
248 enm.export_values();
249 });
250}
"Trampoline" for Psf to let it be used as a base class in Python.
Definition: python.h:50
Interface supporting iteration over heterogenous containers.
Definition: Storable.h:58
Key< int > psf
Definition: Exposure.cc:65

◆ wrapPsf() [2/2]

void lsst::afw::detection::wrapPsf ( WrapperCollection &  )

◆ wrapThreshold() [1/2]

void lsst::afw::detection::wrapThreshold ( utils::python::WrapperCollection &  wrappers)

Definition at line 41 of file _threshold.cc.

41 {
42 auto clsThreshold = wrappers.wrapType(
43 py::class_<Threshold, std::shared_ptr<Threshold>>(wrappers.module, "Threshold"),
44 [](auto& mod, auto& cls) {
45 cls.def(py::init<double const, typename Threshold::ThresholdType const, bool const,
46 double const>(),
47 "value"_a, "type"_a = Threshold::VALUE, "polarity"_a = true,
48 "includeMultiplier"_a = 1.0);
49
50 cls.def("getType", &Threshold::getType);
51 cls.def_static("parseTypeString", Threshold::parseTypeString);
52 cls.def_static("getTypeString", Threshold::getTypeString);
53 cls.def("getValue", (double (Threshold::*)(const double) const) & Threshold::getValue,
54 "param"_a = -1);
55 //
56 // template<typename ImageT>
57 // double getValue(ImageT const& image) const;
58 //
59 cls.def("getPolarity", &Threshold::getPolarity);
60 cls.def("setPolarity", &Threshold::setPolarity);
61 cls.def("getIncludeMultiplier", &Threshold::getIncludeMultiplier);
62 cls.def("setIncludeMultiplier", &Threshold::setIncludeMultiplier);
63 // Different str/repr so that the latter can be used to create a Threshold.
64 cls.def("__str__", [](Threshold const& self) {
65 std::ostringstream os;
66 std::string polarity = (self.getPolarity() == true) ? "positive" : "negative";
67 os << py::cast(self.getType()).attr("name").cast<std::string>() << std::setprecision(8)
68 << " value=" << self.getValue() << " (" << polarity << ")";
69 if (self.getIncludeMultiplier() != 1.0) {
70 os << " multiplier=" << self.getIncludeMultiplier();
71 }
72 return os.str();
73 });
74 cls.def("__repr__", [](Threshold const& self) {
76 os << std::setprecision(16) << "Threshold(value=" << self.getValue()
77 << ", type=" << py::cast(self.getType()).attr("name").cast<std::string>()
78 << ", polarity=" << self.getPolarity()
79 << ", includeMultiplier=" << self.getIncludeMultiplier() << ")";
80 return os.str();
81 });
82 });
83
84 wrappers.wrapType(py::enum_<Threshold::ThresholdType>(clsThreshold, "ThresholdType"),
85 [](auto& mod, auto& enm) {
86 enm.value("VALUE", Threshold::ThresholdType::VALUE);
87 enm.value("BITMASK", Threshold::ThresholdType::BITMASK);
88 enm.value("STDEV", Threshold::ThresholdType::STDEV);
89 enm.value("VARIANCE", Threshold::ThresholdType::VARIANCE);
90 enm.value("PIXEL_STDEV", Threshold::ThresholdType::PIXEL_STDEV);
91 enm.export_values();
92 });
93
94 wrappers.wrap([](auto& mod) {
95 mod.def("createThreshold", createThreshold, "value"_a, "type"_a = "value", "polarity"_a = true);
96 });
97}
Threshold createThreshold(const double value, const std::string type="value", const bool polarity=true)
Factory method for creating Threshold objects.
Definition: Threshold.cc:109
@ STDEV
estimate sample standard deviation
Definition: Statistics.h:67
@ VARIANCE
estimate sample variance
Definition: Statistics.h:68
T setprecision(T... args)

◆ wrapThreshold() [2/2]

void lsst::afw::detection::wrapThreshold ( WrapperCollection &  )