LSST Applications g042eb84c57+730a74494b,g04e9c324dd+8c5ae1fdc5,g134cb467dc+1f1e3e7524,g199a45376c+0ba108daf9,g1fd858c14a+fa7d31856b,g210f2d0738+f66ac109ec,g262e1987ae+83a3acc0e5,g29ae962dfc+d856a2cb1f,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+a1e0c9f713,g47891489e3+0d594cb711,g4d44eb3520+c57ec8f3ed,g4d7b6aa1c5+f66ac109ec,g53246c7159+8c5ae1fdc5,g56a1a4eaf3+fd7ad03fde,g64539dfbff+f66ac109ec,g67b6fd64d1+0d594cb711,g67fd3c3899+f66ac109ec,g6985122a63+0d594cb711,g74acd417e5+3098891321,g786e29fd12+668abc6043,g81db2e9a8d+98e2ab9f28,g87389fa792+8856018cbb,g89139ef638+0d594cb711,g8d7436a09f+80fda9ce03,g8ea07a8fe4+760ca7c3fc,g90f42f885a+033b1d468d,g97be763408+a8a29bda4b,g99822b682c+e3ec3c61f9,g9d5c6a246b+0d5dac0c3d,ga41d0fce20+9243b26dd2,gbf99507273+8c5ae1fdc5,gd7ef33dd92+0d594cb711,gdab6d2f7ff+3098891321,ge410e46f29+0d594cb711,geaed405ab2+c4bbc419c6,gf9a733ac38+8c5ae1fdc5,w.2025.38
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst::meas::base::CentroidChecker Class Reference

#include <CentroidUtilities.h>

Public Member Functions

 CentroidChecker (afw::table::Schema &schema, std::string const &name, bool inside=true, double maxDistFromPeak=-1.0)
 Check source record produced by a centroid algorithm called "name".
 
bool operator() (afw::table::SourceRecord &record) const
 Set the centroid to the first footprint if the centroid is either more than _dist pixels from the footprint center, or if it is outside the footprint.
 

Detailed Description

Definition at line 192 of file CentroidUtilities.h.

Constructor & Destructor Documentation

◆ CentroidChecker()

lsst::meas::base::CentroidChecker::CentroidChecker ( afw::table::Schema & schema,
std::string const & name,
bool inside = true,
double maxDistFromPeak = -1.0 )

Check source record produced by a centroid algorithm called "name".

If the centroid is accompanied by uncertainties (the xErr and yErr fields), these should not be NaN. If they are, the algorithmName + "_flag_badError" flag and the general failure flag for the algorithm are both set.

If the centroid set by the algorithm lies outside the footprint attached to the record, or the centroid is more than "dist" pixels from the footprint peak:

(1) the general failure flag for the algorithm is set (2) algorithmName + "_flag_resetToPeak" flag is set (3) the position of the centroid is changed to that of the footprint Peak

Parameters
[in,out]schemaSchema to which the flag_resetToPeak is to be added
[in]nameThe name of the algorithm we will be checking
[in]doFootprintCheckCheck if centroid is within footprint
[in]maxDistFromPeakIf >0; maximum distance in pixels between the footprint peak and centroid allowed before resetToPeak flag is set.

Definition at line 179 of file CentroidUtilities.cc.

181 : _doFootprintCheck(doFootprintCheck), _maxDistFromPeak(maxDistFromPeak) {
182 _resetKey = schema.addField<afw::table::Flag>(schema.join(name, "flag_resetToPeak"),
183 "set if CentroidChecker reset the centroid");
184 _failureKey = schema.find<afw::table::Flag>(schema.join(name, "flag")).key;
185 _xKey = schema.find<CentroidElement>(schema.join(name, "x")).key;
186 _yKey = schema.find<CentroidElement>(schema.join(name, "y")).key;
187
188 // We only check errors on the centroid if they exist: not all measurement
189 // algorithms provide them.
190 try {
191 _xErrKey = schema.find<ErrElement>(schema.join(name, "xErr")).key;
192 } catch (pex::exceptions::NotFoundError &err) {
193 }
194 try {
195 _yErrKey = schema.find<ErrElement>(schema.join(name, "yErr")).key;
196 } catch (pex::exceptions::NotFoundError &err) {
197 }
198 if (_xErrKey.isValid() || _yErrKey.isValid()) {
199 _badErrorKey = schema.addField<afw::table::Flag>(schema.join(name, "flag_badError"),
200 "Error on x and/or y position is NaN");
201 }
202}
double CentroidElement
Definition constants.h:56

Member Function Documentation

◆ operator()()

bool lsst::meas::base::CentroidChecker::operator() ( afw::table::SourceRecord & record) const

Set the centroid to the first footprint if the centroid is either more than _dist pixels from the footprint center, or if it is outside the footprint.

Set appropriate flags to indicate any changes to the centroid, and to indicate if uncertainties are set to invalid ("NaN") values.

Definition at line 204 of file CentroidUtilities.cc.

204 {
205 CentroidElement x = record.get(_xKey);
206 CentroidElement y = record.get(_yKey);
207
208 // Check any errors specified on the centroid position are valid.
209 if ((_xErrKey.isValid() && std::isnan(record.get(_xErrKey))) ||
210 (_yErrKey.isValid() && std::isnan(record.get(_yErrKey)))) {
211 record.set(_badErrorKey, true);
212 record.set(_failureKey, true);
213 }
214
215 // Only proceed with checking if appropriately configured.
216 if (!_doFootprintCheck && _maxDistFromPeak < 0.0) {
217 return false;
218 }
219
220 // Check that the centroid has a footprint that we can validate; otherwise, give up.
221 std::shared_ptr<afw::detection::Footprint> footprint = record.getFootprint();
222 if (!footprint) {
223 throw LSST_EXCEPT(pex::exceptions::RuntimeError, "No Footprint attached to record");
224 }
225 if (footprint->getPeaks().empty()) {
226 throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Footprint has no peaks; cannot verify centroid.");
227 }
228
229 // Set the centroid to the first footprint if the centroid is either more than
230 // _maxDistFromPeak pixels from the centroid, or if it is outside the footprint.
231 CentroidElement footX = footprint->getPeaks().front().getFx();
232 CentroidElement footY = footprint->getPeaks().front().getFy();
233 double distsq = (x - footX) * (x - footX) + (y - footY) * (y - footY);
234 if ((_doFootprintCheck && !footprint->contains(geom::Point2I(geom::Point2D(x, y)))) ||
235 ((_maxDistFromPeak > 0) && (distsq > _maxDistFromPeak * _maxDistFromPeak))) {
236 record.set(_xKey, footX);
237 record.set(_yKey, footY);
238 record.set(_failureKey, true);
239 record.set(_resetKey, true);
240 return true;
241 }
242 return false;
243}
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
T isnan(T... args)
Point< double, 2 > Point2D
Definition Point.h:324
Point< int, 2 > Point2I
Definition Point.h:321

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