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 Types | Public Member Functions | Protected Attributes | List of all members
lsst::meas::base::PixelFlagsAlgorithm Class Reference

A measurement algorithm that gets mask bits from the exposure and sets flag bits to summarize which bits are set within a source's footprint. More...

#include <PixelFlags.h>

Inheritance diagram for lsst::meas::base::PixelFlagsAlgorithm:
lsst::meas::base::SimpleAlgorithm lsst::meas::base::SingleFrameAlgorithm lsst::meas::base::ForcedAlgorithm lsst::meas::base::BaseAlgorithm lsst::meas::base::BaseAlgorithm

Public Types

typedef PixelFlagsControl Control
 A typedef to the Control object for this algorithm, defined above. More...
 
typedef std::map< std::string, afw::table::Key< afw::table::Flag > > KeyMap
 

Public Member Functions

 PixelFlagsAlgorithm (Control const &ctrl, std::string const &name, afw::table::Schema &schema)
 
virtual void measure (afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
 Called to measure a single child source in an image. More...
 
virtual void fail (afw::table::SourceRecord &measRecord, MeasurementError *error=nullptr) const
 Handle an exception thrown by the current algorithm by setting flags in the given record. More...
 
virtual void measureForced (afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure, afw::table::SourceRecord const &refRecord, afw::geom::SkyWcs const &refWcs) const
 Called to measure a single child source in an image. More...
 
virtual void measureNForced (afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure, afw::table::SourceCatalog const &refRecord, afw::geom::SkyWcs const &refWcs) const
 Called to simultaneously measure all children in a deblend family, in a single image. More...
 
virtual void measureN (afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure) const
 Called to simultaneously measure all children in a deblend family, in a single image. More...
 
std::string getLogName () const
 

Protected Attributes

std::string _logName
 

Detailed Description

A measurement algorithm that gets mask bits from the exposure and sets flag bits to summarize which bits are set within a source's footprint.

Definition at line 64 of file PixelFlags.h.

Member Typedef Documentation

◆ Control

A typedef to the Control object for this algorithm, defined above.

The control object contains the configuration parameters for this algorithm.

Definition at line 68 of file PixelFlags.h.

◆ KeyMap

Definition at line 77 of file PixelFlags.h.

Constructor & Destructor Documentation

◆ PixelFlagsAlgorithm()

lsst::meas::base::PixelFlagsAlgorithm::PixelFlagsAlgorithm ( Control const &  ctrl,
std::string const &  name,
afw::table::Schema schema 
)

Definition at line 76 of file PixelFlags.cc.

78  : _ctrl(ctrl) {
79  // Add generic keys first, which don't correspond to specific mask planes
80  _generalFailureKey = schema.addField<afw::table::Flag>(
81  name + "_flag", "General failure flag, set if anything went wrong");
82  _offImageKey =
83  schema.addField<afw::table::Flag>(name + "_flag" + "_offimage", "Source center is off image");
84  // Set all the flags that correspond to mask planes anywhere in the footprint
85  _anyKeys["EDGE"] = schema.addField<afw::table::Flag>(
86  name + "_flag_edge", "Source is outside usable exposure region (masked EDGE or NO_DATA)");
87  _anyKeys["INTRP"] = schema.addField<afw::table::Flag>(name + "_flag_interpolated",
88  "Interpolated pixel in the Source footprint");
89  _anyKeys["SAT"] = schema.addField<afw::table::Flag>(name + "_flag_saturated",
90  "Saturated pixel in the Source footprint");
91  _anyKeys["CR"] =
92  schema.addField<afw::table::Flag>(name + "_flag_cr", "Cosmic ray in the Source footprint");
93  _anyKeys["BAD"] =
94  schema.addField<afw::table::Flag>(name + "_flag_bad", "Bad pixel in the Source footprint");
95  _anyKeys["SUSPECT"] = schema.addField<afw::table::Flag>(name + "_flag_suspect",
96  "Source's footprint includes suspect pixels");
97  // Flags that correspond to mask bits which occur in the center of the object
98  _centerKeys["INTRP"] = schema.addField<afw::table::Flag>(name + "_flag_interpolatedCenter",
99  "Interpolated pixel in the Source center");
100  _centerKeys["SAT"] = schema.addField<afw::table::Flag>(name + "_flag_saturatedCenter",
101  "Saturated pixel in the Source center");
102  _centerKeys["CR"] =
103  schema.addField<afw::table::Flag>(name + "_flag_crCenter", "Cosmic ray in the Source center");
104  _centerKeys["SUSPECT"] = schema.addField<afw::table::Flag>(name + "_flag_suspectCenter",
105  "Source's center is close to suspect pixels");
106 
107  // Read in the flags passed from the configuration, and add them to the schema
108  for (auto const& i : _ctrl.masksFpCenter) {
109  std::string maskName(i);
110  std::transform(maskName.begin(), maskName.end(), maskName.begin(), ::tolower);
111  _centerKeys[i] = schema.addField<afw::table::Flag>(name + "_flag_" + maskName + "Center",
112  "Source center is close to " + i + " pixels");
113  }
114 
115  for (auto const& i : _ctrl.masksFpAnywhere) {
116  std::string maskName(i);
117  std::transform(maskName.begin(), maskName.end(), maskName.begin(), ::tolower);
118  _anyKeys[i] = schema.addField<afw::table::Flag>(name + "_flag_" + maskName,
119  "Source footprint includes " + i + " pixels");
120  }
121 }
table::Key< std::string > name
Definition: Amplifier.cc:116
table::Schema schema
Definition: python.h:134
std::vector< std::string > masksFpAnywhere
"List of mask planes to be searched for which occur anywhere within a footprint. " "If any of the pla...
Definition: PixelFlags.h:51
std::vector< std::string > masksFpCenter
"List of mask planes to be searched for which occur in the center of a footprint. " "If any of the pl...
Definition: PixelFlags.h:48
T transform(T... args)

Member Function Documentation

◆ fail()

void lsst::meas::base::PixelFlagsAlgorithm::fail ( afw::table::SourceRecord measRecord,
MeasurementError error = nullptr 
) const
virtual

Handle an exception thrown by the current algorithm by setting flags in the given record.

fail() is called by the measurement framework when an exception is allowed to propagate out of one the algorithm's measure() methods. It should generally set both a general failure flag for the algorithm as well as a specific flag indicating the error condition, if possible. To aid in this, if the exception was an instance of MeasurementError, it will be passed in, carrying information about what flag to set.

An algorithm can also to chose to set flags within its own measure() methods, and then just return, rather than throw an exception. However, fail() should be implemented even when all known failure modes do not throw exceptions, to ensure that unexpected exceptions thrown in lower-level code are properly handled.

Implements lsst::meas::base::BaseAlgorithm.

Definition at line 199 of file PixelFlags.cc.

199  {
200  measRecord.set(_generalFailureKey, true);
201 }

◆ getLogName()

std::string lsst::meas::base::BaseAlgorithm::getLogName ( ) const
inlineinherited

Definition at line 66 of file Algorithm.h.

66 { return _logName; }

◆ measure()

void lsst::meas::base::PixelFlagsAlgorithm::measure ( afw::table::SourceRecord measRecord,
afw::image::Exposure< float > const &  exposure 
) const
virtual

Called to measure a single child source in an image.

Before this method is called, all neighbors will be replaced with noise, using the outputs of the deblender. Outputs should be saved in the given SourceRecord, which can also be used to obtain centroid (see SafeCentroidExtractor) and shape (see SafeShapeExtractor) information.

Implements lsst::meas::base::SingleFrameAlgorithm.

Definition at line 123 of file PixelFlags.cc.

124  {
125  MaskedImageF mimage = exposure.getMaskedImage();
126  FootprintBits<MaskedImageF> func;
127 
128  // Check if the measRecord has a valid centroid key, i.e. it was centroided
129  geom::Point2D center;
130  if (measRecord.getTable()->getCentroidSlot().getMeasKey().isValid()) {
131  center = measRecord.getCentroid();
132  // Catch NAN in centroid estimate
133  if (std::isnan(center.getX()) || std::isnan(center.getY())) {
134  throw LSST_EXCEPT(pex::exceptions::RuntimeError,
135  "Center point passed to PixelFlagsAlgorithm is NaN");
136  }
137  } else {
138  // Set the general failure flag because using the Peak might affect
139  // the current measurement
140  measRecord.set(_generalFailureKey, true);
141  // Attempting to set pixel flags with no centroider, the center will
142  // be determined though the peak pixel. The first peak in the
143  // footprint (supplied by the measurement framework) should be the
144  // highest peak so that one will be used as a proxy for the central
145  // tendency of the distribution of flux for the record.
146  std::shared_ptr<afw::detection::Footprint> footprint = measRecord.getFootprint();
147  // If there is no footprint or the footprint contains no peaks, throw
148  // a runtime error.
149  if (!footprint || footprint->getPeaks().empty()) {
150  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "No footprint, or no footprint peaks detected");
151  } else {
152  center.setX(footprint->getPeaks().front().getFx());
153  center.setY(footprint->getPeaks().front().getFy());
154  }
155  }
156 
157  // Catch centroids off the image
158  if (!mimage.getBBox().contains(geom::Point2I(center))) {
159  measRecord.set(_offImageKey, true);
160  measRecord.set(_anyKeys.at("EDGE"), true);
161  }
162 
163  // Check for bits set in the source's Footprint
164  auto footprint = measRecord.getFootprint();
165  if (!footprint) {
166  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "No footprint present.");
167  }
168  auto fullSpans = footprint->getSpans();
169  if (!fullSpans) {
170  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "No spans in footprint.");
171  }
172  fullSpans->clippedTo(mimage.getBBox())->applyFunctor(func, *(mimage.getMask()));
173 
174  // Set the EDGE flag if the bitmask has NO_DATA set
175  try {
176  if (func.getBits() & MaskedImageF::Mask::getPlaneBitMask("NO_DATA")) {
177  measRecord.set(_anyKeys.at("EDGE"), true);
178  }
179  } catch (pex::exceptions::InvalidParameterError& err) {
180  throw LSST_EXCEPT(FatalAlgorithmError, err.what());
181  }
182 
183  // update the source record for the any keys
184  updateFlags(_anyKeys, func, measRecord);
185 
186  // Check for bits set in the 3x3 box around the center
187  geom::Point2I llc(afw::image::positionToIndex(center.getX()) - 1,
188  afw::image::positionToIndex(center.getY()) - 1);
189 
190  func.reset();
191  auto spans = std::make_shared<afw::geom::SpanSet>(geom::Box2I(llc, geom::ExtentI(3)));
192  afw::detection::Footprint const middle(spans); // central 3x3
193  middle.getSpans()->clippedTo(mimage.getBBox())->applyFunctor(func, *(mimage.getMask()));
194 
195  // Update the flags which have to do with the center of the footprint
196  updateFlags(_centerKeys, func, measRecord);
197 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
T at(T... args)
An integer coordinate rectangle.
Definition: Box.h:55
T isnan(T... args)
int positionToIndex(double pos)
Convert image position to nearest integer index.
Definition: ImageUtils.h:69
lsst::afw::detection::Footprint Footprint
Definition: Source.h:57

◆ measureForced()

virtual void lsst::meas::base::SimpleAlgorithm::measureForced ( afw::table::SourceRecord measRecord,
afw::image::Exposure< float > const &  exposure,
afw::table::SourceRecord const &  refRecord,
afw::geom::SkyWcs const &  refWcs 
) const
inlinevirtualinherited

Called to measure a single child source in an image.

Before this method is called, all neighbors will be replaced with noise, using the outputs of the deblender. Outputs should be saved in the given SourceRecord, which can also be used to obtain centroid (see SafeCentroidExtractor) and shape (see SafeShapeExtractor) information.

Implements lsst::meas::base::ForcedAlgorithm.

Reimplemented in lsst::meas::extensions::photometryKron::KronFluxAlgorithm.

Definition at line 172 of file Algorithm.h.

175  {
176  measure(measRecord, exposure);
177  }
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const =0
Called to measure a single child source in an image.

◆ measureN()

void lsst::meas::base::SingleFrameAlgorithm::measureN ( afw::table::SourceCatalog const &  measCat,
afw::image::Exposure< float > const &  exposure 
) const
virtualinherited

Called to simultaneously measure all children in a deblend family, in a single image.

Outputs should be saved in the given SourceCatalog, which can also be used to obtain centroid (see SafeCentroidExtractor) and shape (see SafeShapeExtractor) information.

The default implementation simply throws an exception, indicating that simultaneous measurement is not supported.

Definition at line 31 of file Algorithm.cc.

32  {
33  throw LSST_EXCEPT(pex::exceptions::LogicError, "measureN not implemented for this algorithm");
34 }

◆ measureNForced()

virtual void lsst::meas::base::SimpleAlgorithm::measureNForced ( afw::table::SourceCatalog const &  measCat,
afw::image::Exposure< float > const &  exposure,
afw::table::SourceCatalog const &  refRecord,
afw::geom::SkyWcs const &  refWcs 
) const
inlinevirtualinherited

Called to simultaneously measure all children in a deblend family, in a single image.

Outputs should be saved in the given SourceCatalog, which can also be used to obtain centroid (see SafeCentroidExtractor) and shape (see SafeShapeExtractor) information.

The default implementation simply throws an exception, indicating that simultaneous measurement is not supported.

Reimplemented from lsst::meas::base::ForcedAlgorithm.

Definition at line 179 of file Algorithm.h.

182  {
183  measureN(measCat, exposure);
184  }
virtual void measureN(afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure) const
Called to simultaneously measure all children in a deblend family, in a single image.
Definition: Algorithm.cc:31

Member Data Documentation

◆ _logName

std::string lsst::meas::base::BaseAlgorithm::_logName
protectedinherited

Definition at line 69 of file Algorithm.h.


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