23 #include "ndarray/eigen.h" 24 #include "lsst/afw/table/Source.h" 28 namespace lsst {
namespace meas {
namespace base {
30 FlagDefinitionList flagDefinitions;
38 return flagDefinitions;
43 std::string
const & name,
44 afw::table::Schema & schema
51 _centroidExtractor(schema, name, true),
52 _centroidChecker(schema, name, ctrl.doFootprintCheck, ctrl.maxDistToPeak)
57 afw::table::SourceRecord & measRecord,
58 afw::image::Exposure<float>
const & exposure
61 afw::geom::Point2D center = _centroidExtractor(measRecord, _flagHandler);
63 result.
x = center.getX();
64 result.
y = center.getY();
65 measRecord.set(_centroidKey, result);
67 typedef afw::image::Image<float> ImageT;
68 ImageT
const& image = *exposure.getMaskedImage().getImage();
70 int x = center.getX();
71 int y = center.getY();
76 if (x < 1 || x >= image.getWidth() - 1 || y < 1 || y >= image.getHeight() - 1) {
85 ImageT::xy_locator im = image.xy_at(x, y);
88 (im(-1, 1) + im( 0, 1) + im( 1, 1) +
89 im(-1, 0) + im( 0, 0) + im( 1, 0) +
90 im(-1, -1) + im( 0, -1) + im( 1, -1))
102 -im(-1, 1) + im( 1, 1) +
103 -im(-1, 0) + im( 1, 0) +
104 -im(-1, -1) + im( 1, -1);
106 (im(-1, 1) + im( 0, 1) + im( 1, 1)) -
107 (im(-1, -1) + im( 0, -1) + im( 1, -1));
109 result.
x = lsst::afw::image::indexToPosition(x + image.getX0()) + sum_x / sum;
110 result.
y = lsst::afw::image::indexToPosition(y + image.getY0()) + sum_y / sum;
111 measRecord.set(_centroidKey, result);
112 _centroidChecker(measRecord);
122 std::string
const & name,
123 afw::table::SchemaMapper & mapper
129 if (flag == NaiveCentroidAlgorithm::FAILURE)
continue;
130 if (mapper.getInputSchema().getNames().count(
131 mapper.getInputSchema().join(name, flag.
name)) == 0)
continue;
132 afw::table::Key<afw::table::Flag> key = mapper.getInputSchema().find<afw::table::Flag>(
133 name +
"_" + flag.
name).key;
134 mapper.addMapping(key);
std::size_t size() const
return the current size (number of defined elements) of the collection
NaiveCentroidAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...
A reusable struct for centroid measurements.
static FlagDefinition const EDGE
CentroidElement x
x (column) coordinate of the measured position
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Utility class for handling flag fields that indicate the failure modes of an algorithm.
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 FlagDefinitionList const & getFlagDefinitions()
static FlagDefinition const NO_COUNTS
Algorithm provides no uncertainy information at all.
double background
"Value to subtract from the image pixel values" ;
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=nullptr) const
Handle an expected or unexpected Exception thrown by a measurement algorithm.
A FunctorKey for CentroidResult.
CentroidElement y
y (row) coordinate of the measured position
A C++ control class to handle NaiveCentroidAlgorithm's configuration.
vector-type utility class to build a collection of FlagDefinitions
static FlagDefinition const FAILURE