25 #include "lsst/afw/table/BaseRecord.h" 27 namespace lsst {
namespace meas {
namespace base {
53 xSigma = std::sqrt(matrix(0, 0));
54 ySigma = std::sqrt(matrix(1, 1));
65 afw::table::Schema & schema,
66 std::string
const & name,
67 std::string
const & doc,
71 r._centroid = afw::table::PointKey<CentroidElement>::addFields(
78 std::vector< afw::table::Key<ErrElement> > sigma(2);
79 std::vector< afw::table::Key<ErrElement> > cov;
81 schema.join(name,
"xSigma"),
"1-sigma uncertainty on x position",
"pixel" 84 schema.join(name,
"ySigma"),
"1-sigma uncertainty on y position",
"pixel" 89 schema.join(name,
"x_y_Cov"),
"uncertainty covariance in x and y",
"pixel^2" 93 r._centroidErr = afw::table::CovarianceMatrixKey<ErrElement,2>(sigma, cov);
100 std::vector<std::string> getNameVector() {
101 std::vector<std::string> v;
112 static std::vector<std::string> names = getNameVector();
114 _centroidErr = afw::table::CovarianceMatrixKey<ErrElement,2>(s, names);
115 }
catch (pex::exceptions::NotFoundError &) {}
121 if (_centroidErr.isValid()) {
129 if (_centroidErr.isValid()) {
135 std::string
const & name,
136 afw::table::SchemaMapper & mapper
141 mapper.addMapping(mapper.getInputSchema().find<afw::table::Flag>(name +
"_flag").key);
144 auto & s = mapper.editOutputSchema();
145 _coordKey = afw::table::CoordKey::addFields(s, name,
"ICRS coordinates");
151 std::vector< afw::table::Key<ErrElement> > sigma(2);
152 std::vector< afw::table::Key<ErrElement> > cov(1);
153 sigma[0] = s.addField<
ErrElement>(s.join(name,
"raSigma"),
"Uncertainty on RA",
"rad");
154 sigma[1] = s.addField<
ErrElement>(s.join(name,
"decSigma"),
"Uncertainty on dec",
"rad");
155 cov[0] = s.addField<
ErrElement>(s.join(name,
"ra_dec_Cov"),
156 "Uncertainty covariance in RA and dec",
"rad^2");
157 _coordErrKey = afw::table::CovarianceMatrixKey<ErrElement,2>(sigma, cov);
163 afw::table::SourceCatalog
const & inputCatalog,
164 afw::table::BaseCatalog & outputCatalog,
165 afw::image::Wcs
const & wcs,
166 afw::image::Calib
const & calib
171 afw::table::SourceCatalog::const_iterator inSrc = inputCatalog.begin();
172 afw::table::BaseCatalog::iterator outSrc = outputCatalog.begin();
174 for (; inSrc != inputCatalog.end() && outSrc != outputCatalog.end(); ++inSrc, ++outSrc) {
177 _coordKey.set(*outSrc, *wcs.pixelToSky(centroidResult.
getCentroid()));
179 if (centroidResultKey.getCentroidErr().isValid()) {
181 if (!(std::isnan(centroidCov(0,0)) || std::isnan(centroidCov(1,1)))) {
183 afw::geom::radians).getLinear().getMatrix();
185 transform.transpose()).cast<ErrElement>());
194 afw::table::Schema & schema,
195 std::string
const & name,
196 bool doFootprintCheck,
197 double maxDistFromPeak
198 ) : _doFootprintCheck(doFootprintCheck), _maxDistFromPeak(maxDistFromPeak)
200 _resetKey = schema.addField<afw::table::Flag>(schema.join(name,
"flag_resetToPeak"),
201 "set if CentroidChecker reset the centroid");
202 _failureKey = schema.find<lsst::afw::table::Flag>(schema.join(name,
"flag")).key;
210 afw::table::SourceRecord & record
215 if (!_doFootprintCheck && _maxDistFromPeak < 0.0) {
218 PTR(afw::detection::Footprint) footprint = record.getFootprint();
221 pex::exceptions::RuntimeError,
222 "No Footprint attached to record");
224 if (footprint->getPeaks().empty()) {
226 pex::exceptions::RuntimeError,
227 "Footprint has no peaks; cannot verify centroid." 232 double distsq = (x - footX) * (x - footX) + (y - footY) * (y - footY);
233 if ((_doFootprintCheck && !footprint->contains(lsst::afw::geom::Point2I(lsst::afw::geom::Point2D(x, y)))) ||
234 ((_maxDistFromPeak > 0) && (distsq > _maxDistFromPeak*_maxDistFromPeak))) {
235 record.set(_xKey, footX);
236 record.set(_yKey, footY);
237 record.set(_failureKey,
true);
238 record.set(_resetKey,
true);
Centroid const getCentroid() const
Return a Point object containing the measured x and y.
ErrElement ySigma
1-Sigma uncertainty on y (sqrt of variance)
virtual void set(afw::table::BaseRecord &record, CentroidResult const &value) const
Set a CentroidResult in the given record.
UncertaintyEnum
An enum used to specify how much uncertainty information measurement algorithms provide.
A reusable struct for centroid measurements.
ErrElement xSigma
1-Sigma uncertainty on x (sqrt of variance)
bool isValid() const
Return True if the centroid key is valid.
The full covariance matrix is provided.
CentroidElement x
x (column) coordinate of the measured position
void setCentroid(Centroid const ¢roid)
Set the struct fields from the given Point object.
CentroidChecker(afw::table::Schema &schema, std::string const &name, bool inside=true, double maxDistFromPeak=-1.0)
Check source record for an centroid algorithm called name, noting if the centroid already set by the ...
CentroidResult()
Constructor; initializes everything to NaN.
ErrElement x_y_Cov
x,y term in the uncertainty convariance matrix
static CentroidResultKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc, UncertaintyEnum uncertainty)
Add the appropriate fields to a Schema, and return a CentroidResultKey that manages them...
bool operator()(afw::table::SourceRecord &record) const
Set the centroid to the first footprint if the centroid is either more than _dist pixels from the foo...
Algorithm provides no uncertainy information at all.
A FunctorKey for CentroidResult.
CentroidElement y
y (row) coordinate of the measured position
Eigen::Matrix< ErrElement, 2, 2, Eigen::DontAlign > CentroidCov
afw::geom::Point< CentroidElement, 2 > Centroid
CentroidResultKey()
Default constructor; instance will not be usuable unless subsequently assigned to.
virtual CentroidResult get(afw::table::BaseRecord const &record) const
Get a CentroidResult from the given record.
CentroidCov const getCentroidErr() const
Return the 2x2 symmetric covariance matrix, with rows and columns ordered (x, y)
void setCentroidErr(CentroidCov const &matrix)
Set the struct uncertainty fields from the given matrix, with rows and columns ordered (x...