26 #include "lsst/afw/table/Source.h" 27 #include "lsst/afw/detection/Footprint.h" 31 namespace lsst {
namespace meas {
namespace base {
34 afw::table::Schema & schema,
35 std::string
const & name,
39 _isCentroider(isCentroider)
45 std::string aliasedFlagName = schema.join(
"slot",
"Centroid",
"flag");
46 std::string slotFlagName = schema.getAliasMap()->apply(aliasedFlagName);
48 if (slotFlagName != schema.join(name,
"flag")) {
50 schema.getAliasMap()->set(schema.join(name,
"flag",
"badInitialCentroid"), slotFlagName);
53 if (aliasedFlagName == slotFlagName) {
55 pex::exceptions::LogicError,
56 (boost::format(
"Alias for '%s' must be defined before initializing '%s' plugin.")
57 % aliasedFlagName % name).str()
60 schema.getAliasMap()->set(schema.join(name,
"flag",
"badCentroid"), slotFlagName);
66 afw::geom::Point2D extractPeak(afw::table::SourceRecord
const & record, std::string
const & name) {
67 afw::geom::Point2D result;
68 PTR(afw::detection::Footprint) footprint = record.getFootprint();
71 pex::exceptions::RuntimeError,
72 (boost::format(
"%s: Centroid slot value is NaN, but no Footprint attached to record")
76 if (footprint->getPeaks().empty()) {
78 pex::exceptions::RuntimeError,
79 (boost::format(
"%s: Centroid slot value is NaN, but Footprint has no Peaks")
83 result.setX(footprint->getPeaks().front().getFx());
84 result.setY(footprint->getPeaks().front().getFy());
91 afw::table::SourceRecord & record,
94 if (!record.getTable()->getCentroidKey().isValid()) {
96 return extractPeak(record, _name);
100 (boost::format(
"%s requires a centroid, but the centroid slot is not defined") % _name).str()
104 afw::geom::Point2D result = record.getCentroid();
105 if (std::isnan(result.getX()) || std::isnan(result.getY())) {
106 if (!record.getTable()->getCentroidFlagKey().isValid()) {
108 return extractPeak(record, _name);
111 pex::exceptions::RuntimeError,
112 (boost::format(
"%s: Centroid slot value is NaN, but there is no Centroid slot flag " 113 "(is the executionOrder for %s lower than that of the slot Centroid?)")
114 % _name % _name).str()
118 if (!record.getCentroidFlag() && !_isCentroider) {
120 pex::exceptions::RuntimeError,
121 (boost::format(
"%s: Centroid slot value is NaN, but the Centroid slot flag is not set " 122 "(is the executionOrder for %s lower than that of the slot Centroid?)")
123 % _name % _name).str()
126 result = extractPeak(record, _name);
127 if (!_isCentroider) {
131 }
else if (!_isCentroider && record.getTable()->getCentroidFlagKey().isValid()
132 && record.getCentroidFlag()) {
147 std::string aliasedFlagName = schema.join(
"slot",
"Shape",
"flag");
148 std::string slotFlagName = schema.getAliasMap()->apply(aliasedFlagName);
149 if (aliasedFlagName == slotFlagName) {
151 pex::exceptions::LogicError,
152 (boost::format(
"Alias for '%s' must be defined before initializing '%s' plugin.")
153 % aliasedFlagName % name).str()
156 schema.getAliasMap()->set(schema.join(name,
"flag",
"badShape"), slotFlagName);
160 afw::table::SourceRecord & record,
163 if (!record.getTable()->getShapeKey().isValid()) {
166 (boost::format(
"%s requires a shape, but the shape slot is not defined") % _name).str()
169 afw::geom::ellipses::Quadrupole result = record.getShape();
170 if (std::isnan(result.getIxx()) || std::isnan(result.getIyy()) || std::isnan(result.getIxy())
171 || result.getIxx()*result.getIyy() <
172 (1.0 + 1.0e-6)*result.getIxy()*result.getIxy()
177 if (!record.getTable()->getShapeFlagKey().isValid()) {
179 pex::exceptions::RuntimeError,
180 (boost::format(
"%s: Shape slot value is NaN, but there is no Shape slot flag " 181 "(is the executionOrder for %s lower than that of the slot Shape?)")
182 % _name % _name).str()
185 if (!record.getShapeFlag()) {
187 pex::exceptions::RuntimeError,
188 (boost::format(
"%s: Shape slot value is NaN, but the Shape slot flag is not set " 189 "(is the executionOrder for %s lower than that of the slot Shape?)")
190 % _name % _name).str()
195 (boost::format(
"%s: Shape needed, and Shape slot measurement failed.") % _name).str(),
198 }
else if (record.getTable()->getShapeFlagKey().isValid() && record.getShapeFlag()) {
void setValue(afw::table::BaseRecord &record, std::size_t i, bool value) const
Set the flag field corresponding to the given flag index.
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Exception to be thrown when a measurement algorithm experiences a fatal error.
std::size_t getFailureFlagNumber() const
Get the index of the General Failure flag, if one is defined.
Utility class for handling flag fields that indicate the failure modes of an algorithm.