LSST Applications g0fba68d861+bb7a7cfa1f,g1ec0fe41b4+f536777771,g1fd858c14a+470a99fdf4,g216c3ac8a7+0d4d80193f,g35bb328faa+fcb1d3bbc8,g4d2262a081+23bd310d1b,g53246c7159+fcb1d3bbc8,g56a49b3a55+369644a549,g5a012ec0e7+3632fc3ff3,g60b5630c4e+3bfb9058a5,g67b6fd64d1+ed4b5058f4,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g8180f54f50+60bd39f3b6,g8352419a5c+fcb1d3bbc8,g87d29937c9+57a68d035f,g8852436030+4699110379,g89139ef638+ed4b5058f4,g9125e01d80+fcb1d3bbc8,g94187f82dc+3bfb9058a5,g989de1cb63+ed4b5058f4,g9ccd5d7f00+b7cae620c0,g9d31334357+3bfb9058a5,g9f33ca652e+00883ace41,gabe3b4be73+1e0a283bba,gabf8522325+fa80ff7197,gb1101e3267+27b24065a3,gb58c049af0+f03b321e39,gb89ab40317+ed4b5058f4,gc0af124501+708fe67c54,gcf25f946ba+4699110379,gd6cbbdb0b4+bb83cc51f8,gde0f65d7ad+acd5afb0eb,ge1ad929117+3bfb9058a5,ge278dab8ac+d65b3c2b70,ge410e46f29+ed4b5058f4,gf5e32f922b+fcb1d3bbc8,gf67bdafdda+ed4b5058f4,w.2025.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
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 setting flags.");
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 "Pixel in source outside usable exposure region (masked EDGE or centroid off image).");
111 _anyKeys["NO_DATA"] = schema.addField<afw::table::Flag>(name + "_flag_nodata",
112 "NO_DATA pixel in the source footprint.");
113 _anyKeys["INTRP"] = schema.addField<afw::table::Flag>(name + "_flag_interpolated",
114 "Interpolated pixel in the Source footprint");
115 _anyKeys["SAT"] = schema.addField<afw::table::Flag>(name + "_flag_saturated",
116 "Saturated pixel in the Source footprint");
117 _anyKeys["CR"] =
118 schema.addField<afw::table::Flag>(name + "_flag_cr", "Cosmic ray in the Source footprint");
119 _anyKeys["BAD"] =
120 schema.addField<afw::table::Flag>(name + "_flag_bad", "Bad pixel in the Source footprint");
121 _anyKeys["SUSPECT"] = schema.addField<afw::table::Flag>(name + "_flag_suspect",
122 "Source's footprint includes suspect pixels");
123 // Flags that correspond to mask bits which are set anywhere in the 3x3 central region of the object.
124 _centerKeys["EDGE"] = schema.addField<afw::table::Flag>(
125 name + "_flag_edgeCenter", "EDGE pixel in the 3x3 region around the centroid.");
126 _centerKeys["NO_DATA"] = schema.addField<afw::table::Flag>(
127 name + "_flag_nodataCenter", "NO_DATA pixel in the 3x3 region around the centroid.");
128 _centerKeys["INTRP"] = schema.addField<afw::table::Flag>(
129 name + "_flag_interpolatedCenter", "Interpolated pixel in the 3x3 region around the centroid.");
130 _centerKeys["SAT"] = schema.addField<afw::table::Flag>(
131 name + "_flag_saturatedCenter", "Saturated pixel in the 3x3 region around the centroid.");
132 _centerKeys["CR"] = schema.addField<afw::table::Flag>(
133 name + "_flag_crCenter", "Cosmic ray in the 3x3 region around the centroid.");
134 _centerKeys["BAD"] = schema.addField<afw::table::Flag>(name + "_flag_badCenter",
135 "Bad pixel in the 3x3 region around the centroid");
136 _centerKeys["SUSPECT"] = schema.addField<afw::table::Flag>(
137 name + "_flag_suspectCenter", "Suspect pixel in the 3x3 region around the centroid.");
138
139 // Flags that correspond to mask bits which are set on all of the 3x3 central pixels of the object.
140 _centerAllKeys["EDGE"] = schema.addField<afw::table::Flag>(
141 name + "_flag_edgeCenterAll",
142 "All pixels in the 3x3 region around the centroid are marked EDGE.");
143 _centerAllKeys["NO_DATA"] = schema.addField<afw::table::Flag>(
144 name + "_flag_nodataCenterAll",
145 "All pixels in the 3x3 region around the centroid are marked NO_DATA");
146 _centerAllKeys["INTRP"] = schema.addField<afw::table::Flag>(
147 name + "_flag_interpolatedCenterAll",
148 "All pixels in the 3x3 region around the centroid are interpolated.");
149 _centerAllKeys["SAT"] = schema.addField<afw::table::Flag>(
150 name + "_flag_saturatedCenterAll",
151 "All pixels in the 3x3 region around the centroid are saturated.");
152 _centerAllKeys["CR"] = schema.addField<afw::table::Flag>(
153 name + "_flag_crCenterAll",
154 "All pixels in the 3x3 region around the centroid have the cosmic ray mask bit.");
155 _centerAllKeys["BAD"] = schema.addField<afw::table::Flag>(
156 name + "_flag_badCenterAll", "All pixels in the 3x3 region around the centroid are bad.");
157 _centerAllKeys["SUSPECT"] = schema.addField<afw::table::Flag>(
158 name + "_flag_suspectCenterAll", "All pixels in the 3x3 region around the centroid are suspect.");
159
160 // Read in the flags passed from the configuration, and add them to the schema
161 for (auto const& i : _ctrl.masksFpCenter) {
162 std::string maskName(i);
163 std::transform(maskName.begin(), maskName.end(), maskName.begin(), ::tolower);
164 _centerKeys[i] = schema.addField<afw::table::Flag>(
165 name + "_flag_" + maskName + "Center", "3x3 region around the centroid has " + i + " pixels");
166 }
167 for (auto const& i : _ctrl.masksFpCenter) {
168 std::string maskName(i);
169 std::transform(maskName.begin(), maskName.end(), maskName.begin(), ::tolower);
170 _centerAllKeys[i] = schema.addField<afw::table::Flag>(
171 name + "_flag_" + maskName + "CenterAll",
172 "All pixels in the 3x3 region around the source centroid are " + i + " pixels");
173 }
174
175 for (auto const& i : _ctrl.masksFpAnywhere) {
176 std::string maskName(i);
177 std::transform(maskName.begin(), maskName.end(), maskName.begin(), ::tolower);
178 _anyKeys[i] = schema.addField<afw::table::Flag>(name + "_flag_" + maskName,
179 "Source footprint includes " + i + " pixels");
180 }
181}
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 262 of file PixelFlags.cc.

262 {
263 measRecord.set(_generalFailureKey, true);
264}

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

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

◆ 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: