LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
lsst::afw::detection::Footprint Class Reference

Class to describe the properties of a detected object from an image. More...

#include <Footprint.h>

Inheritance diagram for lsst::afw::detection::Footprint:
lsst::afw::table::io::PersistableFacade< lsst::afw::detection::Footprint > lsst::afw::table::io::Persistable lsst::afw::detection::HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT >

Public Member Functions

 Footprint (std::shared_ptr< geom::SpanSet > inputSpans, lsst::geom::Box2I const &region=lsst::geom::Box2I())
 Constructor for Footprint object. More...
 
 Footprint (std::shared_ptr< geom::SpanSet > inputSpans, afw::table::Schema const &peakSchema, lsst::geom::Box2I const &region=lsst::geom::Box2I())
 Constructor for the Footprint object. More...
 
 Footprint ()
 Constructor of a empty Footprint object. More...
 
 Footprint (Footprint const &other)=default
 
 Footprint (Footprint &&)=default
 
Footprintoperator= (Footprint const &other)=default
 
Footprintoperator= (Footprint &&)=default
 
 ~Footprint () override=default
 
virtual bool isHeavy () const
 Indicates if this object is a HeavyFootprint. More...
 
std::shared_ptr< geom::SpanSet > getSpans () const
 Return a shared pointer to the SpanSet. More...
 
void setSpans (std::shared_ptr< geom::SpanSet > otherSpanSet)
 Sets the shared pointer to the SpanSet in the Footprint. More...
 
PeakCataloggetPeaks ()
 Return the Peaks contained in this Footprint. More...
 
const PeakCataloggetPeaks () const
 
std::shared_ptr< PeakRecordaddPeak (float fx, float fy, float value)
 Convenience function to add a peak. More...
 
void sortPeaks (afw::table::Key< float > const &key=afw::table::Key< float >())
 Sort Peaks from most positive value to most negative. More...
 
void setPeakSchema (afw::table::Schema const &peakSchema)
 Set the Schema used by the PeakCatalog (will throw if PeakCatalog is not empty). More...
 
void setPeakCatalog (PeakCatalog const &otherPeaks)
 Set the peakCatalog to a copy of the supplied catalog. More...
 
std::size_t getArea () const
 Return the number of pixels in this Footprint. More...
 
lsst::geom::Point2D getCentroid () const
 Return the Footprint's centroid. More...
 
geom::ellipses::Quadrupole getShape () const
 Return the Footprint's shape (interpreted as an ellipse) More...
 
void shift (int dx, int dy)
 Shift a Footprint by (dx, dy) More...
 
void shift (lsst::geom::ExtentI const &d)
 Shift a Footprint by a given extent. More...
 
lsst::geom::Box2I getBBox () const
 Return the Footprint's bounding box. More...
 
lsst::geom::Box2I getRegion () const
 Return the corners of the MaskedImage the footprints live in. More...
 
void setRegion (lsst::geom::Box2I const &region)
 Set the corners of the MaskedImage wherein the footprints dwell. More...
 
void clipTo (lsst::geom::Box2I const &bbox)
 Clip the Footprint such that all values lie inside the supplied Bounding Box. More...
 
bool contains (lsst::geom::Point2I const &pix) const
 Tests if a pixel postion falls inside the Footprint. More...
 
std::shared_ptr< Footprinttransform (std::shared_ptr< geom::SkyWcs > source, std::shared_ptr< geom::SkyWcs > target, lsst::geom::Box2I const &region, bool doClip=true) const
 Transform the footprint from one WCS to another. More...
 
std::shared_ptr< Footprinttransform (lsst::geom::LinearTransform const &t, lsst::geom::Box2I const &region, bool doClip=true) const
 Return a new Footprint whose pixels are the product of applying the specified transformation. More...
 
std::shared_ptr< Footprinttransform (lsst::geom::AffineTransform const &t, lsst::geom::Box2I const &region, bool doClip=true) const
 Return a new Footprint whose pixels are the product of applying the specified transformation. More...
 
std::shared_ptr< Footprinttransform (geom::TransformPoint2ToPoint2 const &t, lsst::geom::Box2I const &region, bool doClip=true) const
 Return a new Footprint whose pixels are the product of applying the specified transformation. More...
 
bool isPersistable () const noexcept override
 Report if this object is persistable. More...
 
void dilate (int r, geom::Stencil s=geom::Stencil::CIRCLE)
 Dilate the Footprint with a defined kernel. More...
 
void dilate (geom::SpanSet const &other)
 Dilate the Footprint with a defined kernel. More...
 
void erode (int r, geom::Stencil s=geom::Stencil::CIRCLE)
 Erode the Footprint with a defined kernel. More...
 
void erode (geom::SpanSet const &other)
 Erode the Footprint with a defined kernel. More...
 
void removeOrphanPeaks ()
 Remove peaks from the PeakCatalog that fall outside the area of the Footprint. More...
 
bool isContiguous () const
 Reports if the Footprint is simply connected or has multiple components. More...
 
std::vector< std::shared_ptr< Footprint > > split () const
 Split a multi-component Footprint into a vector of contiguous Footprints. More...
 
bool operator== (Footprint const &other) const
 equality operator More...
 
void writeFits (std::string const &fileName, std::string const &mode="w") const
 Write the object to a regular FITS file. More...
 
void writeFits (fits::MemFileManager &manager, std::string const &mode="w") const
 Write the object to a FITS image in memory. More...
 
void writeFits (fits::Fits &fitsfile) const
 Write the object to an already-open FITS object. More...
 

Static Public Member Functions

static std::shared_ptr< lsst::afw::detection::FootprintreadFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object. More...
 
static std::shared_ptr< lsst::afw::detection::FootprintreadFits (std::string const &fileName, int hdu=fits::DEFAULT_HDU)
 Read an object from a regular FITS file. More...
 
static std::shared_ptr< lsst::afw::detection::FootprintreadFits (fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
 Read an object from a FITS file in memory. More...
 
static std::shared_ptr< lsst::afw::detection::FootprintdynamicCast (std::shared_ptr< Persistable > const &ptr)
 Dynamically cast a shared_ptr. More...
 

Protected Types

using OutputArchiveHandle = io::OutputArchiveHandle
 

Protected Member Functions

std::string getPersistenceName () const override
 Return the name correspoinging ot the persistence type. More...
 
std::string getPythonModule () const override
 Return the python module the object will live in. More...
 
void write (OutputArchiveHandle &handle) const override
 Write an instance of a Footprint to an output Archive. More...
 

Static Protected Member Functions

static std::unique_ptr< FootprintreadSpanSet (afw::table::BaseCatalog const &, afw::table::io::InputArchive const &)
 Static method used to unpersist the SpanSet member of the Footprint class. More...
 
static void readPeaks (afw::table::BaseCatalog const &, Footprint &)
 Static method used to unpersist the PeakCatalog member of the Footprint class. More...
 

Friends

class FootprintFactory
 
class FootprintMerge
 

Detailed Description

Class to describe the properties of a detected object from an image.

A Footprint is designed to be constructed with information about a detected object in an image. Internally a Footprint holds a SpanSet which is used to describe the location of the object in the image (the x, y pixel locations which are considered part of the object). In addition a Footprint contains a PeakCatalog which is used to store the location and intensity of peaks in the detection.

Definition at line 62 of file Footprint.h.

Member Typedef Documentation

◆ OutputArchiveHandle

using lsst::afw::table::io::Persistable::OutputArchiveHandle = io::OutputArchiveHandle
protectedinherited

Definition at line 108 of file Persistable.h.

Constructor & Destructor Documentation

◆ Footprint() [1/5]

lsst::afw::detection::Footprint::Footprint ( std::shared_ptr< geom::SpanSet >  inputSpans,
lsst::geom::Box2I const &  region = lsst::geom::Box2I() 
)
explicit

Constructor for Footprint object.

Parameters
inputSpansShared pointer to a SpanSet defining the pixels included in the Footprint.
regionBounding box of the image in which the Footprint was created, defaults to empty box.

Definition at line 38 of file Footprint.cc.

39  : _spans(inputSpans), _peaks(PeakTable::makeMinimalSchema()), _region(region) {}
static afw::table::Schema makeMinimalSchema()
Return a minimal schema for Peak tables and records.
Definition: Peak.h:137

◆ Footprint() [2/5]

lsst::afw::detection::Footprint::Footprint ( std::shared_ptr< geom::SpanSet >  inputSpans,
afw::table::Schema const &  peakSchema,
lsst::geom::Box2I const &  region = lsst::geom::Box2I() 
)
explicit

Constructor for the Footprint object.

Parameters
inputSpansShared pointer to a SpanSet defining the pixels included in the Footprint.
peakSchemaschema to be used in the PeakCatalog
regionBounding box of the image in which the Footprint was created, defaults to empty box.

Definition at line 41 of file Footprint.cc.

43  : _spans(inputSpans), _peaks(peakSchema), _region(region) {}

◆ Footprint() [3/5]

lsst::afw::detection::Footprint::Footprint ( )
inlineexplicit

Constructor of a empty Footprint object.

Definition at line 96 of file Footprint.h.

97  : _spans(std::make_shared<geom::SpanSet>()),
99  _region(lsst::geom::Box2I()) {}
An integer coordinate rectangle.
Definition: Box.h:55

◆ Footprint() [4/5]

lsst::afw::detection::Footprint::Footprint ( Footprint const &  other)
default

◆ Footprint() [5/5]

lsst::afw::detection::Footprint::Footprint ( Footprint &&  )
default

◆ ~Footprint()

lsst::afw::detection::Footprint::~Footprint ( )
overridedefault

Member Function Documentation

◆ addPeak()

std::shared_ptr< PeakRecord > lsst::afw::detection::Footprint::addPeak ( float  fx,
float  fy,
float  value 
)

Convenience function to add a peak.

Parameters
fxFloat containing the x position of a peak
fyFloat containing the y position of a peak
valueThe intensity value of the peak

Definition at line 47 of file Footprint.cc.

47  {
49  p->setIx(fx);
50  p->setIy(fy);
51  p->setFx(fx);
52  p->setFy(fy);
53  p->setPeakValue(height);
54  return p;
55 }
PeakCatalog & getPeaks()
Return the Peaks contained in this Footprint.
Definition: Footprint.h:129
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
Definition: Catalog.h:490

◆ clipTo()

void lsst::afw::detection::Footprint::clipTo ( lsst::geom::Box2I const &  bbox)

Clip the Footprint such that all values lie inside the supplied Bounding Box.

Parameters
bboxInteger box object that defines the boundaries the footprint should be clipped to.

Definition at line 74 of file Footprint.cc.

74  {
75  setSpans(getSpans()->clippedTo(box));
77 }
std::shared_ptr< geom::SpanSet > getSpans() const
Return a shared pointer to the SpanSet.
Definition: Footprint.h:115
void removeOrphanPeaks()
Remove peaks from the PeakCatalog that fall outside the area of the Footprint.
Definition: Footprint.cc:136
void setSpans(std::shared_ptr< geom::SpanSet > otherSpanSet)
Sets the shared pointer to the SpanSet in the Footprint.
Definition: Footprint.cc:45

◆ contains()

bool lsst::afw::detection::Footprint::contains ( lsst::geom::Point2I const &  pix) const

Tests if a pixel postion falls inside the Footprint.

Parameters
pixInteger point object defining the position of a pixel to test

Definition at line 79 of file Footprint.cc.

79 { return getSpans()->contains(pix); }

◆ dilate() [1/2]

void lsst::afw::detection::Footprint::dilate ( geom::SpanSet const &  other)

Dilate the Footprint with a defined kernel.

This function enlarges the SpanSet which defines the area of the Footprint by an amount governed by the input kernel

Parameters
otherSpanSet to use as the kernel in dilation

Definition at line 124 of file Footprint.cc.

124 { setSpans(getSpans()->dilated(other)); }

◆ dilate() [2/2]

void lsst::afw::detection::Footprint::dilate ( int  r,
geom::Stencil  s = geom::Stencil::CIRCLE 
)

Dilate the Footprint with a defined kernel.

This function enlarges the SpanSet which defines the area of the Footprint by an amount governed by in input kernel

Parameters
rThe radius of the stencil object used to create a dilation kernel
sThe stencil object used to create the dilation kernel

Definition at line 122 of file Footprint.cc.

122 { setSpans(getSpans()->dilated(r, s)); }

◆ dynamicCast()

Dynamically cast a shared_ptr.

Dynamically cast a shared pointer and raise on failure.

You must provide an explicit template instantiation in the .cc file for each class that inherits from PersistableFacade. Designed to work around RTTI issues on macOS with hidden symbols;

Exceptions
lsst::pex::exceptions::LogicErrorif the cast fails

param[in] ptr The pointer to be cast.

Returns
The cast pointer.
Exceptions
lsst::pex::exceptions::TypeErrorIf the dynamic cast fails.

Definition at line 218 of file Persistable.cc.

18  {
19  auto result = std::dynamic_pointer_cast<T>(ptr);
20  if (!result) {
21  throw LSST_EXCEPT(pex::exceptions::TypeError, "Dynamic pointer cast failed");
22  }
23  return result;
24 }
py::object result
Definition: _schema.cc:429
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
uint64_t * ptr
Definition: RangeSet.cc:88

◆ erode() [1/2]

void lsst::afw::detection::Footprint::erode ( geom::SpanSet const &  other)

Erode the Footprint with a defined kernel.

This function reduces the size of the SpanSet which defines the area of the Footprint by an amount governed by the input kernel

Parameters
otherSpanSet to use as the kernel in erosion

Definition at line 131 of file Footprint.cc.

131  {
132  setSpans(getSpans()->eroded(other));
134 }

◆ erode() [2/2]

void lsst::afw::detection::Footprint::erode ( int  r,
geom::Stencil  s = geom::Stencil::CIRCLE 
)

Erode the Footprint with a defined kernel.

This function reduces the size of the SpanSet which defines the area of the Footprint by an amount governed by the input kernel

Parameters
rThe radius of the stencil object used to create a erosion kernel
sThe stencil object used to create the erosion kernel

Definition at line 126 of file Footprint.cc.

126  {
127  setSpans(getSpans()->eroded(r, s));
129 }

◆ getArea()

std::size_t lsst::afw::detection::Footprint::getArea ( ) const
inline

Return the number of pixels in this Footprint.

This function returns the real number of pixels, not the area of the bbox.

Definition at line 173 of file Footprint.h.

173 { return _spans->getArea(); }

◆ getBBox()

lsst::geom::Box2I lsst::afw::detection::Footprint::getBBox ( ) const
inline

Return the Footprint's bounding box.

Definition at line 208 of file Footprint.h.

208 { return _spans->getBBox(); }

◆ getCentroid()

lsst::geom::Point2D lsst::afw::detection::Footprint::getCentroid ( ) const
inline

Return the Footprint's centroid.

The centroid is calculated as the mean of the pixel centers

Definition at line 180 of file Footprint.h.

180 { return _spans->computeCentroid(); }

◆ getPeaks() [1/2]

PeakCatalog& lsst::afw::detection::Footprint::getPeaks ( )
inline

Return the Peaks contained in this Footprint.

The peaks should be ordered by decreasing pixel intensity at the peak position (so the most negative peak appears last). Users that add new Peaks manually are responsible for maintaining this sorting.

Definition at line 129 of file Footprint.h.

129 { return _peaks; }

◆ getPeaks() [2/2]

const PeakCatalog& lsst::afw::detection::Footprint::getPeaks ( ) const
inline

Definition at line 130 of file Footprint.h.

130 { return _peaks; }

◆ getPersistenceName()

std::string lsst::afw::detection::Footprint::getPersistenceName ( ) const
overrideprotectedvirtual

Return the name correspoinging ot the persistence type.

Reimplemented from lsst::afw::table::io::Persistable.

Reimplemented in lsst::afw::detection::HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT >.

Definition at line 255 of file Footprint.cc.

255 { return getFootprintPersistenceName(); }

◆ getPythonModule()

std::string lsst::afw::detection::Footprint::getPythonModule ( ) const
inlineoverrideprotectedvirtual

Return the python module the object will live in.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 362 of file Footprint.h.

362 { return "lsst.afw.detection"; }

◆ getRegion()

lsst::geom::Box2I lsst::afw::detection::Footprint::getRegion ( ) const
inline

Return the corners of the MaskedImage the footprints live in.

Definition at line 213 of file Footprint.h.

213 { return _region; }

◆ getShape()

geom::ellipses::Quadrupole lsst::afw::detection::Footprint::getShape ( ) const
inline

Return the Footprint's shape (interpreted as an ellipse)

The shape is determined by measuring the moments of the pixel centers about its centroid (cf. getCentroid)

Definition at line 188 of file Footprint.h.

188 { return _spans->computeShape(); }

◆ getSpans()

std::shared_ptr<geom::SpanSet> lsst::afw::detection::Footprint::getSpans ( ) const
inline

Return a shared pointer to the SpanSet.

Definition at line 115 of file Footprint.h.

115 { return _spans; }

◆ isContiguous()

bool lsst::afw::detection::Footprint::isContiguous ( ) const
inline

Reports if the Footprint is simply connected or has multiple components.

Definition at line 335 of file Footprint.h.

335 { return getSpans()->isContiguous(); };

◆ isHeavy()

virtual bool lsst::afw::detection::Footprint::isHeavy ( ) const
inlinevirtual

Indicates if this object is a HeavyFootprint.

Reimplemented in lsst::afw::detection::HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT >.

Definition at line 111 of file Footprint.h.

111 { return false; }

◆ isPersistable()

bool lsst::afw::detection::Footprint::isPersistable ( ) const
inlineoverridevirtualnoexcept

Report if this object is persistable.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 283 of file Footprint.h.

283 { return true; }

◆ operator=() [1/2]

Footprint& lsst::afw::detection::Footprint::operator= ( Footprint &&  )
default

◆ operator=() [2/2]

Footprint& lsst::afw::detection::Footprint::operator= ( Footprint const &  other)
default

◆ operator==()

bool lsst::afw::detection::Footprint::operator== ( Footprint const &  other) const

equality operator

Parameters
otherThe Footprint for which equality will be computed

Definition at line 162 of file Footprint.cc.

162  {
163  /* If the peakCatalogs are not the same length the Footprints can't be equal */
164  if (getPeaks().size() != other.getPeaks().size()) {
165  return false;
166  }
167  /* Check that for every peak in the PeakCatalog there is a corresponding peak
168  * in the other, and if not return false
169  */
170  for (auto const& selfPeak : getPeaks()) {
171  bool match = false;
172  for (auto const& otherPeak : other.getPeaks()) {
173  if (selfPeak.getI() == otherPeak.getI() && selfPeak.getF() == otherPeak.getF() &&
174  selfPeak.getPeakValue() == otherPeak.getPeakValue()) {
175  match = true;
176  break;
177  }
178  }
179  if (!match) {
180  return false;
181  }
182  }
183  /* At this point the PeakCatalogs have evaluated true, compare the SpanSets
184  */
185  return *(getSpans()) == *(other.getSpans());
186 }
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:413

◆ readFits() [1/3]

Read an object from an already open FITS object.

Parameters
[in]fitsfileFITS object to read from, already positioned at the desired HDU.

Definition at line 183 of file Persistable.h.

183  {
184  return dynamicCast(Persistable::_readFits(fitsfile));
185  }
static std::shared_ptr< lsst::afw::detection::Footprint > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
Definition: Persistable.cc:18

◆ readFits() [2/3]

static std::shared_ptr<lsst::afw::detection::Footprint > lsst::afw::table::io::PersistableFacade< lsst::afw::detection::Footprint >::readFits ( fits::MemFileManager manager,
int  hdu = fits::DEFAULT_HDU 
)
inlinestaticinherited

Read an object from a FITS file in memory.

Parameters
[in]managerManager for the memory to read from.
[in]hduHDU to read, where 0 is the primary. The special value of afw::fits::DEFAULT_HDU skips the primary HDU if it is empty.

Definition at line 205 of file Persistable.h.

205  {
206  return dynamicCast(Persistable::_readFits(manager, hdu));
207  }

◆ readFits() [3/3]

static std::shared_ptr<lsst::afw::detection::Footprint > lsst::afw::table::io::PersistableFacade< lsst::afw::detection::Footprint >::readFits ( std::string const &  fileName,
int  hdu = fits::DEFAULT_HDU 
)
inlinestaticinherited

Read an object from a regular FITS file.

Parameters
[in]fileNameName of the file to read.
[in]hduHDU to read, where 0 is the primary. The special value of afw::fits::DEFAULT_HDU skips the primary HDU if it is empty.

Definition at line 194 of file Persistable.h.

194  {
195  return dynamicCast(Persistable::_readFits(fileName, hdu));
196  }

◆ readPeaks()

void lsst::afw::detection::Footprint::readPeaks ( afw::table::BaseCatalog const &  peakCat,
Footprint loadedFootprint 
)
staticprotected

Static method used to unpersist the PeakCatalog member of the Footprint class.

Definition at line 296 of file Footprint.cc.

296  {
297  using namespace std::string_literals;
298  if (!peakCat.getSchema().contains(PeakTable::makeMinimalSchema())) {
299  // need to handle an older form of Peak persistence for backwards compatibility
300  afw::table::SchemaMapper mapper(peakCat.getSchema());
301  mapper.addMinimalSchema(PeakTable::makeMinimalSchema());
302  afw::table::Key<float> oldX = peakCat.getSchema()["x"];
303  afw::table::Key<float> oldY = peakCat.getSchema()["y"];
304  afw::table::Key<float> oldPeakValue = peakCat.getSchema()["value"];
305  mapper.addMapping(oldX, "f.x"s);
306  mapper.addMapping(oldY, "f.y"s);
307  mapper.addMapping(oldPeakValue, "peakValue"s);
308  loadedFootprint.setPeakSchema(mapper.getOutputSchema());
309  auto peaks = loadedFootprint.getPeaks();
310  peaks.reserve(peakCat.size());
311  for (auto const& peak : peakCat) {
312  auto newPeak = peaks.addNew();
313  newPeak->assign(peak, mapper);
314  newPeak->setIx(static_cast<int>(newPeak->getFx()));
315  newPeak->setIy(static_cast<int>(newPeak->getFy()));
316  }
317  return;
318  }
319  loadedFootprint.setPeakSchema(peakCat.getSchema());
320  auto& peaks = loadedFootprint.getPeaks();
321  peaks.reserve(peakCat.size());
322  for (auto const& peak : peakCat) {
323  peaks.addNew()->assign(peak);
324  }
325 }
SchemaMapper * mapper
Definition: SchemaMapper.cc:71

◆ readSpanSet()

std::unique_ptr< Footprint > lsst::afw::detection::Footprint::readSpanSet ( afw::table::BaseCatalog const &  catalog,
afw::table::io::InputArchive const &  archive 
)
staticprotected

Static method used to unpersist the SpanSet member of the Footprint class.

Definition at line 272 of file Footprint.cc.

273  {
274  int fieldCount = catalog.getSchema().getFieldCount();
275  LSST_ARCHIVE_ASSERT(fieldCount == 1 || fieldCount == 3);
276  std::shared_ptr<geom::SpanSet> loadedSpanSet;
277  if (fieldCount == 1) {
278  // This is a new style footprint with a SpanSet as a member, treat accordingly
279  auto const schemaAndKey = spanSetPersistenceHelper();
280  int persistedSpanSetId = catalog.front().get(schemaAndKey.second);
281  loadedSpanSet = std::dynamic_pointer_cast<geom::SpanSet>(archive.get(persistedSpanSetId));
282  } else {
283  // This block is for an old style footprint load.
284  auto const& keys = LegacyFootprintPersistenceHelper::get();
285  std::vector<geom::Span> tempVec;
286  tempVec.reserve(catalog.size());
287  for (auto const& val : catalog) {
288  tempVec.emplace_back(val.get(keys.spanY), val.get(keys.spanX0), val.get(keys.spanX1));
289  }
290  loadedSpanSet = std::make_shared<geom::SpanSet>(std::move(tempVec));
291  }
292  auto loadedFootprint = std::unique_ptr<Footprint>(new Footprint(loadedSpanSet));
293  return loadedFootprint;
294 }
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:48
Footprint()
Constructor of a empty Footprint object.
Definition: Footprint.h:96
T emplace_back(T... args)
T move(T... args)
T reserve(T... args)
ImageT val
Definition: CR.cc:146

◆ removeOrphanPeaks()

void lsst::afw::detection::Footprint::removeOrphanPeaks ( )

Remove peaks from the PeakCatalog that fall outside the area of the Footprint.

Definition at line 136 of file Footprint.cc.

136  {
137  for (auto iter = getPeaks().begin(); iter != getPeaks().end(); ++iter) {
138  if (!getSpans()->contains(lsst::geom::Point2I(iter->getIx(), iter->getIy()))) {
139  iter = getPeaks().erase(iter);
140  --iter;
141  }
142  }
143 }
T begin(T... args)
iterator erase(iterator pos)
Erase the record pointed to by pos, and return an iterator the next record.
Definition: Catalog.h:565

◆ setPeakCatalog()

void lsst::afw::detection::Footprint::setPeakCatalog ( PeakCatalog const &  otherPeaks)

Set the peakCatalog to a copy of the supplied catalog.

PeakCatalog will be copied into the Footprint, but a PeakCatalog is a shallow copy, so records will not be duplicated. This function will throw an error if the PeakCatalog of *this is not empty.

Parameters
otherPeaksThe PeakCatalog to copy

Definition at line 421 of file Footprint.cc.

421  {
422  if (!getPeaks().empty()) {
423  throw LSST_EXCEPT(pex::exceptions::LogicError, "Cannot change the PeakCatalog unless it is empty");
424  }
425  // this syntax doesn't work in Python, which is why this method has to exist
426  getPeaks() = otherPeaks;
427 }

◆ setPeakSchema()

void lsst::afw::detection::Footprint::setPeakSchema ( afw::table::Schema const &  peakSchema)

Set the Schema used by the PeakCatalog (will throw if PeakCatalog is not empty).

Parameters
peakSchemaThe schema to use in the PeakCatalog
Exceptions
pex::exceptions::LogicErrorThrown if if the PeakCatalog is not empty

Definition at line 417 of file Footprint.cc.

417  {
418  setPeakCatalog(PeakCatalog(peakSchema));
419 }
void setPeakCatalog(PeakCatalog const &otherPeaks)
Set the peakCatalog to a copy of the supplied catalog.
Definition: Footprint.cc:421
afw::table::CatalogT< PeakRecord > PeakCatalog
Definition: Peak.h:244

◆ setRegion()

void lsst::afw::detection::Footprint::setRegion ( lsst::geom::Box2I const &  region)
inline

Set the corners of the MaskedImage wherein the footprints dwell.

Parameters
regionA box describing the corners of the Image the Footprint derives from

Definition at line 220 of file Footprint.h.

220 { _region = region; }

◆ setSpans()

void lsst::afw::detection::Footprint::setSpans ( std::shared_ptr< geom::SpanSet >  otherSpanSet)

Sets the shared pointer to the SpanSet in the Footprint.

Parameters
otherSpanSetShared pointer to a SpanSet

Definition at line 45 of file Footprint.cc.

45 { _spans = otherSpanSet; }

◆ shift() [1/2]

void lsst::afw::detection::Footprint::shift ( int  dx,
int  dy 
)

Shift a Footprint by (dx, dy)

Parameters
dxHow much to move Footprint in column direction
dyHow much to move in row direction

Definition at line 64 of file Footprint.cc.

64  {
65  setSpans(getSpans()->shiftedBy(dx, dy));
66  for (auto& peak : getPeaks()) {
67  peak.setIx(peak.getIx() + dx);
68  peak.setIy(peak.getIy() + dy);
69  peak.setFx(peak.getFx() + dx);
70  peak.setFy(peak.getFy() + dy);
71  }
72 }

◆ shift() [2/2]

void lsst::afw::detection::Footprint::shift ( lsst::geom::ExtentI const &  d)
inline

Shift a Footprint by a given extent.

Parameters
dExtentI object which gives the dimensions the Footprint should be shifted

Definition at line 203 of file Footprint.h.

203 { shift(d.getX(), d.getY()); }
void shift(int dx, int dy)
Shift a Footprint by (dx, dy)
Definition: Footprint.cc:64

◆ sortPeaks()

void lsst::afw::detection::Footprint::sortPeaks ( afw::table::Key< float > const &  key = afw::table::Key<float>())

Sort Peaks from most positive value to most negative.

If the key passed is invalid (the default) PeakTable::getPeakValueKey() will be used.

Parameters
keyA key corresponding to the field in the Schema the PeakCatalog is to be sorted by.

Definition at line 57 of file Footprint.cc.

57  {
58  auto validatedKey = key.isValid() ? key : PeakTable::getPeakValueKey();
59  getPeaks().sort([&validatedKey](detection::PeakRecord const& a, detection::PeakRecord const& b) {
60  return a.get(validatedKey) > b.get(validatedKey);
61  });
62 }
table::Key< int > b
table::Key< int > a
static afw::table::Key< float > getPeakValueKey()
Definition: Peak.h:169
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:756

◆ split()

std::vector< std::shared_ptr< Footprint > > lsst::afw::detection::Footprint::split ( ) const

Split a multi-component Footprint into a vector of contiguous Footprints.

Split a multi-component Footprint such that each Footprint in the output vector is contiguous and contains only peaks that can be found within the bounds of the Footprint

Definition at line 145 of file Footprint.cc.

145  {
146  auto splitSpanSets = getSpans()->split();
148  footprintList.reserve(splitSpanSets.size());
149  for (auto& spanPtr : splitSpanSets) {
150  auto tmpFootprintPointer = std::make_shared<Footprint>(spanPtr, getPeaks().getSchema(), getRegion());
151  tmpFootprintPointer->_peaks = getPeaks();
152  // No need to remove any peaks, as there is only one Footprint, so it will
153  // simply be a copy of the original
154  if (splitSpanSets.size() > 1) {
155  tmpFootprintPointer->removeOrphanPeaks();
156  }
157  footprintList.push_back(std::move(tmpFootprintPointer));
158  }
159  return footprintList;
160 }
lsst::geom::Box2I getRegion() const
Return the corners of the MaskedImage the footprints live in.
Definition: Footprint.h:213
T push_back(T... args)

◆ transform() [1/4]

std::shared_ptr< Footprint > lsst::afw::detection::Footprint::transform ( geom::TransformPoint2ToPoint2 const &  t,
lsst::geom::Box2I const &  region,
bool  doClip = true 
) const

Return a new Footprint whose pixels are the product of applying the specified transformation.

Parameters
tA 2-D transform which will be used to map the pixels
regionUsed to set the "region" box of the returned footprint; note that this is NOT the same as the footprint's bounding box.
doClipIf true, clip the new footprint to the region bbox before returning it.

Definition at line 98 of file Footprint.cc.

99  {
100  // Transfrom the SpanSet first
101  auto transformedSpan = getSpans()->transformedBy(t);
102  // Use this new SpanSet and the peakSchema to create a new Footprint
103  auto newFootprint = std::make_shared<Footprint>(transformedSpan, getPeaks().getSchema(), region);
104  // now populate the new Footprint with transformed Peaks
106  peakPosList.reserve(_peaks.size());
107  for (auto const& peak : getPeaks()) {
108  peakPosList.emplace_back(peak.getF());
109  }
110  auto newPeakPosList = t.applyForward(peakPosList);
111  auto newPeakPos = newPeakPosList.cbegin();
112  for (auto peak = getPeaks().cbegin(), endPeak = getPeaks().cend(); peak != endPeak;
113  ++peak, ++newPeakPos) {
114  newFootprint->addPeak(newPeakPos->getX(), newPeakPos->getY(), peak->getPeakValue());
115  }
116  if (doClip) {
117  newFootprint->clipTo(region);
118  }
119  return newFootprint;
120 }

◆ transform() [2/4]

std::shared_ptr< Footprint > lsst::afw::detection::Footprint::transform ( lsst::geom::AffineTransform const &  t,
lsst::geom::Box2I const &  region,
bool  doClip = true 
) const

Return a new Footprint whose pixels are the product of applying the specified transformation.

Parameters
tAn affine transform object which will be used to map the pixels
regionUsed to set the "region" box of the returned footprint; note that this is NOT the same as the footprint's bounding box.
doClipIf true, clip the new footprint to the region bbox before returning it.

Definition at line 93 of file Footprint.cc.

94  {
95  return transform(*geom::makeTransform(t), region, doClip);
96 }
std::shared_ptr< Footprint > transform(std::shared_ptr< geom::SkyWcs > source, std::shared_ptr< geom::SkyWcs > target, lsst::geom::Box2I const &region, bool doClip=true) const
Transform the footprint from one WCS to another.
Definition: Footprint.cc:81
std::shared_ptr< TransformPoint2ToPoint2 > makeTransform(lsst::geom::AffineTransform const &affine)
Wrap an lsst::geom::AffineTransform as a Transform.

◆ transform() [3/4]

std::shared_ptr< Footprint > lsst::afw::detection::Footprint::transform ( lsst::geom::LinearTransform const &  t,
lsst::geom::Box2I const &  region,
bool  doClip = true 
) const

Return a new Footprint whose pixels are the product of applying the specified transformation.

Parameters
tA linear transform object which will be used to map the pixels
regionUsed to set the "region" box of the returned footprint; note that this is NOT the same as the footprint's bounding box.
doClipIf true, clip the new footprint to the region bbox before returning it.

Definition at line 88 of file Footprint.cc.

89  {
90  return transform(lsst::geom::AffineTransform(t), region, doClip);
91 }
An affine coordinate transformation consisting of a linear transformation and an offset.

◆ transform() [4/4]

std::shared_ptr< Footprint > lsst::afw::detection::Footprint::transform ( std::shared_ptr< geom::SkyWcs >  source,
std::shared_ptr< geom::SkyWcs >  target,
lsst::geom::Box2I const &  region,
bool  doClip = true 
) const

Transform the footprint from one WCS to another.

Parameters
sourceWcs that defines the coordinate system of the input footprint.
targetWcs that defines that desired coordinate system of the returned footprint.
regionUsed to set the "region" box of the returned footprint; note that this is NOT the same as the footprint's bounding box.
doClipIf true, clip the new footprint to the region bbox before returning it.

Definition at line 81 of file Footprint.cc.

83  {
84  auto srcToTarget = geom::makeWcsPairTransform(*source, *target);
85  return transform(*srcToTarget, region, doClip);
86 }
Key< Flag > const & target
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
Definition: SkyWcs.cc:146

◆ write()

void lsst::afw::detection::Footprint::write ( OutputArchiveHandle handle) const
overrideprotectedvirtual

Write an instance of a Footprint to an output Archive.

Reimplemented from lsst::afw::table::io::Persistable.

Reimplemented in lsst::afw::detection::HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT >.

Definition at line 257 of file Footprint.cc.

257  {
258  // get the span schema and key
259  auto const keys = spanSetPersistenceHelper();
260  // create the output catalog
261  afw::table::BaseCatalog spanSetCat = handle.makeCatalog(keys.first);
262  // create a record that will hold the ID of the recursively saved SpanSet
263  auto record = spanSetCat.addNew();
264  record->set(keys.second, handle.put(getSpans()));
265  handle.saveCatalog(spanSetCat);
266  // save the peaks into a catalog
267  afw::table::BaseCatalog peakCat = handle.makeCatalog(getPeaks().getSchema());
268  peakCat.insert(peakCat.end(), getPeaks().begin(), getPeaks().end(), true);
269  handle.saveCatalog(peakCat);
270 }
int end
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:518
CatalogT< BaseRecord > BaseCatalog
Definition: fwd.h:72

◆ writeFits() [1/3]

void lsst::afw::table::io::Persistable::writeFits ( fits::Fits fitsfile) const
inherited

Write the object to an already-open FITS object.

Parameters
[in]fitsfileOpen FITS object to write to.

Definition at line 18 of file Persistable.cc.

18  {
19  OutputArchive archive;
20  archive.put(this);
21  archive.writeFits(fitsfile);
22 }

◆ writeFits() [2/3]

void lsst::afw::table::io::Persistable::writeFits ( fits::MemFileManager manager,
std::string const &  mode = "w" 
) const
inherited

Write the object to a FITS image in memory.

Parameters
[in]managerName of the file to write to.
[in]modeIf "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file.

Definition at line 29 of file Persistable.cc.

29  {
30  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
31  writeFits(fitsfile);
32 }
void writeFits(std::string const &fileName, std::string const &mode="w") const
Write the object to a regular FITS file.
Definition: Persistable.cc:24

◆ writeFits() [3/3]

void lsst::afw::table::io::Persistable::writeFits ( std::string const &  fileName,
std::string const &  mode = "w" 
) const
inherited

Write the object to a regular FITS file.

Parameters
[in]fileNameName of the file to write to.
[in]modeIf "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file.

Definition at line 24 of file Persistable.cc.

24  {
25  fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
26  writeFits(fitsfile);
27 }

Friends And Related Function Documentation

◆ FootprintFactory

friend class FootprintFactory
friend

Definition at line 369 of file Footprint.h.

◆ FootprintMerge

friend class FootprintMerge
friend

Definition at line 382 of file Footprint.h.


The documentation for this class was generated from the following files: