LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Private Attributes | List of all members
lsst::meas::base::SafeCentroidExtractor Class Reference

#include <InputUtilities.h>

Public Member Functions

 SafeCentroidExtractor (afw::table::Schema &schema, std::string const &name, bool isCentroider=false)
 
afw::geom::Point2D operator() (afw::table::SourceRecord &record, FlagHandler const &flags) const
 

Private Attributes

std::string _name
 
bool _isCentroider
 

Detailed Description

Utility class for measurement algorithms that extracts a position from the Centroid slot and handles errors in a safe and consistent way.

Definition at line 37 of file InputUtilities.h.

Constructor & Destructor Documentation

lsst::meas::base::SafeCentroidExtractor::SafeCentroidExtractor ( afw::table::Schema schema,
std::string const &  name,
bool  isCentroider = false 
)

Construct the extractor, creating a flag alias that indicates failure in the input centroid by linking to the slot centroid flag.

Parameters
[out]schemaSchema to which the alias should be added. The "slot_Centroid" alias must already be present in the Schema's AliasMap.
[in]nameThe name of the algorithm; the flag alias added will be "<name>_flag_badCentroid", or "<name>_flag_badInitialCentroid" if isCentroider=true.
[in]isCentroiderIndicates whether the calling algorithm is itself a centroid measurement algorithm. If true,, falling back to the Peak because there was no previous centroider or a previous centroider failed will not cause the general failure flag of the current algorithm to be set.

Definition at line 32 of file InputUtilities.cc.

36  :
37  _name(name),
38  _isCentroider(isCentroider)
39 {
40  // Instead of aliasing e.g. MyAlgorithm_flag_badCentroid->slot_Centroid_flag, we actually
41  // look up the target of slot_Centroid_flag, and alias that to MyAlgorithm_flag_badCentroid.
42  // That way, if someone changes the slots later, after we've already done the measurement,
43  // this alias still points to the right thing.
44  std::string aliasedFlagName = schema.join("slot", "Centroid", "flag");
45  std::string slotFlagName = schema.getAliasMap()->apply(aliasedFlagName);
46  if (_isCentroider) {
47  if (slotFlagName != schema.join(name, "flag")) {
48  // only setup the alias if this isn't the slot algorithm itself (otherwise it'd be circular)
49  schema.getAliasMap()->set(schema.join(name, "flag", "badInitialCentroid"), slotFlagName);
50  }
51  } else {
52  if (aliasedFlagName == slotFlagName) {
53  throw LSST_EXCEPT(
54  pex::exceptions::LogicError,
55  (boost::format("Alias for '%s' must be defined before initializing '%s' plugin.")
56  % aliasedFlagName % name).str()
57  );
58  }
59  schema.getAliasMap()->set(schema.join(name, "flag", "badCentroid"), slotFlagName);
60  }
61 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
afw::table::Schema schema
Definition: GaussianPsf.cc:41
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46

Member Function Documentation

afw::geom::Point2D lsst::meas::base::SafeCentroidExtractor::operator() ( afw::table::SourceRecord record,
FlagHandler const &  flags 
) const

Extract a position from the given record.

We use the Centroid slot if it is not NaN, and fall back to the Peak on the Footprint otherwise.

If the Centroid slot is not defined, we throw FatalAlgorithmError, as this indicates a configuration problem.

If the Centroid slot value is NaN and is not flagged (or there is no Centroid slot flag), we throw RuntimeError, which should cause the measurement framework to log a warning and set the current algorithm's general failure flag if it is allowed to propagate out of the algorithm implementation.

If the Centroid slot is NaN and there is no Footprint or Peak (even if the centroid is flagged), we also throw RuntimeError, as this indicates something wrong in another stage of the pipeline that should be addressed before measurement is run.

If the Centroid slot is flagged and we nevertheless obtain a usable position (either from a the Centroid slot itself or from a successful fall-back to the Peak), we set the current algorithm's general failure flag, but return the position as well, allowing it to continue while indicating that the result may not be reliable.

Definition at line 89 of file InputUtilities.cc.

92  {
93  if (!record.getTable()->getCentroidKey().isValid()) {
94  if (_isCentroider) {
95  return extractPeak(record, _name);
96  } else {
97  throw LSST_EXCEPT(
98  FatalAlgorithmError,
99  (boost::format("%s requires a centroid, but the centroid slot is not defined") % _name).str()
100  );
101  }
102  }
103  afw::geom::Point2D result = record.getCentroid();
104  if (utils::isnan(result.getX()) || utils::isnan(result.getY())) {
105  if (!record.getTable()->getCentroidFlagKey().isValid()) {
106  if (_isCentroider) {
107  return extractPeak(record, _name);
108  } else {
109  throw LSST_EXCEPT(
110  pex::exceptions::RuntimeError,
111  (boost::format("%s: Centroid slot value is NaN, but there is no Centroid slot flag "
112  "(is the executionOrder for %s lower than that of the slot Centroid?)")
113  % _name % _name).str()
114  );
115  }
116  }
117  if (!record.getCentroidFlag() && !_isCentroider) {
118  throw LSST_EXCEPT(
119  pex::exceptions::RuntimeError,
120  (boost::format("%s: Centroid slot value is NaN, but the Centroid slot flag is not set "
121  "(is the executionOrder for %s lower than that of the slot Centroid?)")
122  % _name % _name).str()
123  );
124  }
125  result = extractPeak(record, _name);
126  if (!_isCentroider) {
127  // set the general flag, because using the Peak might affect the current measurement
128  flags.setValue(record, FlagHandler::FAILURE, true);
129  }
130  } else if (!_isCentroider && record.getTable()->getCentroidFlagKey().isValid()
131  && record.getCentroidFlag()) {
132  // we got a usable value, but the centroid flag is still be set, and that might affect
133  // the current measurement
134  flags.setValue(record, FlagHandler::FAILURE, true);
135  }
136  return result;
137 }
Point< double, 2 > Point2D
Definition: Point.h:286
int isnan(T t)
Definition: ieee.h:110
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46

Member Data Documentation

bool lsst::meas::base::SafeCentroidExtractor::_isCentroider
private

Definition at line 85 of file InputUtilities.h.

std::string lsst::meas::base::SafeCentroidExtractor::_name
private

Definition at line 84 of file InputUtilities.h.


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