LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
CentroidUtilities.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2014 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
25 
26 namespace lsst { namespace meas { namespace base {
27 
29  x(std::numeric_limits<CentroidElement>::quiet_NaN()),
30  y(std::numeric_limits<CentroidElement>::quiet_NaN()),
31  xSigma(std::numeric_limits<ErrElement>::quiet_NaN()),
32  ySigma(std::numeric_limits<ErrElement>::quiet_NaN()),
33  x_y_Cov(std::numeric_limits<ErrElement>::quiet_NaN())
34 {}
35 
36 Centroid const CentroidResult::getCentroid() const { return Centroid(x, y); }
37 
39  x = centroid.getX();
40  y = centroid.getY();
41 }
42 
44  CentroidCov m;
45  m <<
48  return m;
49 }
50 
52  xSigma = std::sqrt(matrix(0, 0));
53  ySigma = std::sqrt(matrix(1, 1));
54  x_y_Cov = matrix(0, 1);
55 }
56 
59  std::string const & name,
60  std::string const & doc,
61  UncertaintyEnum uncertainty
62 ) {
65  schema,
66  name,
67  doc,
68  "pixels"
69  );
70  if (uncertainty != NO_UNCERTAINTY) {
71  std::vector< afw::table::Key<ErrElement> > sigma(2);
72  std::vector< afw::table::Key<ErrElement> > cov;
73  sigma[0] = schema.addField<ErrElement>(
74  schema.join(name, "xSigma"), "1-sigma uncertainty on x position", "pixels"
75  );
76  sigma[1] = schema.addField<ErrElement>(
77  schema.join(name, "ySigma"), "1-sigma uncertainty on y position", "pixels"
78  );
79  if (uncertainty == FULL_COVARIANCE) {
80  cov.push_back(
81  schema.addField<ErrElement>(
82  schema.join(name, "x_y_Cov"), "uncertainty covariance in x and y", "pixels^2"
83  )
84  );
85  }
87  }
88  return r;
89 }
90 
91 namespace {
92 
93 std::vector<std::string> getNameVector() {
94  std::vector<std::string> v;
95  v.push_back("x");
96  v.push_back("y");
97  return v;
98 }
99 
100 } // anonymous
101 
103  _centroid(s)
104 {
105  static std::vector<std::string> names = getNameVector(); // C++11 TODO: just use initializer list
106  try {
108  } catch (pex::exceptions::NotFoundError &) {}
109 }
110 
112  CentroidResult r;
113  r.setCentroid(record.get(_centroid));
114  if (_centroidErr.isValid()) {
115  r.setCentroidErr(record.get(_centroidErr));
116  }
117  return r;
118 }
119 
121  record.set(_centroid, value.getCentroid());
122  if (_centroidErr.isValid()) {
123  record.set(_centroidErr, value.getCentroidErr());
124  }
125 }
126 
127 }}} // lsst::meas::base
Defines the fields and offsets for a table.
Definition: Schema.h:46
A proxy type for name lookups in a Schema.
Definition: Schema.h:370
ErrElement ySigma
1-Sigma uncertainty on y (sqrt of variance)
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
int y
UncertaintyEnum
An enum used to specify how much uncertainty information measurement algorithms provide.
Definition: constants.h:41
A reusable struct for centroid measurements.
Centroid const getCentroid() const
Return a Point object containing the measured x and y.
ErrElement xSigma
1-Sigma uncertainty on x (sqrt of variance)
The full covariance matrix is provided.
Definition: constants.h:44
CentroidElement x
x (column) coordinate of the measured position
void setCentroid(Centroid const &centroid)
Set the struct fields from the given Point object.
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
float ErrElement
Definition: constants.h:51
A coordinate class intended to represent absolute positions.
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:42
CentroidResult()
Constructor; initializes everything to NaN.
tbl::Schema schema
Definition: CoaddPsf.cc:324
int x
ErrElement x_y_Cov
x,y term in the uncertainty convariance matrix
virtual CentroidResult get(afw::table::BaseRecord const &record) const
Get a CentroidResult from the given record.
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...
virtual void set(afw::table::BaseRecord &record, CentroidResult const &value) const
Set a CentroidResult in the given record.
Base class for all records.
Definition: BaseRecord.h:27
std::string join(std::string const &a, std::string const &b) const
Join strings using the field delimiter appropriate for this Schema&#39;s version.
Algorithm provides no uncertainy information at all.
Definition: constants.h:42
CentroidCov const getCentroidErr() const
Return the 2x2 symmetric covariance matrix, with rows and columns ordered (x, y)
A FunctorKey for CentroidResult.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:136
CentroidElement y
y (row) coordinate of the measured position
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition: BaseRecord.h:123
Eigen::Matrix< ErrElement, 2, 2, Eigen::DontAlign > CentroidCov
Definition: constants.h:55
afw::geom::Point< CentroidElement, 2 > Centroid
Definition: constants.h:54
bool isValid() const
Return True if all the constituent sigma Keys are valid.
afw::table::PointKey< CentroidElement > _centroid
CentroidResultKey()
Default constructor; instance will not be usuable unless subsequently assigned to.
double CentroidElement
Definition: constants.h:52
afw::table::CovarianceMatrixKey< ErrElement, 2 > _centroidErr
afw::table::SourceRecord * record
void setCentroidErr(CentroidCov const &matrix)
Set the struct uncertainty fields from the given matrix, with rows and columns ordered (x...