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::SafeShapeExtractor Class Reference

#include <InputUtilities.h>

Public Member Functions

 SafeShapeExtractor (afw::table::Schema &schema, std::string const &name)
 
afw::geom::ellipses::Quadrupole operator() (afw::table::SourceRecord &record, FlagHandler const &flags) const
 

Private Attributes

std::string _name
 

Detailed Description

Utility class for measurement algorithms that extracts an ellipse from the Shape slot and handles errors in a safe and consistent way.

Definition at line 92 of file InputUtilities.h.

Constructor & Destructor Documentation

lsst::meas::base::SafeShapeExtractor::SafeShapeExtractor ( afw::table::Schema schema,
std::string const &  name 
)

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

Parameters
[out]schemaSchema to which the alias should be added. The "slot_Shape" alias must already be present in the Schema's AliasMap.
[in]nameThe name of the algorithm; the flag alias added will be "<name>_flag_badShape".

Definition at line 139 of file InputUtilities.cc.

139  :
140  _name(name)
141 {
142  // Instead of aliasing e.g. MyAlgorithm_flag_badShape->slot_Shape_flag, we actually
143  // look up the target of slot_Shape_flag, and alias that to MyAlgorithm_flag_badCentroid.
144  // That way, if someone changes the slots later, after we've already done the measurement,
145  // this alias still points to the right thing.
146  std::string aliasedFlagName = schema.join("slot", "Shape", "flag");
147  std::string slotFlagName = schema.getAliasMap()->apply(aliasedFlagName);
148  if (aliasedFlagName == slotFlagName) {
149  throw LSST_EXCEPT(
150  pex::exceptions::LogicError,
151  (boost::format("Alias for '%s' must be defined before initializing '%s' plugin.")
152  % aliasedFlagName % name).str()
153  );
154  }
155  schema.getAliasMap()->set(schema.join(name, "flag", "badShape"), slotFlagName);
156 }
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::ellipses::Quadrupole lsst::meas::base::SafeShapeExtractor::operator() ( afw::table::SourceRecord record,
FlagHandler const &  flags 
) const

Extract a shape from the given record.

We use the Shape slot if it is not NaN, and throw MeasurementError if it is (with only the general failure code attached to the MeasurementError).

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

If the Shape slot value is NaN and is not flagged (or there is no Shape 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 Shape slot is flagged and we nevertheless obtain a usable ellipse, we set the current algorithm's general failure flag, but return the ellipse as well, allowing it to continue while indicating that the result may not be reliable. A singular ellipse (i.e. one with a non-positive quadrupole matrix determinant) is treated the same as a NaN ellipse; it is not considered usable.

Definition at line 158 of file InputUtilities.cc.

161  {
162  if (!record.getTable()->getShapeKey().isValid()) {
163  throw LSST_EXCEPT(
164  FatalAlgorithmError,
165  (boost::format("%s requires a shape, but the shape slot is not defined") % _name).str()
166  );
167  }
168  afw::geom::ellipses::Quadrupole result = record.getShape();
169  if (utils::isnan(result.getIxx()) || utils::isnan(result.getIyy()) || utils::isnan(result.getIxy())
170  || result.getDeterminant() < 0
171  ) {
172  if (!record.getTable()->getShapeFlagKey().isValid()) {
173  throw LSST_EXCEPT(
174  pex::exceptions::RuntimeError,
175  (boost::format("%s: Shape slot value is NaN, but there is no Shape slot flag "
176  "(is the executionOrder for %s lower than that of the slot Shape?)")
177  % _name % _name).str()
178  );
179  }
180  if (!record.getShapeFlag()) {
181  throw LSST_EXCEPT(
182  pex::exceptions::RuntimeError,
183  (boost::format("%s: Shape slot value is NaN, but the Shape slot flag is not set "
184  "(is the executionOrder for %s lower than that of the slot Shape?)")
185  % _name % _name).str()
186  );
187  }
188  throw LSST_EXCEPT(
189  MeasurementError,
190  (boost::format("%s: Shape needed, and Shape slot measurement failed.") % _name).str(),
192  );
193  } else if (record.getTable()->getShapeFlagKey().isValid() && record.getShapeFlag()) {
194  // we got a usable value, but the shape flag might still be set, and that might affect
195  // the current measurement
196  flags.setValue(record, FlagHandler::FAILURE, true);
197  }
198  return result;
199 }
int isnan(T t)
Definition: ieee.h:110
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46

Member Data Documentation

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

Definition at line 130 of file InputUtilities.h.


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