LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
ShapeUtilities.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2015 AURA/LSST.
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 
66 void ShapeResult::setShapeErr(ErrElement _xxSigma, ErrElement _yySigma, ErrElement _xySigma) {
67  xxSigma = _xxSigma;
68  yySigma = _yySigma;
69  xySigma = _xySigma;
70  xx_yy_Cov = 0.0;
71  xx_xy_Cov = 0.0;
72  yy_xy_Cov = 0.0;
73 }
74 
77  std::string const & name,
78  std::string const & doc,
79  UncertaintyEnum uncertainty,
81 ) {
84  schema,
85  name,
86  doc,
87  coordType
88  );
89  if (uncertainty != NO_UNCERTAINTY) {
90  std::vector< afw::table::Key<ErrElement> > sigma(3);
91  std::vector< afw::table::Key<ErrElement> > cov;
92  sigma[0] = schema.addField<ErrElement>(
93  schema.join(name, "xxSigma"), "1-sigma uncertainty on xx moment",
94  coordType == afw::table::CoordinateType::PIXEL ? "pixels^2" : "radians^2"
95  );
96  sigma[1] = schema.addField<ErrElement>(
97  schema.join(name, "yySigma"), "1-sigma uncertainty on yy moment",
98  coordType == afw::table::CoordinateType::PIXEL ? "pixels^2" : "radians^2"
99  );
100  sigma[2] = schema.addField<ErrElement>(
101  schema.join(name, "xySigma"), "1-sigma uncertainty on xy moment",
102  coordType == afw::table::CoordinateType::PIXEL ? "pixels^2" : "radians^2"
103  );
104  if (uncertainty == FULL_COVARIANCE) {
105  cov.push_back(
106  schema.addField<ErrElement>(
107  schema.join(name, "xx_yy_Cov"), "uncertainty covariance in xx and yy",
108  coordType == afw::table::CoordinateType::PIXEL ? "pixels^4" : "radians^4"
109  )
110  );
111  cov.push_back(
112  schema.addField<ErrElement>(
113  schema.join(name, "xx_xy_Cov"), "uncertainty covariance in xx and xy",
114  coordType == afw::table::CoordinateType::PIXEL ? "pixels^4" : "radians^4"
115  )
116  );
117  cov.push_back(
118  schema.addField<ErrElement>(
119  schema.join(name, "yy_xy_Cov"), "uncertainty covariance in yy and xy",
120  coordType == afw::table::CoordinateType::PIXEL ? "pixels^4" : "radians^4"
121  )
122  );
123  }
125  }
126  return r;
127 }
128 
129 namespace {
130 
131 std::vector<std::string> getNameVector() {
132  std::vector<std::string> v;
133  v.push_back("xx");
134  v.push_back("yy");
135  v.push_back("xy");
136  return v;
137 }
138 
139 } // anonymous
140 
142  _shape(s)
143 {
144  static std::vector<std::string> names = getNameVector(); // C++11 TODO: just use initializer list
145  try {
147  } catch (pex::exceptions::NotFoundError &) {}
148 }
149 
151  ShapeResult r;
152  r.setShape(record.get(_shape));
153  if (_shapeErr.isValid()) {
154  r.setShapeErr(record.get(_shapeErr));
155  }
156  return r;
157 }
158 
159 void ShapeResultKey::set(afw::table::BaseRecord & record, ShapeResult const & value) const {
160  record.set(_shape, value.getShape());
161  if (_shapeErr.isValid()) {
162  record.set(_shapeErr, value.getShapeErr());
163  }
164 }
165 
167  typedef afw::geom::LinearTransform LT;
168  Eigen::Matrix<ShapeElement,3,3,Eigen::DontAlign> m;
169  m << xform[LT::XX]*xform[LT::XX], xform[LT::XY]*xform[LT::XY], 2*xform[LT::XX]*xform[LT::XY],
170  xform[LT::YX]*xform[LT::YX], xform[LT::YY]*xform[LT::YY], 2*xform[LT::YX]*xform[LT::YY],
171  xform[LT::XX]*xform[LT::YX], xform[LT::XY]*xform[LT::YY],
172  xform[LT::XX]*xform[LT::YY] + xform[LT::XY]*xform[LT::YX];
173  return m;
174 }
175 
176 }}} // 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:330
ShapeTrMatrix makeShapeTransformMatrix(afw::geom::LinearTransform const &xform)
Construct a matrix suitable for transforming second moments.
ErrElement yy_xy_Cov
yy,xy term in the uncertainty convariance matrix
table::Key< std::string > name
Definition: ApCorrMap.cc:71
Eigen::Matrix< ErrElement, 3, 3, Eigen::DontAlign > ShapeCov
Definition: constants.h:59
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.
The full covariance matrix is provided.
Definition: constants.h:44
double const getIyy() const
Definition: Quadrupole.h:59
ErrElement xySigma
1-Sigma uncertainty on xy (sqrt of variance)
static QuadrupoleKey addFields(Schema &schema, std::string const &name, std::string const &doc, CoordinateType coordType=CoordinateType::PIXEL)
float ErrElement
Definition: constants.h:53
Shape const getShape() const
Return an afw::geom::ellipses object corresponding to xx, yy, xy.
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:43
A FunctorKey for ShapeResult.
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition: BaseRecord.h:123
A 2D linear coordinate transformation.
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:58
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.
bool isValid() const
Return True if all the constituent sigma Keys are valid.
afw::table::QuadrupoleKey _shape
ShapeResult()
Constructor; initializes everything to NaN.
double const getIxx() const
Definition: Quadrupole.h:56
tbl::Schema schema
CoordinateType
Definition: misc.h:23
virtual ShapeResult get(afw::table::BaseRecord const &record) const
Get a ShapeResult from the given record.
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
Base class for all records.
Definition: BaseRecord.h:27
tuple m
Definition: lsstimport.py:48
std::string join(std::string const &a, std::string const &b) const
Join strings using the field delimiter appropriate for this Schema.
Algorithm provides no uncertainy information at all.
Definition: constants.h:42
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:136
ErrElement yySigma
1-Sigma uncertainty on yy (sqrt of variance)
double ShapeElement
Definition: constants.h:55
double const getIxy() const
Definition: Quadrupole.h:62
ErrElement xxSigma
1-Sigma uncertainty on xx (sqrt of variance)
void setShape(Shape const &shape)
Set struct elements from the given Quadrupole object.
Eigen::Matrix< ShapeElement, 3, 3, Eigen::DontAlign > ShapeTrMatrix
Definition: constants.h:60
ShapeCov const getShapeErr() const
Return the 3x3 symmetric covariance matrix, with rows and columns ordered (xx, yy, xy)
afw::table::CovarianceMatrixKey< ErrElement, 3 > _shapeErr
static ShapeResultKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc, UncertaintyEnum uncertainty, afw::table::CoordinateType coordType=afw::table::CoordinateType::PIXEL)
Add the appropriate fields to a Schema, and return a ShapeResultKey that manages them.