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
ShapeUtilities.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  xx(std::numeric_limits<ShapeElement>::quiet_NaN()),
30  yy(std::numeric_limits<ShapeElement>::quiet_NaN()),
31  xy(std::numeric_limits<ShapeElement>::quiet_NaN()),
32  xxSigma(std::numeric_limits<ErrElement>::quiet_NaN()),
33  yySigma(std::numeric_limits<ErrElement>::quiet_NaN()),
34  xySigma(std::numeric_limits<ErrElement>::quiet_NaN()),
35  xx_yy_Cov(std::numeric_limits<ErrElement>::quiet_NaN()),
36  xx_xy_Cov(std::numeric_limits<ErrElement>::quiet_NaN()),
37  yy_xy_Cov(std::numeric_limits<ErrElement>::quiet_NaN())
38 {}
39 
40 Shape const ShapeResult::getShape() const { return Shape(xx, yy, xy); }
41 
42 void ShapeResult::setShape(Shape const & shape) {
43  xx = shape.getIxx();
44  yy = shape.getIyy();
45  xy = shape.getIxy();
46 }
47 
49  ShapeCov m;
50  m <<
54  return m;
55 }
56 
57 void ShapeResult::setShapeErr(ShapeCov const & matrix) {
58  xxSigma = std::sqrt(matrix(0, 0));
59  yySigma = std::sqrt(matrix(1, 1));
60  xySigma = std::sqrt(matrix(2, 2));
61  xx_yy_Cov = matrix(0, 1);
62  xx_xy_Cov = matrix(0, 2);
63  yy_xy_Cov = matrix(1, 2);
64 }
65 
68  std::string const & name,
69  std::string const & doc,
70  UncertaintyEnum uncertainty
71 ) {
74  schema,
75  name,
76  doc,
77  "pixels^2"
78  );
79  if (uncertainty != NO_UNCERTAINTY) {
80  std::vector< afw::table::Key<ErrElement> > sigma(3);
81  std::vector< afw::table::Key<ErrElement> > cov;
82  sigma[0] = schema.addField<ErrElement>(
83  schema.join(name, "xxSigma"), "1-sigma uncertainty on xx moment", "pixels^2"
84  );
85  sigma[1] = schema.addField<ErrElement>(
86  schema.join(name, "yySigma"), "1-sigma uncertainty on yy moment", "pixels^2"
87  );
88  sigma[2] = schema.addField<ErrElement>(
89  schema.join(name, "xySigma"), "1-sigma uncertainty on xy moment", "pixels^2"
90  );
91  if (uncertainty == FULL_COVARIANCE) {
92  cov.push_back(
93  schema.addField<ErrElement>(
94  schema.join(name, "xx_yy_Cov"), "uncertainty covariance in xx and yy", "pixels^4"
95  )
96  );
97  cov.push_back(
98  schema.addField<ErrElement>(
99  schema.join(name, "xx_xy_Cov"), "uncertainty covariance in xx and xy", "pixels^4"
100  )
101  );
102  cov.push_back(
103  schema.addField<ErrElement>(
104  schema.join(name, "yy_xy_Cov"), "uncertainty covariance in yy and xy", "pixels^4"
105  )
106  );
107  }
109  }
110  return r;
111 }
112 
113 namespace {
114 
115 std::vector<std::string> getNameVector() {
116  std::vector<std::string> v;
117  v.push_back("xx");
118  v.push_back("yy");
119  v.push_back("xy");
120  return v;
121 }
122 
123 } // anonymous
124 
126  _shape(s)
127 {
128  static std::vector<std::string> names = getNameVector(); // C++11 TODO: just use initializer list
129  try {
131  } catch (pex::exceptions::NotFoundError &) {}
132 }
133 
135  ShapeResult r;
136  r.setShape(record.get(_shape));
137  if (_shapeErr.isValid()) {
138  r.setShapeErr(record.get(_shapeErr));
139  }
140  return r;
141 }
142 
144  record.set(_shape, value.getShape());
145  if (_shapeErr.isValid()) {
146  record.set(_shapeErr, value.getShapeErr());
147  }
148 }
149 
150 }}} // lsst::meas::base
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:45
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 yy_xy_Cov
yy,xy term in the uncertainty convariance matrix
Eigen::Matrix< ErrElement, 3, 3, Eigen::DontAlign > ShapeCov
Definition: constants.h:57
UncertaintyEnum
An enum used to specify how much uncertainty information measurement algorithms provide.
Definition: constants.h:41
ShapeResultKey()
Default constructor; instance will not be usuable unless subsequently assigned to.
static QuadrupoleKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
double const getIxy() const
Definition: Quadrupole.h:62
The full covariance matrix is provided.
Definition: constants.h:44
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
ErrElement xySigma
1-Sigma uncertainty on xy (sqrt of variance)
float ErrElement
Definition: constants.h:51
Shape const getShape() const
Return an afw::geom::ellipses object corresponding to xx, yy, xy.
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:42
A FunctorKey for ShapeResult.
ErrElement xx_xy_Cov
xx,xy term in the uncertainty convariance matrix
void setShapeErr(ShapeCov const &matrix)
Set the struct uncertainty elements from the given matrix, with rows and columns ordered (xx...
ErrElement xx_yy_Cov
xx,yy term in the uncertainty convariance matrix
afw::geom::ellipses::Quadrupole Shape
Definition: constants.h:56
A reusable struct for moments-based shape measurements.
virtual void set(afw::table::BaseRecord &record, ShapeResult const &value) const
Set a ShapeResult in the given record.
tbl::Schema schema
Definition: CoaddPsf.cc:324
afw::table::QuadrupoleKey _shape
double const getIyy() const
Definition: Quadrupole.h:59
ShapeResult()
Constructor; initializes everything to NaN.
virtual ShapeResult get(afw::table::BaseRecord const &record) const
Get a ShapeResult from 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
ErrElement yySigma
1-Sigma uncertainty on yy (sqrt of variance)
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:136
double ShapeElement
Definition: constants.h:53
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition: BaseRecord.h:123
bool isValid() const
Return True if all the constituent sigma Keys are valid.
ErrElement xxSigma
1-Sigma uncertainty on xx (sqrt of variance)
static ShapeResultKey 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 ShapeResultKey that manages them.
void setShape(Shape const &shape)
Set struct elements from the given Quadrupole object.
ShapeCov const getShapeErr() const
Return the 3x3 symmetric covariance matrix, with rows and columns ordered (xx, yy, xy)
afw::table::CovarianceMatrixKey< ErrElement, 3 > _shapeErr
double const getIxx() const
Definition: Quadrupole.h:56
afw::table::SourceRecord * record