LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+f5613e8b4f,g1470d8bcf6+190ad2ba91,g14a832a312+311607e4ab,g2079a07aa2+86d27d4dc4,g2305ad1205+a8e3196225,g295015adf3+b67ee847e5,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+a761f810f3,g487adcacf7+17c8fdbcbd,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+65b5bd823e,g5a732f18d5+53520f316c,g64a986408d+f5613e8b4f,g6c1bc301e9+51106c2951,g858d7b2824+f5613e8b4f,g8a8a8dda67+585e252eca,g99cad8db69+6729933424,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e9bba80f27,gc120e1dc64+eee469a5e5,gc28159a63d+0e5473021a,gcf0d15dbbd+a761f810f3,gdaeeff99f8+f9a426f77a,ge6526c86ff+d4c1d4bfef,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf1cff7945b+f5613e8b4f,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
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.
 
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.
 
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.
 
void measureForced (afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure, afw::table::SourceRecord const &refRecord, afw::geom::SkyWcs const &refWcs) const override
 Called to measure a single child source in an image.
 
void measureNForced (afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure, afw::table::SourceCatalog const &refRecord, afw::geom::SkyWcs const &refWcs) const override
 Called to simultaneously measure all children in a deblend family, in a single image.
 
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.
 
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 99 of file PixelFlags.cc.

101 : _ctrl(ctrl) {
102 // Add generic keys first, which don't correspond to specific mask planes
103 _generalFailureKey = schema.addField<afw::table::Flag>(
104 name + "_flag", "General failure flag, set if anything went wrong");
105 _offImageKey =
106 schema.addField<afw::table::Flag>(name + "_flag" + "_offimage", "Source center is off image");
107 // Set all the flags that correspond to mask planes anywhere in the footprint
108 _anyKeys["EDGE"] = schema.addField<afw::table::Flag>(
109 name + "_flag_edge",
110 "Source is outside usable exposure region (masked EDGE or NO_DATA, or centroid off image).");
111 _anyKeys["NO_DATA"] = _anyKeys.at("EDGE"); // Also set edge flag for NO_DATA.
112 _anyKeys["INTRP"] = schema.addField<afw::table::Flag>(name + "_flag_interpolated",
113 "Interpolated pixel in the Source footprint");
114 _anyKeys["SAT"] = schema.addField<afw::table::Flag>(name + "_flag_saturated",
115 "Saturated pixel in the Source footprint");
116 _anyKeys["CR"] =
117 schema.addField<afw::table::Flag>(name + "_flag_cr", "Cosmic ray in the Source footprint");
118 _anyKeys["BAD"] =
119 schema.addField<afw::table::Flag>(name + "_flag_bad", "Bad pixel in the Source footprint");
120 _anyKeys["SUSPECT"] = schema.addField<afw::table::Flag>(name + "_flag_suspect",
121 "Source's footprint includes suspect pixels");
122 // Flags that correspond to mask bits which are set anywhere in the 3x3 central region of the object.
123 _centerKeys["EDGE"] = schema.addField<afw::table::Flag>(
124 name + "_flag_edgeCenter", "EDGE or NO_DATA Pixel in the 3x3 region around the centroid.");
125 _centerKeys["NO_DATA"] = _centerKeys.at("EDGE"); // Also set edge flag for NO_DATA.
126 _centerKeys["INTRP"] = schema.addField<afw::table::Flag>(
127 name + "_flag_interpolatedCenter", "Interpolated pixel in the 3x3 region around the centroid.");
128 _centerKeys["SAT"] = schema.addField<afw::table::Flag>(
129 name + "_flag_saturatedCenter", "Saturated pixel in the 3x3 region around the centroid.");
130 _centerKeys["CR"] = schema.addField<afw::table::Flag>(
131 name + "_flag_crCenter", "Cosmic ray in the 3x3 region around the centroid.");
132 _centerKeys["BAD"] = schema.addField<afw::table::Flag>(name + "_flag_badCenter",
133 "Bad pixel in the 3x3 region around the centroid");
134 _centerKeys["SUSPECT"] = schema.addField<afw::table::Flag>(
135 name + "_flag_suspectCenter", "Suspect pixel in the 3x3 region around the centroid.");
136
137 // Flags that correspond to mask bits which are set on all of the 3x3 central pixels of the object.
138 _centerAllKeys["EDGE"] = schema.addField<afw::table::Flag>(
139 name + "_flag_edgeCenterAll",
140 "All pixels in the 3x3 region around the centroid are marked EDGE or NO_DATA.");
141 _centerAllKeys["NO_DATA"] = _centerAllKeys.at("EDGE"); // Also set edge flag for NO_DATA.
142 _centerAllKeys["INTRP"] = schema.addField<afw::table::Flag>(
143 name + "_flag_interpolatedCenterAll",
144 "All pixels in the 3x3 region around the centroid are interpolated.");
145 _centerAllKeys["SAT"] = schema.addField<afw::table::Flag>(
146 name + "_flag_saturatedCenterAll",
147 "All pixels in the 3x3 region around the centroid are saturated.");
148 _centerAllKeys["CR"] = schema.addField<afw::table::Flag>(
149 name + "_flag_crCenterAll",
150 "All pixels in the 3x3 region around the centroid have the cosmic ray mask bit.");
151 _centerAllKeys["BAD"] = schema.addField<afw::table::Flag>(
152 name + "_flag_badCenterAll", "All pixels in the 3x3 region around the centroid are bad.");
153 _centerAllKeys["SUSPECT"] = schema.addField<afw::table::Flag>(
154 name + "_flag_suspectCenterAll", "All pixels in the 3x3 region around the centroid are suspect.");
155
156 // Read in the flags passed from the configuration, and add them to the schema
157 for (auto const& i : _ctrl.masksFpCenter) {
158 std::string maskName(i);
159 std::transform(maskName.begin(), maskName.end(), maskName.begin(), ::tolower);
160 _centerKeys[i] = schema.addField<afw::table::Flag>(
161 name + "_flag_" + maskName + "Center", "3x3 region around the centroid has " + i + " pixels");
162 }
163 for (auto const& i : _ctrl.masksFpCenter) {
164 std::string maskName(i);
165 std::transform(maskName.begin(), maskName.end(), maskName.begin(), ::tolower);
166 _centerAllKeys[i] = schema.addField<afw::table::Flag>(
167 name + "_flag_" + maskName + "CenterAll",
168 "All pixels in the 3x3 region around the source centroid are " + i + " pixels");
169 }
170
171 for (auto const& i : _ctrl.masksFpAnywhere) {
172 std::string maskName(i);
173 std::transform(maskName.begin(), maskName.end(), maskName.begin(), ::tolower);
174 _anyKeys[i] = schema.addField<afw::table::Flag>(name + "_flag_" + maskName,
175 "Source footprint includes " + i + " pixels");
176 }
177}
T at(T... args)
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 258 of file PixelFlags.cc.

258 {
259 measRecord.set(_generalFailureKey, true);
260}

◆ 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 179 of file PixelFlags.cc.

180 {
181 MaskedImageF mimage = exposure.getMaskedImage();
182 FootprintBits<MaskedImageF> func;
183
184 // Check if the measRecord has a valid centroid key, i.e. it was centroided
185 geom::Point2D center;
186 if (measRecord.getTable()->getCentroidSlot().getMeasKey().isValid()) {
187 center = measRecord.getCentroid();
188 } else {
189 // Set the general failure flag because using the Peak might affect
190 // the current measurement
191 measRecord.set(_generalFailureKey, true);
192 // Attempting to set pixel flags with no centroider, the center will
193 // be determined though the peak pixel. The first peak in the
194 // footprint (supplied by the measurement framework) should be the
195 // highest peak so that one will be used as a proxy for the central
196 // tendency of the distribution of flux for the record.
197 std::shared_ptr<afw::detection::Footprint> footprint = measRecord.getFootprint();
198 // If there is no footprint or the footprint contains no peaks, throw
199 // a runtime error.
200 if (!footprint || footprint->getPeaks().empty()) {
201 throw LSST_EXCEPT(pex::exceptions::RuntimeError, "No footprint, or no footprint peaks detected");
202 } else {
203 center.setX(footprint->getPeaks().front().getFx());
204 center.setY(footprint->getPeaks().front().getFy());
205 }
206 }
207
208 // Flag centroids off the image.
209 // Float bbox to properly handle non-finite centroids (casting Point2D->Point2I breaks NaN/inf).
210 geom::Box2D bbox(mimage.getBBox());
211 if (!bbox.contains(center)) {
212 measRecord.set(_offImageKey, true);
213 measRecord.set(_anyKeys.at("EDGE"), true);
214 measRecord.set(_centerKeys.at("EDGE"), true);
215 measRecord.set(_centerAllKeys.at("EDGE"), true);
216 }
217
218 // Check for bits set in the source's Footprint
219 auto footprint = measRecord.getFootprint();
220 if (!footprint) {
221 throw LSST_EXCEPT(pex::exceptions::RuntimeError,
222 (boost::format("Source id %d has no footprint.") % measRecord.getId()).str());
223 }
224 auto fullSpans = footprint->getSpans();
225 if (!fullSpans) {
226 throw LSST_EXCEPT(
227 pex::exceptions::RuntimeError,
228 (boost::format("Source id %d has no spans in footprint.") % measRecord.getId()).str());
229 }
230 fullSpans->clippedTo(mimage.getBBox())->applyFunctor(func, *(mimage.getMask()));
231
232 // update the source record for the any keys
233 updateFlags(_anyKeys, func, measRecord);
234
235 if (!(std::isfinite(center.getX()) && std::isfinite(center.getY()))) {
236 auto msg =
237 (boost::format("Centroid of source id %d passed to PixelFlags is non-finite; "
238 "footprint-based flags have been set, but centroid-based flags will not be.") %
239 measRecord.getId())
240 .str();
241 throw LSST_EXCEPT(pex::exceptions::RuntimeError, msg);
242 } else {
243 // Check for bits set in the 3x3 box around the center
244 geom::Point2I llc(afw::image::positionToIndex(center.getX()) - 1,
245 afw::image::positionToIndex(center.getY()) - 1);
246
247 func.reset();
248 auto spans = std::make_shared<afw::geom::SpanSet>(geom::Box2I(llc, geom::ExtentI(3)));
249 afw::detection::Footprint const middle(spans); // central 3x3
250 middle.getSpans()->clippedTo(mimage.getBBox())->applyFunctor(func, *(mimage.getMask()));
251
252 // Update the flags which have to do with the center of the footprint
253 updateFlags(_centerKeys, func, measRecord);
254 updateFlagsAll(_centerAllKeys, func, measRecord);
255 }
256}
AmpInfoBoxKey bbox
Definition Amplifier.cc:117
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
A floating-point coordinate rectangle geometry.
Definition Box.h:413
An integer coordinate rectangle.
Definition Box.h:55
T isfinite(T... args)
int positionToIndex(double pos)
Convert image position to nearest integer index.
Definition ImageUtils.h:69

◆ measureForced()

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
inlineoverridevirtualinherited

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()

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
inlineoverridevirtualinherited

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: