Class SafeCentroidExtractor

Class Documentation

class SafeCentroidExtractor

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

Public Functions

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] schema: Schema to which the alias should be added. The “slot_Centroid” alias must already be present in the Schema’s AliasMap.

  • [in] name: The name of the algorithm; the flag alias added will be “<name>_flag_badCentroid”, or “<name>_flag_badInitialCentroid” if isCentroider=true.

  • [in] isCentroider: Indicates 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.

geom::Point2D 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.