23#include "ndarray/eigen.h"
36 flagDefinitions.add(
"flag_noCounts",
"Object to be centroided has no counts");
38 flagDefinitions.add(
"flag_edge",
"Object too close to edge");
45 _centroidKey(
CentroidResultKey::addFields(schema, name,
"centroid from Naive Centroid algorithm",
48 _centroidExtractor(schema, name, true),
49 _centroidChecker(schema, name, ctrl.doFootprintCheck, ctrl.maxDistToPeak) {}
53 geom::Point2D center = _centroidExtractor(measRecord, _flagHandler);
55 result.
x = center.getX();
56 result.
y = center.getY();
57 measRecord.
set(_centroidKey, result);
62 int x = center.getX();
63 int y = center.getY();
68 if (x < 1 || x >=
image.getWidth() - 1 || y < 1 || y >=
image.getHeight() - 1) {
69 _flagHandler.setValue(measRecord,
EDGE.number,
true);
74 ImageT::xy_locator im =
image.xy_at(x, y);
76 double const sum = (im(-1, 1) + im(0, 1) + im(1, 1) + im(-1, 0) + im(0, 0) + im(1, 0) + im(-1, -1) +
77 im(0, -1) + im(1, -1)) -
81 _flagHandler.setValue(measRecord,
NO_COUNTS.number,
true);
86 double const sum_x = -im(-1, 1) + im(1, 1) + -im(-1, 0) + im(1, 0) + -im(-1, -1) + im(1, -1);
87 double const sum_y = (im(-1, 1) + im(0, 1) + im(1, 1)) - (im(-1, -1) + im(0, -1) + im(1, -1));
91 measRecord.
set(_centroidKey, result);
92 _centroidChecker(measRecord);
96 _flagHandler.handleFailure(measRecord, error);
MaskedImageT getMaskedImage()
ImagePtr getImage() const
void set(Key< T > const &key, U const &value)
std::string join(std::string const &a, std::string const &b) const
std::set< std::string > getNames(bool topOnly=false) const
SchemaItem< T > find(std::string const &name) const
Key< T > addMapping(Key< T > const &inputKey, bool doReplace=false)
Schema const getInputSchema() const
A FunctorKey for CentroidResult.
vector-type utility class to build a collection of FlagDefinitions
std::size_t size() const
return the current size (number of defined elements) of the collection
Utility class for handling flag fields that indicate the failure modes of an algorithm.
Exception to be thrown when a measurement algorithm experiences a known failure mode.
static FlagDefinition const NO_COUNTS
virtual void fail(afw::table::SourceRecord &measRecord, MeasurementError *error=nullptr) const
Handle an exception thrown by the current algorithm by setting flags in the given record.
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
static FlagDefinition const FAILURE
NaiveCentroidAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
NaiveCentroidControl Control
static FlagDefinition const EDGE
static FlagDefinitionList const & getFlagDefinitions()
double indexToPosition(double ind)
Point< double, 2 > Point2D
@ NO_UNCERTAINTY
Algorithm provides no uncertainy information at all.
A reusable struct for centroid measurements.
CentroidElement y
y (row) coordinate of the measured position
CentroidElement x
x (column) coordinate of the measured position
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...